Last active
December 26, 2019 22:16
-
-
Save Barious/17d60e4913b5936d79fc5141e14519e7 to your computer and use it in GitHub Desktop.
This file contains 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
[Cmdletbinding()] | |
Param ([Parameter(Mandatory = $true, ValuefromPipeline = $true, ValuefromPipeLinebypropertyName = $true, Position = 1 )]$User, | |
[parameter(Mandatory = $True, ValuefromPipeline = $true, ValuefromPipeLinebypropertyName = $true, Position = 2 )]$OU, | |
[parameter(Mandatory = $True, ValuefromPipeline = $true, ValuefromPipeLinebypropertyName = $true, Position = 3)]$ObjectName, | |
[Parameter(Mandatory = $True, ValuefromPipeline = $true, ValuefromPipeLinebypropertyName = $true, Position = 4)]$SamName, | |
[Parameter(Mandatory = $True, ValuefromPipeline = $true, ValuefromPipeLinebypropertyName = $true, Position = 5)]$DisplayName, | |
[Parameter(Mandatory = $True, ValuefromPipeline = $true, ValuefromPipeLinebypropertyName = $true, Position = 6)]$UPN, | |
[Parameter(Mandatory = $True, ValuefromPipeline = $true, ValuefromPipeLinebypropertyName = $true, Position = 7)]$Email | |
) | |
#$RidMaster1 = "RID Master servers" | |
#$RidMaster2 = "Target RID Master server" | |
Try { | |
$RetailAccount = Get-aduser -Identity $user -Server $RidMaster1 -Properties Manager | |
if ($null -ne $RetailAccount) { | |
Write-Output $RetailAccount | |
$RetailAccount | Move-adobject -Targetpath $OU -targetserver $RIDMaster2 -Confirm | |
Write-Host " | |
Waiting on Replication 20 seconds | |
" -ForegroundColor Green | |
Start-Sleep -Seconds 20 | |
} | |
} | |
Catch { | |
if ($null -eq $RetailAccount) { | |
Write-Error "User not found Please confirm user account name!" -ErrorAction Stop | |
} | |
} | |
Try { | |
$MigratedAccount = Get-aduser -Identity $user -Server $RidMaster2 -Properties manager | |
if ($null -ne $MigratedAccount) { | |
Write-Output $RidMaster2 | |
$MigratedAccount | Rename-Adobject -NewName $ObjectName -Server $RidMaster2 -Confirm | |
Write-Host "Waiting on replication 10 second" -ForegroundColor Green | |
Start-Sleep -Seconds 10 | |
$MigratedAccount | Set-ADUser -DisplayName $DisplayName -UserPrincipalName $UPN -EmailAddress $Email -Server $RidMaster -Confirm | |
$MigratedAccount | Set-ADUser -SamAccountName $SamName -Server $RidMaster2 -Confirm | |
Write-Host " | |
Waiting on Replication 5 seconds | |
" -ForegroundColor Green | |
Start-Sleep -Seconds 5 | |
$UPdatedSAM = Get-aduser -Identity $SamName -server $RidMaster -Properties DisplayName, Manager, EmailAddress | |
Write-Output $UpdatedSam | |
} | |
} | |
Catch { | |
If ($null -eq $RidMaster2) { | |
Write-Error "Can not find account name" | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment