1

I have a list of users in active directory to which I have to remove the description and office fields. how can i do through poweshell? I try this but not work.

My code path is ok

Import-Module ActiveDirectory
$Users = Import-csv C:\Users\xxxx\Desktop\test.csv
foreach($User in $Users){
Set-ADUser $User.SamAccountName -Description $User.NewDescription
}

my csv

SamAccountName;NewDescription;EmailAddress
xxxxxxxxxx;xxxxxxxxxxx;xxxxxxxxxxxxx@libero.it

Powershell answer

Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the 
argument, and then try running the command again.
At line:4 char:12
+ Set-ADUser $User.SamAccountName -Description $User.NewDescription
+            ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Set-ADUser], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.SetADUs 
   er

Help will be appreciated

2 Answers2

1

You need to specify your delimiter on your import-csv statement. The default is comma separated, so you can define it like so

$Users = Import-csv C:\Users\xxxx\Desktop\test.csv -Delimiter ';'

Without this, then it's importing as one single column instead of three.

See Import-CSV for more.

AutomatedOrder
  • 501
  • 4
  • 14
0

It might work?

$users = Import-Csv -Path C:\users1.csv

foreach ($user in $users) { #Search in specified OU and Update existing attributes Get-ADUser -Filter “SamAccountName -eq ‘$($user.samaccountname)'” -Properties * -SearchBase “cn=Users,DC=**********,DC=*****” | Set-ADUser -Clear description, Office }