The Azure AD Connect Synchronization services is the connector in a hybrid AD environment. By hybrid we mean a local authoritative AD (Active Directory) that sync data to Azure Active Directory to be used in Microsoft Cloud Services including Office 365. The purpose of this article is not to demonstrate how to install AD Connect or even configure it, but how to manually sync to Azure AD with PowerShell. We will attempt to answer other common questions along the way.
Manually sync AD Connect
You can manually sync your local Active Directory with AD Connect to Azure with just a few lines of PowerShell code. The sync is also known as an AD Connect Sync Delta, as you will see specified below.
$s = New-PSSession -ComputerName "adconnect.example.com" -Credential ""
Invoke-Command -Session $s -ScriptBlock {Start-ADSyncSyncCycle -PolicyType Delta}
Remove-PSSession $s
Let us break down each line of code in detail.
$s = New-PSSession -ComputerName "adconnect.example.com" -Credential ""
- Create a new session with New-PSSession and assign it to a variable. The -ComputerName is the name of the server running your Azure AD Connect Synchronization Services. The -Credential will accept your domain admin credentials.
Invoke-Command -Session $s -ScriptBlock {Start-ADSyncSyncCycle -PolicyType Delta}
- Use the Invoke-Command cmdlet to execute a script block on the remote computer running the ad connect sync services. -Session will take the previous session variable as its parameter. -ScriptBlock is the code to execute. Start-ADSyncSyncCycle -PolicyType Delta is the code to perform the delta sync. Alternatively, -PolicyType Initial can be used to perform a full sync of your local directory. This is usually only done the first time and is not the recommended approach after the initial sync.
Remove-PSSession $s
- Remove the session created with the New-PSSession command.
How often does AD Connect Sync?
By default, the AD Connect Sync services execute every 30 minutes.
Conclusion – Azure AD Connect Synchronization
This article has demonstrated how to perform Azure AD Connect sync manually with PowerShell on demand. Let us know in the comments if you have any questions or would like to see more examples with Azure AD Connect sync.
More articles about powershell.
Leave a Reply