PowerShell script notifies Office365 of synchronization errors

Source: Internet
Author: User

The bean company is a listed company and needs to be audited every year. Therefore, the information of the separated users can not be deleted, can only disable out. Sometimes, the desktop needs to re-add an outgoing user's message to another user's alias to continue receiving the message. But Office365 default configuration of a user who has been disable off, no matter how he will not continue to sync, so the result is that the desktop is often modified in the wrong order, resulting in the local ad has been changed, but the modified things will not sync to office365, or directly office365 that there is already a record, refusing to add a new record.

Given the unreliable desktop support, beans need to look at the sync status every day and then notify the desktop to change. Log in to the main screen and click DirSync errors to see it.

Conflicting SMTP Address records

How can I get this interface automatically? Beans just started looking for a half-day API, never found, and even began to play crawler attention, and then finally found the relevant command

https://docs.microsoft.com/en-us/powershell/module/msonline/get-msoldirsyncprovisioningerror?view=azureadps-1.0

The following is the complete script

get-pssession | Remove-pssession$username = "[email protected]" $SECURESTRINGPWD = convertto-securestring-asplaintext "Password "-force$creds = New-object system.management.automation.pscredential-argumentlist $username, $ securestringpwdconnect-msolservice-credential $UserCredential $session = new-pssession-configurationname Microsoft.exchange-connectionuri Https://outlook.office365.com/powershell-liveid/-credential $creds- Authentication Basic-allowredirectionimport-pssession $Session $result=get-msoldirsyncprovisioningerror | Select Displayname, Lastdirsynctime, ObjectId, ObjectType, @{n= ' Error '; e={$_. Provisioningerrors.errorcategory}}, Userprincipalname$from = "[email protected]" $to = "[email protected]" $SMTP = "smtp.office365.com" $sub = "Office365 Sync Error" $secpasswd = convertto-securestring "Password"-asplaintext-fo Rce $mycreds = New-object System.Management.Automation.PSCredential ($from, $secpasswd) $a = "<style>" $a = $a + "BODY {Background-color:lavEnder;} " $a = $a + "table{border-width:1px;border-style:solid;border-color:black;border-collapse:collapse;}" $a = $a + "Th{border-width:1px;padding:0px;border-style:solid;border-color:black;background-color:thistle}" $a = $a + " Td{border-width:1px;padding:0px;border-style:solid;border-color:black;background-color:palegoldenrod} "$a = $a +" </style> "#import-csv C:\scripts\users.csv | Convertto-html-body "<H1> User List </H1>"-head $a | Out-file c:\temp\tt.html$htmlbody= $result | Convertto-html-body "<H1> Office365 DirSync Errors </H1> 

Receive email Notifications

Set a scheduled task after success

$settingspath=‘C:\users\yuan.li\Documents\GitHub\Powershell\AD and Office365\SyncErrorNotification.ps1‘if (Get-ScheduledTask -TaskName ‘SyncNotification‘ -ErrorAction SilentlyContinue){ Unregister-ScheduledTask -TaskName ‘SyncNotification‘ -Confirm:$false}$Action = New-ScheduledTaskAction -Execute ‘C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe‘ -Argument "-executionpolicy bypass -File ‘$settingspath‘"$Trigger = New-ScheduledTaskTrigger -Daily -At ‘10AM‘$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings (New-ScheduledTaskSettingsSet)$Task | Register-ScheduledTask -TaskName ‘SyncNotification‘ -User ‘admin‘ -Password ‘password‘

The results are as follows

PowerShell script notifies Office365 of synchronization errors

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.