I've created a script to read off a CSV and use 2 colums, the issue I'm getting bad output on one of the variables.
$users = import-csv C:\Users\admin\Desktop\ext.csv
foreach($column in $users){
set-aduser $column.user -OfficePhone "800 555 $column.ext"
}
The output I get in AD for the $column.ext is @{ext=3512; user=jondoe}.ext.
How can I fix this?
You may enclose the Object.Property in a sub-expression $() to force the desired expansion within the quotes:
$users = import-csv C:\Users\admin\Desktop\ext.csv
foreach ($column in $users) {
set-aduser $column.user -OfficePhone "800 555 $($column.ext)"
}
For a more detailed explanation of PowerShell's parsing modes, see this blog post from Keith Hill.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With