locked
Newly created 2 state script based monitor does not work RRS feed

  • Question

  • Hi All,

    I referred 2 links as below and tried to create a 2 state script based monitor.

    http://blog.coretech.dk/clm/example-of-setting-up-a-custom-monitor-in-scom-with-a-powershell-script-monitor-nic-teams-in-scom/

    http://www.systemcentercentral.com/wp-content/uploads/2009/04/HOW-TO_2-state_ScriptMonitor.pdf

    It seems to not work as expected. I get event ID 21405 logged mentioning that it is failing as below:

     

    The process started at 22:40:14 failed to create System.PropertyBagData, no errors detected in the output.  The process exited with 1

    Command executed: "C:\Windows\system32\cscript.exe" /nologo "Servicemon.ps1"
    Working Directory: C:\Program Files\Microsoft System Center 2012 R2\Operations Manager\Server\Health Service State\Monitoring Host Temporary Files 93\51099\ 

    One or more workflows were affected by this.  

    Workflow name: UIGeneratedMonitor3180f81488dc48bb82aed10cc3ee6f3a 
    Instance name: MymanagementserverFQDN
    Instance ID: {7763C0F5-60AA-362A-4225-5D45C89E21BB} 
    Management group: MYMG

    Aim: I need to execute the Powershell script which will give me a output.

    Now i need to alert based on the output of the script.

    Ex: I'm trying to query a network Interface on a server using the below Powershell script which will provide me an output of UP or Down directly when i execute it.

    Get-NetAdapter | Where-Object {$_.Name -eq "Corporate Network"} | Select Adminstatus -ExpandProperty Adminstatus

    So if it is down i want a Critical health state, If it is Up i need it healthy

    This is how it is configured in SCOM:

    $api = New-Object -comObject "MOM.ScriptAPI"
    $PropertyBag = $api.CreatePropertyBag()

    $speed = Get-NetAdapter | Where-Object {$_.Name -eq "Corporate Network"} | Select Adminstatus -ExpandProperty Adminstatus

    $PropertyBag.AddValue("Speed","$speed")
    $PropertyBag

    Unhealthy:

    Healthy:

    Does any one know what is wrong here ? Why is this not working ? What needs to be corrected.


    • Edited by Tech_Guy2015 Thursday, February 23, 2017 6:12 PM
    Thursday, February 23, 2017 6:11 PM

Answers

  • Hi There,

    Ensure you have imported the Powershell MP as mentioned by Brian.

    https://gallery.technet.microsoft.com/Sample-Management-Pack-17b76379

    I have modified the code as per your requirement and this should work.

    $api = New-Object -comObject "MOM.ScriptAPI"
    $PropertyBag = $api.CreatePropertyBag()

    [string]$speed = Get-NetAdapter | Where-Object {$_.Name -eq "Corporate Network"} | Select Adminstatus -ExpandProperty Adminstatus

    $PropertyBag.AddValue("Speed",$speed)
    $PropertyBag


    Gautam.75801

    • Marked as answer by Tech_Guy2015 Monday, February 27, 2017 6:28 PM
    Monday, February 27, 2017 4:35 PM

All replies

  • Looks like you're creating this in the Operations Console.  That wizard only supports VBScript, not PowerShell.  You need to use another tool like Visual Studio Authoring Extensions or MP Author for a PowerShell monitor.

    This posting is provided "AS IS" with no warranties, and confers no rights. Use of attachments are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    Friday, February 24, 2017 12:10 AM
  • Hi Brian,

    Thank you for the reply. Not sure on what basis the Author of the below blog made this.

    http://blog.coretech.dk/clm/example-of-setting-up-a-custom-monitor-in-scom-with-a-powershell-script-monitor-nic-teams-in-scom/

    But as you mentioned from Silect Authoring it is possible, But is there no way we can create a similar powershell monitor from the Authoring pane in the SCOM Console its self ?

    Friday, February 24, 2017 12:21 PM
  • The process in that blog requires Wei's MP that gives you an option to create a PowerShell script monitor in the Operations Console. Do you have that installed?  The error you posted had cscript.exe which is the VBScript executable. 

    This posting is provided "AS IS" with no warranties, and confers no rights. Use of attachments are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    Saturday, February 25, 2017 3:52 AM
  • In order to execute the Powershell script, you need to change the below working directory to "powershell installed file like powershell.exe in your server". It should work after this change.

    I recently created a powershell script and getting this script executed via SCOM console and routing the output to a text file. It worked for me.

    Command executed: "C:\Windows\system32\cscript.exe" /nologo "Servicemon.ps1"
    Working Directory: C:\Program Files\Microsoft System Center 2012 R2\Operations Manager\Server\Health Service State\Monitoring Host Temporary Files 93\51099\ 

    Sunday, February 26, 2017 5:01 AM
  • Hi There,

    Ensure you have imported the Powershell MP as mentioned by Brian.

    https://gallery.technet.microsoft.com/Sample-Management-Pack-17b76379

    I have modified the code as per your requirement and this should work.

    $api = New-Object -comObject "MOM.ScriptAPI"
    $PropertyBag = $api.CreatePropertyBag()

    [string]$speed = Get-NetAdapter | Where-Object {$_.Name -eq "Corporate Network"} | Select Adminstatus -ExpandProperty Adminstatus

    $PropertyBag.AddValue("Speed",$speed)
    $PropertyBag


    Gautam.75801

    • Marked as answer by Tech_Guy2015 Monday, February 27, 2017 6:28 PM
    Monday, February 27, 2017 4:35 PM
  • Hi There,

    Thanks a lot.

    It worked now as expected. The alert was generated when the network interface was down.

    Monday, February 27, 2017 6:29 PM