I am a beginner in PowerShell. I have 1500 service accounts in Active Directory which are missing email addresses; I want to update the SAME email addresses in all the accounts.
Example email address: ecertprocess@abc.com
Please help me writing this PowerShell code.
I have all accounts SamAccountName and DN details.
This will find all the users who don't have a email address (You can change the SearchBase) and add email address of them.
Get-ADUser -Filter * -Properties * -SearchBase "dc=test,dc=net" | Where-Object {$_.EmailAddress -eq ''} | ForEach {Set-ADUser -Identity $_.SamAccountName -EmailAddress "Email Address"}
If you have list of users in a csv like:
SamAccountName,
xxx,
yyy,
then:
Import-Csv "Filepath" -Header SamAccountName -Delimiter "," | ForEach {Set-ADUser -Identity $_.SamAccountName -EmailAddress "Email Address"}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.