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

Need help with PRTG recognizing Powershell outputs...

Votes:

0

Hi guys,

I am running the below powershell script to pull the number of days before our CA certs expire.

$threshold = 9999  #Number of days to look for expiring certificates 
$deadline = (Get-Date).AddDays($threshold)   #Set deadline date
[string]$ServerName = "test-server" #Leave this blank when utilizing this in PRTG
        Invoke-Command -ComputerName $ServerName { Dir Cert:\LocalMachine\My } | foreach { 
            If ($_.NotAfter -le $deadline) { $_ | Format-List Issuer, @{Label="Expires In (Days)";Expression={($_.NotAfter - (Get-Date)).Days}} ;}
             
            elseif ($_.NotAfter -ge $deadline)  {Write-host $deadline ":All Certificates are NOT expiring within $threshold days."}
  }




The Expected output looks like this:

Issuer            : CN=test-serverCACERT
Expires In (Days) : 43

Issuer            : CN=test.serverCACERT
Expires In (Days) : 43

Currently, PRTG is only executing the script and not displaying any of the outputs. Am I able to format the output so that PRTG will create channels based on the issuer, and a value based on the Expires In (Days)?

certificate prtg remote-powershell

Created on Aug 23, 2016 7:08:14 PM

Last change on Aug 24, 2016 7:33:51 AM by  Torsten Lindner [Paessler Support]



5 Replies

Accepted Answer

Votes:

0

Dear TSchroeder

To output just one channel, you can use the Custom Exe/Script standard sensor and use the output format

value:message

like

write-host $resultvalue":"$sensormessage

(Of course, this implies having those variables with the according content.)

To return multiple channels, the Exe/Script Advanced sensor is requried. That sensor expect an XML conforming to the Custom Script Advanced API. The API documentation is integrated in the PRTG webinterface, menu Setup | PRTG API, tab "Custom Sensors".

Created on Aug 24, 2016 1:58:35 PM by  Arne Seifert [Paessler Support]



Votes:

0

Thank you! I will give this a go.

Created on Aug 25, 2016 1:26:02 PM



Votes:

0

Currently we are now getting "unauthorized access." Any thoughts?

I am able to run the script manually with the desired credentials on the Probe, and it runs flawlessly.

Created on Aug 25, 2016 4:29:35 PM



Votes:

0

This is the script in a more refined form.

Param(
    [string]$Servername
    )

$threshold = 30  #Number of days to look for expiring certificates 
$deadline = (Get-Date).AddDays($threshold)   #Set deadline date


        Invoke-Command -ComputerName $ServerName { Dir Cert:\LocalMachine\My } | foreach { 
            
        If ($_.NotAfter -le $deadline) 
            {
                $Days= $_.NotAfter - (Get-Date)
            }
                $Day= ($_.NotAfter - (Get-Date)).Days
            }
        If ($Day -le $threshold) 
            {
                $Resultvalue= "1"
                $sensormessage= "The CA Certificates are about to expire in $Day days!"
                
            }
        else 
            {
                $Resultvalue= "0"
                $sensormessage= "All certificates are valid beyond $threshold days!"
            }
            
write-host $resultvalue":"$sensormessage

Created on Aug 25, 2016 4:52:22 PM

Last change on Aug 26, 2016 9:04:46 AM by  Arne Seifert [Paessler Support]



Votes:

0

Dear TSchroeder

By default, the script is started by the Probe service which in turn runs with the local system account. Since the Probe is a 32-bit service, it also starts the 32-bit Powershell.

Please check the security context setting of the Exe/Script sensor and make sure it is set to use the Windows credentials of the parent device. Please also check those device credentials.

Created on Aug 26, 2016 9:06:53 AM by  Arne Seifert [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.