What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Powershell/EXE custom sensor: confusing output

Votes:

0

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?

custom powershell results

Created on Apr 18, 2023 10:38:01 AM

Last change on Apr 18, 2023 10:38:01 AM



2 Replies

Votes:

1

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 [email protected] to attach more information.

Created on Apr 21, 2023 9:06:23 PM by  Jonathan Mena [Paessler Technical Support]



Votes:

0

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!

Created on Apr 25, 2023 8:23:35 AM

Last change on Apr 27, 2023 6:41:18 AM by  Felix Wiesneth [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.