Created
October 28, 2017 03:24
-
-
Save kevinblumenfeld/933b1d7752ee5881b3b057b77592d453 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
Function Sync-ADConnect { | |
Param ( | |
[Parameter(Mandatory = $False)] | |
[switch] $Initial, | |
[Parameter(Mandatory = $False)] | |
$aadComputer = "se-c-ac01.corp.ad.sentara1.com" | |
) | |
<# | |
.SYNOPSIS | |
.EXAMPLE | |
#> | |
if ($initial) { | |
Start-Job -ScriptBlock { | |
Start-Sleep -Seconds 10 | |
$session = New-PSSession -ComputerName $aadComputer | |
Invoke-Command -Session $session -ScriptBlock {Import-Module -Name 'ADSync'} | |
Invoke-Command -Session $session -ScriptBlock { | |
Try { | |
Start-ADSyncSyncCycle -PolicyType Initial -erroraction Stop | |
} | |
Catch { | |
Start-Sleep -Seconds 60 | |
Start-ADSyncSyncCycle -PolicyType Initial | |
} | |
} | |
Remove-PSSession $session | |
} -ArgumentList $aadComputer | |
} | |
else { | |
Start-Job -ScriptBlock { | |
Start-Sleep -Seconds 10 | |
$session = New-PSSession -ComputerName $aadComputer | |
Invoke-Command -Session $session -ScriptBlock {Import-Module -Name 'ADSync'} | |
Invoke-Command -Session $session -ScriptBlock { | |
Try { | |
Start-ADSyncSyncCycle -PolicyType Delta -erroraction Stop | |
} | |
Catch { | |
Start-Sleep -Seconds 60 | |
Start-ADSyncSyncCycle -PolicyType Delta | |
} | |
} | |
Remove-PSSession $session | |
} -ArgumentList $aadComputer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment