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

Modify Sensors with Powershell and PRTG API?

Votes:

0

I have had a look at the page below and have been able to generate reports and list sensors however what I really want to do is modify sensor settings.

https://kb.paessler.com/en/topic/68506-powershell-interface-for-prtg-api

Is it possible to do something like:

######ignore invalid SSL Certs##########
add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

######setup details, access related.
$auth = "username=user&passhash=hash"
$PRTGHost = "IPADDRESS"

function Set-prtgSensorProperty ([string]$SensorID,[string]$PropertyName,[string]$Value)
{
    $url = "https://$PRTGHost/api/setobjectproperty.htm?id=$SensorID&name=$PropertyName&value=$Value&$auth"
    $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore


} # end function

Obviously I tried that and it didn't work but is there an alternative? Am I missing something?

powershell prtg sensor

Created on Mar 15, 2018 12:29:33 PM

Last change on Mar 16, 2018 11:42:53 AM by  Dariusz Gorka [Paessler Support]



Best Answer

Accepted Answer

Votes:

0

I figured it out. I was trying to set an inherited property to off and so I needed to use a _ after the property name.

function Set-prtgSensorPropertyInherited ([string]$SensorID,[string]$PropertyName,[string]$Value)
{
    $url = "https://$PRTGHost/api/setobjectproperty.htm?id=$SensorID&name=$PropertyName_&value=$Value&$auth"
    $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore


} # end function

Created on Mar 16, 2018 2:34:22 PM

Last change on Mar 16, 2018 5:22:33 PM by  Dariusz Gorka [Paessler Support]



2 Replies

Votes:

0

Hi there,

You could try the following. Ignore invalid SSL Cert:

# Ignore SSL errors
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

Request a website:

[system.Net.WebRequest]::Create($URL)


Does that work?

Best regards.

Created on Mar 16, 2018 11:44:41 AM by  Dariusz Gorka [Paessler Support]



Accepted Answer

Votes:

0

I figured it out. I was trying to set an inherited property to off and so I needed to use a _ after the property name.

function Set-prtgSensorPropertyInherited ([string]$SensorID,[string]$PropertyName,[string]$Value)
{
    $url = "https://$PRTGHost/api/setobjectproperty.htm?id=$SensorID&name=$PropertyName_&value=$Value&$auth"
    $request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore


} # end function

Created on Mar 16, 2018 2:34:22 PM

Last change on Mar 16, 2018 5:22:33 PM by  Dariusz Gorka [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.