Powershell Unit Monitor - Not alerting, health state unchanged

I have created a 2 state Unit Monitor using the Community Powershell MP. However the state isn’t changing (and therefore alerting). The script is based on the Get-PendingReboot function written by Brian Wilhite. My intention is to replace the Aquilaweb Pending Reboot MP that is VBS based.

Script is here:

https://raw.githubusercontent.com/chrismackenzie/Community.PowerShellMonitoring.MP/master/Samples/Monitors/Get-PendingReboot.ps1

The Unit Monitor:

  • Targets "Windows Server Operating System"
  • Is disabled by default
  • Runs every 5 mins (for testing)
  • Is unhealthy if Property[@Name='RebootPending'] Equals Yes
  • Is healthy if Property[@Name='RebootPending'] Equals No
I have an override that enables for all objects of class "Windows Server Operating System"

If I check health explorer I can see the monitor in a healthy state, however if I run the script locally on a system (and uncomment the line so to return the property bag), I get no script errors and can see in the XML that the RebootPending value is Yes.

I was originally work with Boolean values, however in troubleshooting have change all of the propertybag values to use strings (and have verified that they are indeed strings).

With no errors showing anywhere i’m running out of ideas!

Hi

Its hard to tell without the monitor itself. Can you paste the code?

I usually do more logging to the eventlog in ps-scripts, that way its easier to follow the steps and see what the different output is. Just a tip :slight_smile:

Hi Peter,

I thought about using the eventlog, it is odd that I am not seeing any errors in script execution though. As you can see in the code snippet below, I have also added it as a Task, which returns the desired output when run… must be something with the monitor itself. FWIW this is SCOM 2016.

 

<?xml version="1.0" encoding="utf-8"?><ManagementPack ContentReadable="true" SchemaVersion="2.0" OriginalSchemaVersion="1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <Manifest>
    <Identity>
      <ID>BKLPRODReboot</ID>
      <Version>1.0.0.0</Version>
    </Identity>
    <Name>BKL-PROD-Reboot</Name>
    <References>
      <Reference Alias="MicrosoftWindowsLibrary7585010">
        <ID>Microsoft.Windows.Library</ID>
        <Version>7.5.8501.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
      <Reference Alias="SystemLibrary7585010">
        <ID>System.Library</ID>
        <Version>7.5.8501.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
      <Reference Alias="PowerShellMonitoring">
        <ID>Community.PowerShellMonitoring</ID>
        <Version>1.1.1.2</Version>
        <PublicKeyToken>3aa540324b898d3c</PublicKeyToken>
      </Reference>
      <Reference Alias="SystemCenter">
        <ID>Microsoft.SystemCenter.Library</ID>
        <Version>7.0.8437.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
      <Reference Alias="Health">
        <ID>System.Health.Library</ID>
        <Version>7.0.8437.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
    </References>
  </Manifest>
  <Monitoring>
    <Tasks>
      <Task ID="ConsoleTaskGeneratedByUI8980d9d7989343879312173f5ce8dbe0" Accessibility="Public" Enabled="true" Target="MicrosoftWindowsLibrary7585010!Microsoft.Windows.Server.OperatingSystem" Timeout="300" Remotable="true" CanSuspend="false" CanCancel="false">
        <Category>Custom</Category>
        <WriteAction ID="PA" TypeID="PowerShellMonitoring!Community.PowerShellMonitoring.WriteAction.SimplePowerShellScript">
          <ScriptName>taskgetpendingreboot.ps1</ScriptName>
          <Arguments>$Target/Host/Property[Type="MicrosoftWindowsLibrary7585010!Microsoft.Windows.Computer"]/NetbiosComputerName$</Arguments>
          <ScriptBody>  [CmdletBinding()]
Param([string]$Arguments = "Localhost")

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

