Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update Active directory from spreadsheet

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?

like image 479
JoeRod Avatar asked Feb 24 '26 10:02

JoeRod


1 Answers

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.

like image 80
jscott Avatar answered Feb 27 '26 02:02

jscott



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!