priara
priara

Reputation: 25

Updating users with different descriptions in AD

I have a .csv file with a couple of users and each user has a different description. I'm trying to create a script to update the users' description with what is in the .csv file. I have searched but have been unable to find a script that does what I need it to do. Can someone take a look at my script please? I am erroring at: Unexpected token 'in' in expression or statement. At line:6 char:35 Unexpected token 'in' in expression or statement. At line:6 char:38

ipmo ac*
$file = c:\user_file.csv
$user = $_.samaccountname
$desc = $_.description

Import-csv $file | Foreach ($user in $file) {
@(Set-aduser -identity $($file.user) -description $($file.desc))
}

Any help would be appreciated since I have been trying to do this for a week now and I'm sure it's something easy?

Upvotes: 1

Views: 387

Answers (1)

Matt
Matt

Reputation: 46710

I would instead do something like this.

ipmo ac*
$file = "c:\user_file.csv"
Import-csv $file | ForEach-Object{
    Set-aduser -identity $_.samaccountname -description $_.description
}

This is assuming you have your CSV with columns called samaccountname and description.

Not sure what you were trying to do with $user and $desc so those are just omitted. Guessing they would have actually been null since $_ is meant to be used inside a pipeline.

The ForEach you were using is not meant to have pipeline input. The way you have it usually stands on its own. So we switched it to the ForEach-Object version that allows pipeline input.

Upvotes: 1

Related Questions