|
Get-PSSession | Remove-PSSession $username = "aaa@bbb.com"
$secureStringPwd = ConvertTo-SecureString -AsPlainText "password" -Force
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $secureStringPwd
Connect-MsolService -Credential $UserCredential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $creds -Authentication Basic -AllowRedirection
Import-PSSession $Session
$result=Get-MsolDirSyncProvisioningError | select Displayname, LastDirSyncTime, ObjectId, ObjectType, @{n='Error';e={$_.ProvisioningErrors.ErrorCategory}}, UserPrincipalName
$from = "helpdesk@bbb.com"
$to = "aaa@bbb.com"
$smtp = "smtp.office365.com"
$sub = "Office365 Sync Error"
$secpasswd = ConvertTo-SecureString "Password" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($from, $secpasswd)
$a = ""
$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 + ""
#import-csv C:\scripts\users.csv | ConvertTo-Html -Body " User List " -Head $a | out-file C:\temp\tt.html
$htmlbody=$result| ConvertTo-Html -Body " Office365 DirSync Errors For Further details, please visit https://portal.office.com/adminportal/home#/dirsyncobjecterrors" -Head $a
Send-MailMessage -To $to -From $from -Subject $sub -Body ($htmlbody|Out-String) -Credential $mycreds -SmtpServer $smtp -DeliveryNotificationOption Never -BodyAsHtml -UseSsl -port 587
|
|
|