Wednesday, 1 January 2020

Azure AD Connect : PowerShell script to check the AD Connect Password Sync status and send E-mail to Admins


Hello All,

Here is the PowerShell script to send an email to DL about the status of the password sync in a CSV.

Here i have used Get-MsolCompanyInformation.
this gives details like,
last sync time
last password sync time
technical notification email
service account used to perform the sync.

this has to be run on the AD Connect server with elevated rights.
before  running, get-msolcompany information you need to connect to azure.
so open PowerShell with admin rights,
run Connect -msolservice ( in the pop up enter the Global admin credentials)
now run the below script, this store the csv file in the path and also send an email to the address specified.

You can also store the encrypted creds in the script. this is an easy way.

post your suggestions and thoughts in the comments



###########AD CONNECT  PASSWORD SYNC STATUS######## 

$fromaddress = "user@abc.com" 
$toaddress = "adminDL@abc.com" 
 $ADConnect = get-MsolCompanyInformation >\\"path to write the output in csv"\ADC.csv
 $body =   "Please Find the Sync Scheduler info of AD CONNECT attached in the CSV and take actions if necessary. THANK YOU!!" 
 $date = get-date
$Subject = " $date : Pls See the state of AD Connect Sync" 

$attachment = "\\"path of the folder whee teh output csv is located"\Documents\11\ADC.csv" 
$smtpserver = "SMTP.abc.com" 

#################################### 

$message = new-object System.Net.Mail.MailMessage $message.From = $fromaddress
$message.To.Add($toaddress)
###############################################



$message.Subject = $Subject
$attach = new-object Net.Mail.Attachment($attachment)
$message.Attachments.Add($attach)
$message.body = $body 

$smtp = new-object Net.Mail.SmtpClient($smtpserver)
$smtp.Send($message) 

No comments:

Post a Comment

 வாழ்க்கை முழுவதைம் அள்ளிச்சென்ற  பின்,   கனவில்  மட்டும்  வந்து   ஏன் இன்பம்  காட்டுகிறாய்... கனவு கலைந்ததும்  உண்மை  வாட்டுகிறது... கனவாவத...