Advertisement
Guest User

Untitled

a guest
May 21st, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. # Azure runbook running under an automation account.
  2. #Requires -Modules MSOnline
  3.  
  4. Import-Module -Name MSOnline
  5. $creds = Get-AutomationPSCredential -Name 'AzureADConnectSyncAccount'
  6. Connect-MsolService -Credential $creds
  7.  
  8.  
  9. <#
  10. .SYNOPSIS
  11. Check last sync time is within 2 hours
  12. .DESCRIPTION
  13. Uses MSOL command to get the last sync time and check it is within two hours.
  14. If it isn't, output a message (this is where a slack hook or other alert can be triggered.
  15. #>
  16. $CompanyInformation = Get-MsolCompanyInformation
  17.  
  18. if ((Get-Date).AddHours(-2) -gt $CompanyInformation.LastDirSyncTime) {
  19. # Send error message
  20. $Message = "Azure AD Connect`nNo AD to Azure sync for over 2 hours`nLast sync time was: $($CompanyInformation.LastDirSyncTime)`nPlease check sync service on the sync server."
  21. Write-Output $Message
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement