Search This Blog

Monday 20 May 2013

Useful PowerShell Commands


As of 01/05/2017, this blog will not be updated or maintained

In my time of using SCOM 2007 and 2012, I had come across a couple of useful PowerShell commands that helped me a lot. I would like to share these commands with you.


Firstly, lets open the Operations Manager Shell. Once opened you can start using the commands as indicated below. You can always change the path indicated in red.

  • The below command retrieve a list of subscriptions.
Get-NotificationSubscription |%{$c=$_.ToRecipients; $b=@($c|%{$_.Name}); $d=@($c|%{$_.Devices}|%{$_.address});"'{0}' '{1}' '{2}'" -f $_.DisplayName,[string]::join(':',$b),[string]::join(':',$d) }
  • The below command retrieve a list of Management Packs and save it in a *.csv file.
Get-ManagementPack | Format-Table Name, FriendlyName, DisplayName, Version -autosize | out-file C:\MPS.csv -width 1000
  • If you ever wanted to export a list of alerts to a document, than the below command can help you with  that.
Get-Alert | where {$_.ResolutionState –eq 0} | select-object MonitoringObjectDisplayName, Name, ResolutionState, RepeatCount | export-csv C:\Alerts.csv –noTypeInformation
  • If you ever wanted to export a list of alerts to a document, than the below command can help you with  that. The only difference between this command and the one above is that this command sorts the alerts by name.
Get-Alert | where {$_.ResolutionState –eq 0} | select-object MonitoringObjectDisplayName, Name, ResolutionState, RepeatCount | sort Name | export-csv C:\Alerts-sorted.csv –noTypeInformation
  • The below command helped me out a lot. Ever came across a couple of agents showing up as greyed out on your console but they are not listed beneath each other to make the view easier? This command will pull a list of only greyed out agents.
$rootMS =’RMS FQDN'

#Initializing the Ops Mgr 2007 Powershell provider
add-pssnapin “Microsoft.EnterpriseManagement.OperationsManager.Client” -ErrorVariable errSnapin ;
set-location “OperationsManagerMonitoring::” -ErrorVariable errSnapin ;
new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin ;
set-location $rootMS -ErrorVariable errSnapin ;
$WCC = get-monitoringclass -name “Microsoft.SystemCenter.Agent”

$MO = Get-MonitoringObject -monitoringclass:$WCC | where {$_.IsAvailable -eq $false}

$MO | select DisplayName


!!PLEASE NOTE THE BELOW COMMANDS WILL ONLY WORK ON SCOM 2012!!

  • The below command is to get a count of Warning alerts generated by a rule.
(get-scomalert -criteria 'ResolutionState = ''0'' AND Severity = ''1''' | where-object {($_.IsMonitorAlert -eq $false)}).count 
  • The below command is to get a count of Warning alerts generated by a monitor.
(get-scomalert -criteria 'ResolutionState = ''0'' AND Severity = ''1''' | where-object {($_.IsMonitorAlert -eq $true)}).count

  • The below command is to get a count of Critical alerts generated by a rule.
(get-scomalert -criteria 'ResolutionState = ''0'' AND Severity = ''2''' | where-object {($_.IsMonitorAlert -eq $False)}).count

  • The below command is to get a count of Critical alerts generated by a Monitor.
(get-scomalert -criteria 'ResolutionState = ''0'' AND Severity = ''2''' | Where-Object {($_.IsMonitorAlert -eq $True)}).count

Please let me know if there is any issues with the commands and feel free to send me some of your PowerShell commands and I will update my page with it after testing.

Hope that this post was helpful.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.