Shared configuration example for AADSync scripts

As part of our Office365 Directory Synchronization project we have written several scripts to monitor the integrity of our AADSync systems. The script below contains shared values and is called by others.
Import-Module msonline Import-Module ActiveDirectory $scriptpath = "C:\scripts\" $fromEmail = "admin@contoso.com" $toEmail = "tonyb@wisc.edu" $EmailServer = "smtp.contoso.com" #encrypted Azure AD credentials $aaduser = "aadsync@contoso.onmicrosoft.com" $aadpwd = get-content ($scriptpath + "aad-password.txt") | convertto-securestring $aadcred = new-object system.management.automation.pscredential($aaduser,$aadpwd) #encrypted Campus AD credentials $AdUser = "contoso\ad-sync-user" $AdPasswordFile = $scriptpath + "ad-password.txt" $adpwd = Get-Content $AdPasswordFile | ConvertTo-SecureString $adcred = New-Object System.Management.Automation.PsCredential($AdUser,$adpwd) #AD User search base $usersearchbase = "ou=users,dc=contoso,dc=com" #User UPN suffix $upn = "contoso.com" #hostname $hostname = hostname #connection to AADSync DB $dataSource = "sql.contoso.com" $dbuser = "adsyncuser" $database = "ADSync" $connectionString = "Server=$dataSource;uid=$user; pwd=$adpwd;Database=$database;Integrated Security=True;Connect Timeout=3;" $connection = New-Object System.Data.SqlClient.SqlConnection $connection.ConnectionString = $connectionString #SyncScript can be called to execute the AADSync jobs Function SyncScript{ $syncprogram = "C:\Program Files\Microsoft Azure AD Sync\Bin\DirectorySyncClientCmd.exe" $maname = "uwfimdev.onmicrosoft.com - AAD" $runprofilename = "Export" $ma = Get-WmiObject -Class MIIS_ManagementAgent -Namespace root/MicrosoftIdentityIntegrationServer -Filter "name='$maname'" & $syncprogram if ($?) { $ma.Execute("$runprofilename") } } #DBQuery can be passed a quoted query and will return the table results Function DBQuery ($inputquery){ $command = $connection.CreateCommand() $command.CommandText = $inputquery $result = $command.ExecuteReader() $outputtable = new-object "System.Data.DataTable" $outputtable.Load($result) $outputtable }


Keywords:
FIM AADSync DirSync SQL 
Doc ID:
46071
Owned by:
MST Support in Identity and Access Management
Created:
2015-01-09
Updated:
2022-05-25
Sites:
Identity and Access Management