Try {
           

    ## Setting pending values to false to cut down on the number of else statements
       $WUAURebootReq,$CompPendRen,$PendFileRename,$Pending,$SCCM = $false,$false,$false,$false,$false
    $strWUAURebootReq,$strCompPendRen,$strPendFileRename,$strPending,$strSCCM = "No","No","No","No","No"
                        
       ## Setting CBSRebootPend to null since not all versions of Windows has this value
       $CBSRebootPend = $null
    $strCBSRebootPend = "N/A"
                                       
       ## Querying WMI for build version
       $WMI_OS = Get-WmiObject -Class Win32_OperatingSystem -Property BuildNumber, CSName -ComputerName $Arguments -ErrorAction Stop

       ## Making registry connection to the local/remote computer
       $HKLM = [UInt32] "0x80000002"
       $WMI_Reg = [WMIClass] "\\$Arguments\root\default:StdRegProv"
                                       
       ## If Vista/2008 &amp; Above query the CBS Reg Key
       If ([Int32]$WMI_OS.BuildNumber -ge 6001) {
             $RegSubKeysCBS = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")
             $CBSRebootPend = $RegSubKeysCBS.sNames -contains "RebootPending"
        If ($CBSRebootPend) {
             $strCBSRebootPend = "Yes"
           }
        Else{
        $strCBSRebootPend = "No"
        }
       }
                                              
       ## Query WUAU from the registry
       $RegWUAURebootReq = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\")
       $WUAURebootReq = $RegWUAURebootReq.sNames -contains "RebootRequired"
    If ($WUAURebootReq) {
             $strWUAURebootReq = "Yes"
       }      
                                       
       ## Query PendingFileRenameOperations from the registry
       $RegSubKeySM = $WMI_Reg.GetMultiStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\","PendingFileRenameOperations")
       If (($RegSubKeySM.sValue -like '*SEP*') -or $RegSubKeySM.sValue -like '*spool*') {
       }
       Else{
             $RegValuePFRO = $RegSubKeySM.sValue
       }

       ## Query JoinDomain key from the registry - These keys are present if pending a reboot from a domain join operation
       $Netlogon = $WMI_Reg.EnumKey($HKLM,"SYSTEM\CurrentControlSet\Services\Netlogon").sNames
       $PendDomJoin = ($Netlogon -contains 'JoinDomain') -or ($Netlogon -contains 'AvoidSpnSet')
    If ($PendDomJoin) {
             $strPendDomJoin = "Yes"
       }      

       ## Query ComputerName and ActiveComputerName from the registry
       $ActCompNm = $WMI_Reg.GetStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\","ComputerName")            
       $CompNm = $WMI_Reg.GetStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\","ComputerName")

       If (($ActCompNm -ne $CompNm) -or $PendDomJoin) {
           $CompPendRen = $true
        If ($CompPendRen) {
             $strCompPendRen = "Yes"
       }      
       }
                                       
       ## If PendingFileRenameOperations has a value set $RegValuePFRO variable to $true
       If ($RegValuePFRO) {
             $PendFileRename = $true
        $strPendFileRename = "Yes"
        $strRegValuePFRO = $RegValuePFRO
       }
    Else {
    $strRegValuePFRO = "N/A"
    }

       ## Determine SCCM 2012 Client Reboot Pending Status
       ## To avoid nested 'if' statements and unneeded WMI calls to determine if the CCM_ClientUtilities class exist, setting EA = 0
       $CCMClientSDK = $null
       $CCMSplat = @{
           NameSpace='ROOT\ccm\ClientSDK'
           Class='CCM_ClientUtilities'
           Name='DetermineIfRebootPending'
           ComputerName=$Arguments
           ErrorAction='Stop'
       }
       ## Try CCMClientSDK
       Try {
           $CCMClientSDK = Invoke-WmiMethod@CCMSplat 
       } Catch [System.UnauthorizedAccessException] {
           $CcmStatus = Get-Service -Name CcmExec -ComputerName $Arguments -ErrorAction SilentlyContinue
           If ($CcmStatus.Status -ne 'Running') {
               Write-Warning "$Arguments`: Error - CcmExec service is not running."
               $CCMClientSDK = $null
           }
       } Catch {
           $CCMClientSDK = $null
       }

       If ($CCMClientSDK) {
           If ($CCMClientSDK.ReturnValue -ne 0) {
                 Write-Warning "Error: DetermineIfRebootPending returned error code $($CCMClientSDK.ReturnValue)"          
             }
             If ($CCMClientSDK.IsHardRebootPending -or $CCMClientSDK.RebootPending) {
                 $SCCM = $true
            If ($SCCM) {
                     $strSCCM = "Yes"
                   } 
             }
       }
            
       Else {
           $SCCM = $null
        $strSCCM = "No"
       }

    $Pending= ($CompPendRen -or $CBSRebootPend -or $WUAURebootReq -or $SCCM -or $PendFileRename)
    If ($Pending) {
             $strPending = "Yes"
       }      
}

