Morning Check SCOM Alerts – Automated using PowerShell Script
One of my clients has a centralised SCOM management group for different segments of the business. The BAU team’s support hours are 8am-6pm Monday - Friday. They are also required to perform a morning check Monday – Friday and manually log service desk calls based on the SCOM alerts generated after hours.
I wanted to automate the process (at least to generate a list of alerts that were raised since 6:00pm previous night). We firstly had a look at the Alerts report from SCOM Generic Reports library but it did not meet our requirements as it does not include the alert resolution state in the report.
We have the following requirements to accomplish:
- Include any warning and critical alerts generated between 6:00pm previous BUSINESS day and 7:30 present day.
- Only include alerts that are still open (resolution state not equals to 255)
- Only include production servers from a specific domain
- Time Raised is displayed as the local time, not GMT standard time
- List is emailed out every morning
As my knowledge in SQL reporting is very limited, I achieved the task using below PowerShell script. It is scheduled in Task Scheduler of the SCOM RMS server to run Monday – Friday.
Note: a SCOM group is required to include all servers in the scope (in this case, all production servers from the particular domain).
Here’s the script.
10 Comments
Nice work mate. You could completely automate the process by using the OpsMgr Interop Connector which will send alerts to pretty much any 3rd party service desk tool. Have a look at this TechNet article for more info.
It’s been suggested. Let’s say there are non-technical reasons behind this…
I really like your script but had a question.
I’ve made the needed edits and commenting out #$erroractionpreference = “SilentlyContinue” so I can see if there are any errors and found that I’m I am getting a bunch of errors. I’m unsure if these are expected or not but I do know that the email does gets sent with the attached CVS. I’m still very green to PowerShell but I’m learning thanks to using useful scripts like yours.
Thanks in advance for any advice,
Thom
Here’s a copy of my PS output.
Welcome to the Operations Manager 2007 R2 Command Shell. This command shell is
designed to provide interactive and script based access to Operations Manager
data and operations. This functionality is provided by a set of Operations
Manager commands.
To list all commands, type: Get-Command
To list all Operations Manager commands, type: Get-OperationsManagerCommand
To get help for a command, type: Get-Help [command name]
Connecting to Operations Manager Management Server ‘OpsMgrRMS.MyDomain.com’.
PS Monitoring:\OpsMgrRMS.MyDomain.com
>C:\scripts\SCOM-MorningCheck.ps1
Initiating SCOM PS Snapin…
Connecting to SCOM RMS OpsMgrRMS.MyDomain.com…
Getting alerts from SCOM…
alerts found
Add-Member : Cannot add a member with the name “IsMonitorAlert” because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter
to overwrite it.
At C:\scripts\SCOM-MorningCheck.ps1:102 char:13
+ Add-Member <<<< -InputObject $PSObjAlert -MemberType NoteProperty -Name IsMonitorAlert -Value $alert.IsMonitorAlert
Clear-Variable : Cannot find a variable with name 'PSObjectAlert'.
At C:\scripts\SCOM-MorningCheck.ps1:115 char:17
+ Clear-Variable <<<< PSObjectAlert
Add-Member : Cannot add a member with the name "IsMonitorAlert" because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter
to overwrite it.
At C:\scripts\SCOM-MorningCheck.ps1:102 char:13
+ Add-Member <<<< -InputObject $PSObjAlert -MemberType NoteProperty -Name IsMonitorAlert -Value $alert.IsMonitorAlert
Clear-Variable : Cannot find a variable with name 'PSObjectAlert'.
At C:\scripts\SCOM-MorningCheck.ps1:115 char:17
+ Clear-Variable <<<< PSObjectAlert
Add-Member : Cannot add a member with the name "IsMonitorAlert" because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter
to overwrite it.
At C:\scripts\SCOM-MorningCheck.ps1:102 char:13
+ Add-Member <<<< -InputObject $PSObjAlert -MemberType NoteProperty -Name IsMonitorAlert -Value $alert.IsMonitorAlert
Clear-Variable : Cannot find a variable with name 'PSObjectAlert'.
At C:\scripts\SCOM-MorningCheck.ps1:115 char:17
+ Clear-Variable <<<< PSObjectAlert
Add-Member : Cannot add a member with the name "IsMonitorAlert" because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter
to overwrite it.
At C:\scripts\SCOM-MorningCheck.ps1:102 char:13
+ Add-Member <<<< -InputObject $PSObjAlert -MemberType NoteProperty -Name IsMonitorAlert -Value $alert.IsMonitorAlert
Clear-Variable : Cannot find a variable with name 'PSObjectAlert'.
At C:\scripts\SCOM-MorningCheck.ps1:115 char:17
+ Clear-Variable <<<< PSObjectAlert
Add-Member : Cannot add a member with the name "IsMonitorAlert" because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter
to overwrite it.
At C:\scripts\SCOM-MorningCheck.ps1:102 char:13
+ Add-Member <<<< -InputObject $PSObjAlert -MemberType NoteProperty -Name IsMonitorAlert -Value $alert.IsMonitorAlert
Clear-Variable : Cannot find a variable with name 'PSObjectAlert'.
At C:\scripts\SCOM-MorningCheck.ps1:115 char:17
+ Clear-Variable <<<< PSObjectAlert
Add-Member : Cannot add a member with the name "IsMonitorAlert" because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter
to overwrite it.
At C:\scripts\SCOM-MorningCheck.ps1:102 char:13
+ Add-Member <<<< -InputObject $PSObjAlert -MemberType NoteProperty -Name IsMonitorAlert -Value $alert.IsMonitorAlert
Clear-Variable : Cannot find a variable with name 'PSObjectAlert'.
At C:\scripts\SCOM-MorningCheck.ps1:115 char:17
+ Clear-Variable <<<< PSObjectAlert
Add-Member : Cannot add a member with the name "IsMonitorAlert" because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter
to overwrite it.
At C:\scripts\SCOM-MorningCheck.ps1:102 char:13
+ Add-Member <<<< -InputObject $PSObjAlert -MemberType NoteProperty -Name IsMonitorAlert -Value $alert.IsMonitorAlert
Clear-Variable : Cannot find a variable with name 'PSObjectAlert'.
At C:\scripts\SCOM-MorningCheck.ps1:115 char:17
+ Clear-Variable <<<< PSObjectAlert
Add-Member : Cannot add a member with the name "IsMonitorAlert" because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter
to overwrite it.
At C:\scripts\SCOM-MorningCheck.ps1:102 char:13
+ Add-Member <<<< -InputObject $PSObjAlert -MemberType NoteProperty -Name IsMonitorAlert -Value $alert.IsMonitorAlert
Clear-Variable : Cannot find a variable with name 'PSObjectAlert'.
At C:\scripts\SCOM-MorningCheck.ps1:115 char:17
+ Clear-Variable <<<< PSObjectAlert
Add-Member : Cannot add a member with the name "IsMonitorAlert" because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter
to overwrite it.
At C:\scripts\SCOM-MorningCheck.ps1:102 char:13
+ Add-Member <<<< -InputObject $PSObjAlert -MemberType NoteProperty -Name IsMonitorAlert -Value $alert.IsMonitorAlert
Clear-Variable : Cannot find a variable with name 'PSObjectAlert'.
At C:\scripts\SCOM-MorningCheck.ps1:115 char:17
+ Clear-Variable <<<< PSObjectAlert
Add-Member : Cannot add a member with the name "IsMonitorAlert" because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter
to overwrite it.
At C:\scripts\SCOM-MorningCheck.ps1:102 char:13
+ Add-Member <<<< -InputObject $PSObjAlert -MemberType NoteProperty -Name IsMonitorAlert -Value $alert.IsMonitorAlert
Clear-Variable : Cannot find a variable with name 'PSObjectAlert'.
At C:\scripts\SCOM-MorningCheck.ps1:115 char:17
+ Clear-Variable <<<< PSObjectAlert
Add-Member : Cannot add a member with the name "IsMonitorAlert" because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter
to overwrite it.
At C:\scripts\SCOM-MorningCheck.ps1:102 char:13
+ Add-Member <<<< -InputObject $PSObjAlert -MemberType NoteProperty -Name IsMonitorAlert -Value $alert.IsMonitorAlert
Clear-Variable : Cannot find a variable with name 'PSObjectAlert'.
At C:\scripts\SCOM-MorningCheck.ps1:115 char:17
+ Clear-Variable <<<
can you email me the script which you’ve been edited?
Hi Tao Yang,
Could you please tell me where can I find the “Alerts report from SCOM Generic Reports library”
Thanks,
John
I get this to run. However I get 0 alerts returned. Any ideas what I might be missing? I only changed the items for my environment.
Not sure. need more details. what happens when you run it manually and comment out line 8: $erroractionpreference = “SilentlyContinue”
And does the account have access in SCOM?
Getting the following error when running from Operations Manager Shell on my RMS:-
>.\report1.ps1
Initiating SCOM PS Snapin…
Connecting to SCOM RMS rms1.mydomain.com…
You cannot call a method on a null-valued expression.
At C:\report1.ps1:67 char:71
+ Foreach ($member in $MonitoringObjectGroup.getrelatedmonitoringobjects <<<< ())
+ CategoryInfo : InvalidOperation: (getrelatedmonitoringobjects:Strin
g) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
In your original script I was not sure what you meant by $strNetBiosDomain = "” so i put the netbios name of the domain in here
Got script to execute successfully by entering following syntax at the start of the script:-
Set-Location Monitoring:
However the csv file generated has no content!
My fault, had not properly edited the script with my site specific parameters i.e. edited all the syntax between
Script now working a treat!
Used a free app called PowerGUI to edit the powershell script which made the job much easier.