Script repository
The scripts force Active Directory synchronization with Microsoft 365. You can use the scripts as part of a business rules, custom command or scheduled task.
Before using the scripts, make sure that the computer where Adaxes service is installed and the computer where the DirSync / AAD Connect tool is installed allow execution of remote PowerShell commands. For details, see About Remote Requirements.
Script 1: Using the DirSync tool
Parameters
$dirsyncServer- the fully-qualified domain name of server where the DirSync tool is installed.$dirsyncmodulePath- the path to the DirSync module relative to the computer where it is installed (by default, the path isC:\Program Files\Windows Azure Active Directory Sync\DirSyncConfigShell.psc1).
$dirsyncServer = "dirsync.domain.com" # TODO: modify me
$scriptBlock = {
$dirsyncModulePath = "C:\Program Files\Windows Azure Active Directory Sync\DirSyncConfigShell.psc1" # TODO: modify me
powershell -PSConsoleFile $dirsyncModulePath -Command "Start-OnlineCoexistenceSync"
}
$result = Invoke-Command -ComputerName $dirsyncServer -ScriptBlock $scriptBlock
if ($result -ne $NULL)
{
$Context.LogMessage($result, "Warning")
}Script 2: Using the AAD Connect tool
In the script, the $dirsyncServer variable specifies the fully-qualified domain name of server where the AAD Connect tool is installed.
$dirsyncServer = "dirsync.domain.com" # TODO: modify me
Invoke-Command -ComputerName $dirsyncServer -ErrorAction Stop -ScriptBlock {
Import-Module "C:\Program Files\Microsoft Azure AD Sync\Bin\ADSync\ADSync.psd1"
Start-ADSyncSyncCycle -PolicyType Delta
}
Comments 7
You must be signed in to comment.
Christian Diaz
This script/command will error if there's already a synchronization in progress, which injects an error in the Adaxes logging. Would be nice to see some error handling in this or maybe a check beforehand execution if a sync is already running.
Support
Hello,
Unfortunately, there is no such possibility as it would require parsing the error returned by the Invoke-Command cmdlet.
Christian
Had the same issue , not sure if something like this would help you? Not tested yet in Adaxes
Christian
You define $dirsyncServer but use $computerName later : )
Support
Hello Christian,
-ComputerName is a predefined parameter name for the Invoke-Command cmdlet. There is no possibility to change it. We use $dirsyncServer as the corresponding tools are usually installed on server editions.
Christian
Hi,
I talking about the first script - if you run it, it will throw error , as variable $computerName was never set
Support
Hello Christian,
Thank you for pointing out the mistake. We have just fixed it.