Finally {

    write-host "Computer: " $WMI_OS.CSName
    write-host "CBServicing: " $strCBSRebootPend
    write-host "WindowsUpdate: " $strWUAURebootReq
    write-host "CCMClientSDK: " $strSCCM
    write-host "PendComputerRename: " $strCompPendRen
    write-host "PendFileRename: " $strPendFileRename
    write-host "PendFileRenVal: " $strRegValuePFRO
    write-host "RebootPending: " $strPending
&lt;#
    write-host "Computer: " $WMI_OS.CSName.GetType().FullName
    write-host "CBServicing: " $strCBSRebootPend.GetType().FullName
    write-host "WindowsUpdate: " $strWUAURebootReq.GetType().FullName
    write-host "CCMClientSDK: " $strSCCM.GetType().FullName
    write-host "PendComputerRename: " $strCompPendRen.GetType().FullName
    write-host "PendFileRename: " $strPendFileRename.GetType().FullName
    write-host "PendFileRenVal: " $strRegValuePFRO.GetType().FullName
    write-host "RebootPending: " $strPending.GetType().FullName
   #&gt;
    # Context for alert or performance collection
    $PropertyBag.AddValue("Computer",[string]$WMI_OS.CSName)
    $PropertyBag.AddValue("CBServicing",[string]$strCBSRebootPend)
    $PropertyBag.AddValue("WindowsUpdate",[string]$strWUAURebootReq)
    $PropertyBag.AddValue("CCMClientSDK",[string]$strSCCM)
    $PropertyBag.AddValue("PendComputerRename",[string]$strCompPendRen)
    $PropertyBag.AddValue("PendFileRename",[string]$strPendFileRename)
    $PropertyBag.AddValue("PendFileRenVal",[string]$strRegValuePFRO)
    $PropertyBag.AddValue("RebootPending",[string]$strPending)

    # Send output to SCOM
    #$PropertyBag

}</ScriptBody>
          <TimeoutSeconds>60</TimeoutSeconds>
        </WriteAction>
      </Task>
    </Tasks>
    <Monitors>
      <UnitMonitor ID="UIGeneratedMonitor6fa21531da0f4660a3dd348159f87876" Accessibility="Public" Enabled="false" Target="MicrosoftWindowsLibrary7585010!Microsoft.Windows.Server.OperatingSystem" ParentMonitorID="Health!System.Health.ConfigurationState" Remotable="true" Priority="Normal" TypeID="PowerShellMonitoring!Community.PowerShellMonitoring.UnitMonitors.PowerShellTwoState" ConfirmDelivery="false">
        <Category>Custom</Category>
        <AlertSettings AlertMessage="UIGeneratedMonitor6fa21531da0f4660a3dd348159f87876_AlertMessageResourceID">
          <AlertOnState>Warning</AlertOnState>
          <AutoResolve>true</AutoResolve>
          <AlertPriority>Low</AlertPriority>
          <AlertSeverity>Warning</AlertSeverity>
          <AlertParameters>
            <AlertParameter1>$Target/Host/Property[Type="MicrosoftWindowsLibrary7585010!Microsoft.Windows.Computer"]/DNSName$</AlertParameter1>
          </AlertParameters>
        </AlertSettings>
        <OperationalStates>
          <OperationalState ID="UIGeneratedOpStateId091500b459884706b9a5a9e65eec8664" MonitorTypeStateID="Healthy" HealthState="Success" />
          <OperationalState ID="UIGeneratedOpStateId08b30f50e3424eb18cce49f82e7968da" MonitorTypeStateID="Unhealthy" HealthState="Warning" />
        </OperationalStates>
        <Configuration>
          <IntervalSeconds>300</IntervalSeconds>
          <SyncTime />
          <ScriptName>GetPendingReboot.ps1</ScriptName>
          <ScriptBody> [CmdletBinding()]
Param([string]$Arguments = "Localhost")

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

