Advertisement
Guest User

Untitled

a guest
Aug 28th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #### CHECK OPERATIONS MANAGER MODULE ####
  2. $OM_Module = Get-Module -ListAvailable | Where-Object {$_.Name -eq "OperationsManager"}
  3.  
  4. #### CREDENTIALS FOR AUTHENTICATION ####
  5. $Account = Get-AutomationPSCredential -Name 'SCOM Automation Account'
  6. $userName = $Account.UserName
  7. $securePassword = $Account.Password
  8. $credential = New-Object System.Management.Automation.PSCredential $userName, $securePassword
  9.  
  10. #### IMPORTING OPERATIONS MANAGER MODULE ####
  11.  
  12. if ($OM_Module)
  13. {
  14.     Import-Module OperationsManager
  15. }
  16. else
  17. {
  18.     $Session = New-PSSession -ComputerName XXXXXXXXXXXX  -Credential $credential
  19.     Import-Module -Name OperationsManager -PSSession $Session
  20. }
  21.  
  22. #$Session = New-PSSession -ComputerName XXXXXXXXXXXX -Credential $credential
  23.  
  24. #$ttt = New-SCManagementGroupConnection -ComputerName XXXXXXXX -Credential $credential
  25.  
  26. #### UPDATE COMMVAULT ALERTS ####
  27. try
  28. {
  29.     #[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")Microsoft.EnterpriseManagement.Monitoring.MonitoringAlert
  30.     $Alerts = Get-SCOMAlert -Name "CommVault Alert*" | Where-Object {$_.ResolutionState -eq 0}
  31.     Write-Output "Found the following alerts:"
  32.     Write-Output $Alerts | select name,TimeAdded,Description,severity | fl
  33.     $gm = $Alerts | get-member
  34.     write-output $gm
  35.    
  36.     foreach ($Alert in $Alerts)
  37.     {
  38.         $TMP = New-Object Microsoft.EnterpriseManagement.Monitoring.MonitoringAlert $Alert
  39.         Write-Output $TMP1.GetType()
  40.         Write-Output "Closing alert: $TMP"
  41.         Resolve-SCOMAlert -Alert $TMP -ResolutionState 255 -Comment "Closed by Azure Automation"
  42.     }
  43.     Write-Output "Runbook has been finished."
  44.     Remove-Module OperationsManager
  45.     Remove-PSSession $Session
  46. }
  47. catch
  48. {
  49.     Write-Error -Message $_.Exception
  50.     throw $_.Exception
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement