OpsMgr: New Sample Wizard to Create PowerShell Monitors in the Ops Console
This is an update to the sample management pack that provides a wizard to create PowerShell script based monitors in the Operations Console in System Center Operations Manager 2007 R2 & 2012. The updated sample management pack can now be downloaded from the TechNet Gallery.
The first version was released about 2 years ago – refer to Using Wizards to create Powershell-based Monitors for more information.
The new features included in this update are:
Ability to specify script parameters: The input parameter value can now be accessed in the script by using the $Arguments variable via
param( $Arguments).
Ability to apply an Override to modify the “Arguments” parameter value for the custom PowerShell based monitor created .
Importing the management pack will allow the PowerShell script Two State Monitor type to appear under the Scripting\Generic folder in the “Create a unit monitor” wizard.
Here is a simple example to test and display the input parameter values used via an alert triggered by a monitor state change for a custom PowerShell script monitor created from this updated wizard:
The PowerShell script used to test is as follows:
#///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
param($Arguments)
$PropertyBagAPI = new-object -comObject "MOM.ScriptAPI"
$PropertyBag = $PropertyBagAPI.CreatePropertyBag()
if($Arguments.length -gt 10){
$PropertyBag.AddValue("State","Critical")
$PropertyBag.AddValue("MessageText",$Arguments)}
else{
$PropertyBag.AddValue("State","Healthy")
$PropertyBag.AddValue("MessageText",$Arguments)}
$PropertyBag
#///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Paste the script in the Script field and click the Parameters button:
Important Note:
The input parameter value can ONLY be accessed in the script by using the $Arguments variable - param($Arguments) :
You can use a static string or any target variables accessible via the Target menu in the Parameters field of the pop-up page:
Provide the expressions based on the value in the Propertybag and map monitor conditions to health states (If the length of the string value of $Arguments exceeds 10, change monitor state to Critical/Warning, else monitor state is Healthy):
The Expression Builder Pages builds expression that looks for a particular value from the Propertybag that the data source outputs
(Property[@Name='State'] ).
Specify the name of the value in the Propertybag in the alert context variable: $Data/Context/Property[@Name='Description']$
Here is an example of the active alert generated and the state change recorded:
Disclaimer:
All information on this blog is provided on an as-is basis with no warranties and for informational purposes only. Use at your own risk. The opinions and views expressed in this blog are those of the author and do not necessarily state or reflect those of my employer.
Comments
Anonymous
July 12, 2015
Hi Wei, Once again you have blown our minds with providing a fundamental feature, which is missing from the product and with simplicity!!! Works like a dream of course!! Thanks for the share!!! DimiAnonymous
July 12, 2015
The comment has been removedAnonymous
July 20, 2015
Thanks for updated MP. Trying to run SQL Query Scripts. The SQL Run As Account has access to Databases. How can this be achieved?Anonymous
July 25, 2015
Resolved SQL Query scripts issue by adding SQL RunAsAccount (Which had permissions) As SecureReference and RunAs to both Modules.Anonymous
January 25, 2016
Hello, I have error in event viewer The PowerShell script failed with below exception System.Management.Automation.IncompleteParseException: Missing closing '}' in statement block. at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) at Microsoft.EnterpriseManagement.Common.PowerShell.RunspaceController.RunScript[T](String scriptName, String scriptBody, Dictionary2 parameters, Object[] constructorArgs, IScriptDebug iScriptDebug, Boolean bSerializeOutput) Script Name: HardDriveOnline.ps1 script body The PowerShell script failed with below exception System.Management.Automation.IncompleteParseException: Missing closing '}' in statement block. at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) at Microsoft.EnterpriseManagement.Common.PowerShell.RunspaceController.RunScript[T](String scriptName, String scriptBody, Dictionary
2 parameters, Object[] constructorArgs, IScriptDebug iScriptDebug, Boolean bSerializeOutput) SCRIPT BODY $oAPI = new-object -comObject "MOM.ScriptAPI" $pb = $oAPI.CreatePropertyBag() $dsk=Get-Disk -number 5 | where { $_.OperationalStatus -eq 'online' } if ($dsk.OperationalStatus -eq 'online' ){ $pb.AddValue("State", "Healthy") $pb.AddValue("Message", "диск на месте:$dsk")} else { $pb.AddValue("State", "Critical") $pb.AddValue("Message", "Отключен диск:$dsk")} $pb #return Bag I do not understand where the errorAnonymous
February 12, 2016
Hello Wei, I get an error trying to import the MP with SCOM 2012 R2 UR9. Where do you find the Microsoft IntelligencePacks Performance and Microsoft IntelligencePacks Types? Is it some OMS or System Advisor MP that you have as a dependency?Anonymous
February 12, 2016
Hello Kevin, I have just uploaded a version without the OMS integration. If you choose to continue using the version with the OMS integration, I think you can also download the Microsoft.IntelligencePack.Core that contains icrosoft.IntelligencePacks.Types from //systemcentercore.com/?Get_ManagementPackBundle=Microsoft.IntelligencePack.Core.mpb&FileMD5=B57A456BBA72AC7C3DFE0B039F615F40Anonymous
July 27, 2016
The comment has been removedAnonymous
July 27, 2016
Just found out:I missed the following in my script:. ([Scriptblock]::Create($Arguments))Thanks a lot Ken for your comments!And Thanks Wei for the article! It helps a lot!Anonymous
July 05, 2017
The comment has been removed- Anonymous
July 06, 2017
Thank you for your support Christian. Did you use the v2 versionthat I shared 2 years ago ? or the original one that was released 4 years ago ? v2 should allow you to use the Parameters function.
- Anonymous