Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinblumenfeld/933b1d7752ee5881b3b057b77592d453 to your computer and use it in GitHub Desktop.
Save kevinblumenfeld/933b1d7752ee5881b3b057b77592d453 to your computer and use it in GitHub Desktop.
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