Try {
           

    ## Setting pending values to false to cut down on the number of else statements
       $WUAURebootReq,$CompPendRen,$PendFileRename,$Pending,$SCCM = $false,$false,$false,$false,$false
    $strWUAURebootReq,$strCompPendRen,$strPendFileRename,$strPending,$strSCCM = "No","No","No","No","No"
                        
       ## Setting CBSRebootPend to null since not all versions of Windows has this value
       $CBSRebootPend = $null
    $strCBSRebootPend = "N/A"
                                       
       ## Querying WMI for build version
       $WMI_OS = Get-WmiObject -Class Win32_OperatingSystem -Property BuildNumber, CSName -ComputerName $Arguments -ErrorAction Stop

       ## Making registry connection to the local/remote computer
       $HKLM = [UInt32] "0x80000002"
       $WMI_Reg = [WMIClass] "\\$Arguments\root\default:StdRegProv"
                                       
       ## If Vista/2008 &amp; Above query the CBS Reg Key
       If ([Int32]$WMI_OS.BuildNumber -ge 6001) {
             $RegSubKeysCBS = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")
             $CBSRebootPend = $RegSubKeysCBS.sNames -contains "RebootPending"
        If ($CBSRebootPend) {
             $strCBSRebootPend = "Yes"
           }
        Else{
        $strCBSRebootPend = "No"
        }
       }
                                              
       ## Query WUAU from the registry
       $RegWUAURebootReq = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\")
       $WUAURebootReq = $RegWUAURebootReq.sNames -contains "RebootRequired"
    If ($WUAURebootReq) {
             $strWUAURebootReq = "Yes"
       }      
                                       
       ## Query PendingFileRenameOperations from the registry
       $RegSubKeySM = $WMI_Reg.GetMultiStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\","PendingFileRenameOperations")
       If (($RegSubKeySM.sValue -like '*SEP*') -or $RegSubKeySM.sValue -like '*spool*') {
       }
       Else{
             $RegValuePFRO = $RegSubKeySM.sValue
       }

       ## Query JoinDomain key from the registry - These keys are present if pending a reboot from a domain join operation
       $Netlogon = $WMI_Reg.EnumKey($HKLM,"SYSTEM\CurrentControlSet\Services\Netlogon").sNames
       $PendDomJoin = ($Netlogon -contains 'JoinDomain') -or ($Netlogon -contains 'AvoidSpnSet')
    If ($PendDomJoin) {
             $strPendDomJoin = "Yes"
       }      

       ## Query ComputerName and ActiveComputerName from the registry
       $ActCompNm = $WMI_Reg.GetStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\","ComputerName")            
       $CompNm = $WMI_Reg.GetStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\","ComputerName")

       If (($ActCompNm -ne $CompNm) -or $PendDomJoin) {
           $CompPendRen = $true
        If ($CompPendRen) {
             $strCompPendRen = "Yes"
       }      
       }
                                       
       ## If PendingFileRenameOperations has a value set $RegValuePFRO variable to $true
       If ($RegValuePFRO) {
             $PendFileRename = $true
        $strPendFileRename = "Yes"
        $strRegValuePFRO = $RegValuePFRO
       }
    Else {
    $strRegValuePFRO = "N/A"
    }

       ## Determine SCCM 2012 Client Reboot Pending Status
       ## To avoid nested 'if' statements and unneeded WMI calls to determine if the CCM_ClientUtilities class exist, setting EA = 0
       $CCMClientSDK = $null
       $CCMSplat = @{
           NameSpace='ROOT\ccm\ClientSDK'
           Class='CCM_ClientUtilities'
           Name='DetermineIfRebootPending'
           ComputerName=$Arguments
           ErrorAction='Stop'
       }
       ## Try CCMClientSDK
       Try {
           $CCMClientSDK = Invoke-WmiMethod@CCMSplat 
       } Catch [System.UnauthorizedAccessException] {
           $CcmStatus = Get-Service -Name CcmExec -ComputerName $Arguments -ErrorAction SilentlyContinue
           If ($CcmStatus.Status -ne 'Running') {
               Write-Warning "$Arguments`: Error - CcmExec service is not running."
               $CCMClientSDK = $null
           }
       } Catch {
           $CCMClientSDK = $null
       }

       If ($CCMClientSDK) {
           If ($CCMClientSDK.ReturnValue -ne 0) {
                 Write-Warning "Error: DetermineIfRebootPending returned error code $($CCMClientSDK.ReturnValue)"          
             }
             If ($CCMClientSDK.IsHardRebootPending -or $CCMClientSDK.RebootPending) {
                 $SCCM = $true
            If ($SCCM) {
                     $strSCCM = "Yes"
                   } 
             }
       }
            
       Else {
           $SCCM = $null
        $strSCCM = "No"
       }

    $Pending= ($CompPendRen -or $CBSRebootPend -or $WUAURebootReq -or $SCCM -or $PendFileRename)
    If ($Pending) {
             $strPending = "Yes"
       }      
}

