I need to delete the email address field from about 200 users. I was able to generate a csv file and run this code. Think of these users like vendors that you setup an accounts for to do some kind of remote work, most of these are for SSL VPN for us. We want to have an email address on record for them but not in the email address field.
Import-CSV C:\temp\users_with_email_addresses.csv | ForEach-Object { $samaccountname = $_.samaccountname Get-ADUser -Identity $samaccountname -Properties emailaddress}
I am running this under my domain admin account. This shows me all the accounts and the email address associated with them.
I thought it would be as easy as sending that info across the pipe line to set-aduser. I am using this code.
Import-CSV C:\temp\users_with_email_addresses.csv | ForEach-Object { $samaccountname = $_.samaccountname $emailaddress = $_.emailaddress Get-ADUser -Identity $samaccountname | Set-ADUser -Remove $emailaddress }
I have used multiple variations of the set-aduser. I have used the -replace parameter. I have tried $null, $_.null set directly to the variable. I have tried leaving the emailaddress cell in my CSV file blank.
In the current iteration above I get the error message “set-aduser : cannot bind parameter ‘remove’. Cannot convert the “user@emailaddres.com” value of type “System.string” to type “system.collection.hashtable”.”
How do I use set-aduser to blank out the email field in AD?