Last active
May 15, 2018 12:24
-
-
Save 1951FDG/15f8de2013af27abba965d5ee1477edf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param ( | |
[string]$oldDomain = "{OLDDOMAIN}", | |
[string]$newDomain = "{NEWDOMAIN}", | |
[string]$SearchBase = "{SEARCHBASE}" | |
) | |
Write-Verbose "$(Get-Date): Loading ActiveDirectory module..." | |
Try { Import-Module ActiveDirectory -ErrorAction Stop } | |
Catch { Write-Host "Unable to load Active Directory module, is RSAT installed?" -ForegroundColor Red; Exit } | |
Get-ADUser -Filter * -Properties givenName, Surname, EmailAddress, sAMAccountName -searchbase $SearchBase | %{ | |
if ($_.SurName -eq $null) | |
{ | |
Write-Host "User Name:" $($_.sAMAccountName) "has been not been updated" -ForegroundColor Yellow | |
} | |
else | |
{ | |
if ($_.EmailAddress) | |
{ | |
if ($_.EmailAddress.EndsWith($oldDomain)) | |
{ | |
#Write-Output $($_.EmailAddress).Replace($oldDomain, $newDomain) | |
Set-ADUser -Identity $_ -EmailAddress $($_.EmailAddress).Replace($oldDomain, $newDomain) | |
Write-Host "User Name:" $($_.sAMAccountName) "has been updated" -ForegroundColor Green | |
} | |
} | |
else | |
{ | |
Write-Host "User Name:" $($_.sAMAccountName) "has not been updated" -ForegroundColor Red | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment