This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Windows PowerShell Monitor Output Undefined

Hi Thwack Community,

I'm writing a powershell monitor to review the status of servers running in a Storage Replica. The idea is that they will review the "IsPrimary" Value, and if the value is true it will check whether shares are available, and if not then the monitor is down.

I have '${Caption}' defined in the Script Arguments, and I am running in Local Host mode.

The script is as below:

Invoke-Command -Computername '${Caption}' -UseSSL -Credential '${Credential} -ScriptBlock {

$SMBShareCheck = Get-SMBShare | measure

$Primary = "True"

$SRMemberStatus = Get-SRGRoup | Select-Object -ExpandProperty IsPrimary

If ($SRMemberStatus -eq $Primary){

If ($SMBShareCheck.Count -lt 1){

Write-Host 'Down'; Exit 1

}

else

{Write-Host 'Up'; Exit 0}

}

else

{Write-Host 'Up'; Exit 0}

}

I have tested this from the poller using Powershell ISE and it works great. If I use it in the Monitor I get

"Output Result:

ND Not Defined"

Anyone know what I'm doing wrong?

  • If I understand how the SAM component for Powershell works, you have to return a statistic as part of the script for it to work.

    i.e.

    IF ($SMBShareCheck.Count -lt 1)

    {

    Write-Host "Statistic.Status:" 0

    Write-Host "Message.Status: Down"

    }

    You can still use exit codes to determine status or use the statistic value to move the component into a warning or critical status. 

  • OK I've changed that but it still doesn't like it unfortunately. Still testing ok direct from the poller:

    The script now looks like:

    Invoke-Command -Computername '${Caption}' -UseSSL -Credential '${Credential}' -ScriptBlock {

    $SMBShareCheck = Get-SMBShare | measure

    $Primary = "True"

    $SRMemberStatus = Get-SRGRoup | Select-Object -ExpandProperty IsPrimary

    If ($SRMemberStatus -eq $Primary){

    If ($SMBShareCheck.Count -lt 1){

    Write-Host "Statistic.Status: 1"

    Write-Host "Message.Status: Down"

    Exit 1

    }

    else

    {Write-Host "Statistic.Status: 0"

    Write-Host "Message.Status: Up"

    Exit 0}

    }

    else

    {Write-Host "Statistic.Status: 0"

    Write-Host "Message.Status: Up"

    Exit 0}

    }

  • did you  ever get this working?  i would love to do monitoring of our storage replication.