Finally {

    &lt;#
    write-host "Computer: " $WMI_OS.CSName
    write-host "CBServicing: " $strCBSRebootPend
    write-host "WindowsUpdate: " $strWUAURebootReq
    write-host "CCMClientSDK: " $strSCCM
    write-host "PendComputerRename: " $strCompPendRen
    write-host "PendFileRename: " $strPendFileRename
    write-host "PendFileRenVal: " $strRegValuePFRO
    write-host "RebootPending: " $strPending

    write-host "Computer: " $WMI_OS.CSName.GetType().FullName
    write-host "CBServicing: " $strCBSRebootPend.GetType().FullName
    write-host "WindowsUpdate: " $strWUAURebootReq.GetType().FullName
    write-host "CCMClientSDK: " $strSCCM.GetType().FullName
    write-host "PendComputerRename: " $strCompPendRen.GetType().FullName
    write-host "PendFileRename: " $strPendFileRename.GetType().FullName
    write-host "PendFileRenVal: " $strRegValuePFRO.GetType().FullName
    write-host "RebootPending: " $strPending.GetType().FullName
    #&gt;
    
    # Context for alert or performance collection
    ##$PropertyBag.AddValue("Computer",[string]$WMI_OS.CSName)
    $PropertyBag.AddValue("CBServicing",[string]$strCBSRebootPend)
    $PropertyBag.AddValue("WindowsUpdate",[string]$strWUAURebootReq)
    $PropertyBag.AddValue("CCMClientSDK",[string]$strSCCM)
    $PropertyBag.AddValue("PendComputerRename",[string]$strCompPendRen)
    $PropertyBag.AddValue("PendFileRename",[string]$strPendFileRename)
    ##$PropertyBag.AddValue("PendFileRenVal",[string]$strRegValuePFRO)
    $PropertyBag.AddValue("RebootPending",[string]$strPending)

    # Send output to SCOM
    $PropertyBag
    ##$ScomAPI.Return($PropertyBag)

} 
</ScriptBody>
          <Arguments>$Target/Host/Property[Type="MicrosoftWindowsLibrary7585010!Microsoft.Windows.Computer"]/NetbiosComputerName$</Arguments>
          <TimeoutSeconds>60</TimeoutSeconds>
          <UnhealthyExpression>
            <SimpleExpression>
              <ValueExpression>
                <XPathQuery>Property[@Name='RebootPending']</XPathQuery>
              </ValueExpression>
              <Operator>Equal</Operator>
              <ValueExpression>
                <Value Type="String">Yes</Value>
              </ValueExpression>
            </SimpleExpression>
          </UnhealthyExpression>
          <HealthyExpression>
            <SimpleExpression>
              <ValueExpression>
                <XPathQuery>Property[@Name='RebootPending']</XPathQuery>
              </ValueExpression>
              <Operator>Equal</Operator>
              <ValueExpression>
                <Value Type="String">No</Value>
              </ValueExpression>
            </SimpleExpression>
          </HealthyExpression>
        </Configuration>
      </UnitMonitor>
    </Monitors>
    <Overrides>
      <MonitorPropertyOverride ID="Alias412b243bff814093a1df6415f56528bcOverrideForMonitorUIGeneratedMonitor6fa21531da0f4660a3dd348159f87876ForContextMicrosoftWindowsServerOperatingSystem" Context="MicrosoftWindowsLibrary7585010!Microsoft.Windows.Server.OperatingSystem" Enforced="false" Monitor="UIGeneratedMonitor6fa21531da0f4660a3dd348159f87876" Property="Enabled">
        <Value>true</Value>
      </MonitorPropertyOverride>
    </Overrides>
  </Monitoring>
  <Presentation>
    <Folders>
      <Folder ID="Folder_02e878bf601a4064875be2bfb13c2a26" Accessibility="Public" ParentFolder="SystemCenter!Microsoft.SystemCenter.Monitoring.ViewFolder.Root" />
    </Folders>
    <StringResources>
      <StringResource ID="UIGeneratedMonitor6fa21531da0f4660a3dd348159f87876_AlertMessageResourceID" />
    </StringResources>
  </Presentation>
  <LanguagePacks>
    <LanguagePack ID="ENU" IsDefault="false">
      <DisplayStrings>
        <DisplayString ElementID="BKLPRODReboot">
          <Name>BKL-PROD-Reboot</Name>
        </DisplayString>
        <DisplayString ElementID="Folder_02e878bf601a4064875be2bfb13c2a26">
          <Name>BKL-PROD-Reboot</Name>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitor6fa21531da0f4660a3dd348159f87876">
          <Name>Pending Reboot</Name>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitor6fa21531da0f4660a3dd348159f87876_AlertMessageResourceID">
          <Name>Pending Reboot</Name>
          <Description>The system {0} has a reboot pending.</Description>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitor6fa21531da0f4660a3dd348159f87876" SubElementID="UIGeneratedOpStateId091500b459884706b9a5a9e65eec8664">
          <Name>Healthy</Name>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitor6fa21531da0f4660a3dd348159f87876" SubElementID="UIGeneratedOpStateId08b30f50e3424eb18cce49f82e7968da">
          <Name>Unhealthy</Name>
        </DisplayString>
        <DisplayString ElementID="ConsoleTaskGeneratedByUI8980d9d7989343879312173f5ce8dbe0">
          <Name>Get Pending Reboot</Name>
        </DisplayString>
      </DisplayStrings>
    </LanguagePack>
    <LanguagePack ID="ENA" IsDefault="false">
      <DisplayStrings>
        <DisplayString ElementID="UIGeneratedMonitor6fa21531da0f4660a3dd348159f87876" SubElementID="UIGeneratedOpStateId091500b459884706b9a5a9e65eec8664">
          <Name>Healthy</Name>
        </DisplayString>
        <DisplayString ElementID="UIGeneratedMonitor6fa21531da0f4660a3dd348159f87876" SubElementID="UIGeneratedOpStateId08b30f50e3424eb18cce49f82e7968da">
          <Name>Unhealthy</Name>
        </DisplayString>
        <DisplayString ElementID="ConsoleTaskGeneratedByUI8980d9d7989343879312173f5ce8dbe0">
          <Name>Get Pending Reboot</Name>
        </DisplayString>
      </DisplayStrings>
    </LanguagePack>
  </LanguagePacks>
</ManagementPack>

Can you try to change the script so that you dont do any test for wmi/regvalue and only return yes to the propertybag and see that the monitor picks up the value. So you can rule out that the monitor is faulty.

I have come across a monitor where the script runs fine I run it but fails most of the time when scom runs it.

The error seems to be that system (the monitoring account in that case) gets access denied to wmi now and then. That happens less often when I run it as my user but it did happen after I had tested the script a couple of times.

I have an ongoing case with microsoft regarding that management pack but they have not found the issue yet.

You have a timeout of 60 seconds for the script. Do you know how long it takes to execute?

I would for testing purposes write to the event-log for every query just to see that you get the right output.

So i’ve just come back to this and was about to do the tests that both@jannep and@peter have suggested (basic test and use event log). However the monitor appears to be working now!?! The last changes I made were to comment out:

##$PropertyBag.AddValue("Computer",[string]$WMI_OS.CSName)
##$PropertyBag.AddValue("PendFileRenVal",[string]$strRegValuePFRO)

As I don’t really need the computer name, and I noticed that strRegValuePFRO was returning as a string array. I suspect the latter was the real culprit here.

So thanks for your guidance. A couple of good troubleshooting tips I hadn’t tried and will keep them in mind for next time!

1 Like