Running the following script on the probe device itself returns the correct value as it should, but running it via the senor it returns the value 0. Seems to be an issue with the Foreach loop? How can I get the right output returned to the map?

$checkservice=((Get-EC2Instance -Region us-east-1) | Select -ExpandProperty RunningInstance | where {$_.Tag.Key -eq "K12-Function" -and $_.Tag.Value -eq "jsched-asg"} | select -ExpandProperty PrivateIpAddress) $cnt=@(Foreach ($InstanceID in $checkservice) { invoke-command {get-service bbk12* -computername $args[0] | where {$_.Status -eq 'Running'}} -ArgumentList $InstanceID }).count write-host $cnt":ok"

Steven Belanger


Article Comments

Dear Steven,

I assume that the foreach loop is correct, but that the statement

$checkservice=((Get-EC2Instance -Region us-east-1) | Select -ExpandProperty RunningInstance | where {$_.Tag.Key -eq "K12-Function" -and $_.Tag.Value -eq "jsched-asg"} | select -ExpandProperty PrivateIpAddress)

yields an error message, or a different result when you run it with the 32 bit powershell. Please test that. If the 32 bit powershell shows the correct output, please check the sensor settings if you use the context of the probe, or the Windows credentials of the device object.


May, 2018 - Permalink

Arne Seifert,

Changing the sensors Security Context setting to "Use Windows credentials of parent device" allowed the sensor to return the correct value of the script. Thanks for your help!

Steven Belanger


May, 2018 - Permalink