Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

For all you Office 365 admins, this simple script restores the sync-and-wait behavior of the Azure AD Connect sync service (formerly known as DirSync)

$
0
0

When Azure AD Connect updated a few months ago, it broke a number of our account creation scripts. The new PowerShell commands that initiate a delta sync or full sync don’t halt script execution until the synchronization completes. Why does this matter? Say you have a new user that needs to be synchronized from the on-prem directory to Azure AD in order to receive an Office 365 license. Previously, you could count on the delta sync executable to pause the account creation process until the delta sync was able to complete. With the new PowerShell commandlets, it’s all dumb timers and guesswork… that is, unless you use the following script.

This little script will kick off a delta sync and wait until it completes before exiting. Any account creation scripts (or other scripts that might rely on Azure AD Connect) will wait until this script exits before proceeding.

Write-Host "Initializing Azure AD Delta Sync..." -ForegroundColor Yellow Start-ADSyncSyncCycle -PolicyType Delta #Wait 10 seconds for the sync connector to wake up. Start-Sleep -Seconds 10 #Display a progress indicator and hold up the rest of the script while the sync completes. While(Get-ADSyncConnectorRunStatus){ Write-Host "." -NoNewline Start-Sleep -Seconds 10 } Write-Host " | Complete!" -ForegroundColor Green 

This works because Get-ADSyncConnectorRunStatus returns a null result when the Azure AD Connector is not actively running. So as long as Get-ADSyncConnectorRunStatus returns anything at all, the script will continue to wait for synchronization to complete.

Hopefully someone finds this useful.

submitted by /u/miltonthecat
[link] [comments]

The post For all you Office 365 admins, this simple script restores the sync-and-wait behavior of the Azure AD Connect sync service (formerly known as DirSync) appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles