public/Start-O365DirSync.ps1

<#
.Synopsis
This powershell cmdlet allows you to sync Active Directory with your Azure AD Connection server. Password synchronizations can be completed as Delta (only changes are applied), Full (all attributes are checked and applied), or FullPW (an entire full synchronization of your Active Directory). This will not run if Azure AD Connect services are not found on your system and will only run on your 'DirSync' server.
  
.Description
Syncs your Active Directory with Azure AD Connect via powershell cmdlets.
  
.Example
Start-O365DirSync -SyncType Full
 
.Example
Start-O365DirSync -SyncType Delta
 
.Example
Start-O365DirSync -SyncType FullPW
#>


Function Start-O365DirSync{
 [cmdletbinding()]
    Param (
    [Parameter(Position=0,mandatory=$true)] [string]$SyncType
        )
    # End of Parameters
    Process {
            Test-O365Dirsync
    If (Get-ADSyncConnectorRunStatus) {Write-Warning "A sync is already in progress"}
    Else{
        switch ($SyncType)
            {
            Full    {   Start-ADSyncSyncCycle -PolicyType Initial
                        Get-O365SyncStatus
                    }
            Delta   { 
                        Start-ADSyncSyncCycle -PolicyType Delta
                        Get-O365SyncStatus
                    }
            FullPW  { 
                        $adConnector  = Read-Host -Prompt 'Please enter your Full AD Domain Name (i.e. - "fabrikam.com"): '
                        $aadConnector = Read-Host -Prompt 'Please enter your full *.onmicrosoft.com address (i.e. - "aaddocteam.onmicrosoft.com"): '
                        $aadConnector = $aadConnector + " - AAD"
                        Import-Module adsync
                        $c = Get-ADSyncConnector -Name $adConnector
                        $p = New-Object Microsoft.IdentityManagement.PowerShell.ObjectModel.ConfigurationParameter "Microsoft.Synchronize.ForceFullPasswordSync", String, ConnectorGlobal, $null, $null, $null
                        $p.Value = 1
                        $c.GlobalParameters.Remove($p.Name)
                        $c.GlobalParameters.Add($p)
                        $c = Add-ADSyncConnector -Connector $c
                        Set-ADSyncAADPasswordSyncConfiguration -SourceConnector $adConnector -TargetConnector $aadConnector -Enable $false
                        Set-ADSyncAADPasswordSyncConfiguration -SourceConnector $adConnector -TargetConnector $aadConnector -Enable $true
                        Get-O365SyncStatus
                    }
        default {"Invalid parameter entered for '-SyncType'"}
        }
        }
    }#End Process
}