Hi.

I have created a powershell script that reports the status of the value of NetworkCategory from Get-NetConnectionProfile.

My custom EXE/Powershell script is...

$ConProf = Get-NetConnectionProfile | Select -ExpandProperty NetworkCategory
If ($ConProf -eq "DomainAuthenticated") {write-output 0:Domain} else {write-output 1:Non-Domain}

When executed manually (using enter-pssession) from the PRTG server (probe) to a remote machine it returns "0", which is correct and expected.

However, the sensor returns the value of "1", which is incorrect. Where have I gone wrong?


Article Comments

Are you running that manually from the target? EXE/Script sensors always execute on the probe unless you add code to run on a remote machine, which I dot see in your script, you might want to add a Invoke-Command section to specify the remote machine you want to run this one. We recommend to submit a ticket to support@paessler.com to attach more information.


Apr, 2023 - Permalink

Yes, of course! Thanks for the suggestion. I updated my script and it worked.

I was previously just using enter-pssession from the PRTG probe to the remote computer in question to test the script worked, which is where the unexpected behaviour originated from.

For everyone's benefit, here is my complete script...

param ($Server)
Invoke-Command -ScriptBlock {
$ConProf = Get-NetConnectionProfile | Select -ExpandProperty NetworkCategory
If ($ConProf -eq "DomainAuthenticated") {write-output 0:Domain} else {write-output 1:Non-Domain}
} -ComputerName $Server

Then I added the following as the parameters on the EXE sensor settings...

-server %host

I then cloned my sensor to all other Windows servers.

Thanks for your help!


Apr, 2023 - Permalink