New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

300.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Need help with PRTG recognizing Powershell outputs...

Votes:

0

Your Vote:

Up

Down

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 by  Todd Schroeder (0) 1

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



5 Replies

Accepted Answer

Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

Thank you! I will give this a go.

Created on Aug 25, 2016 1:26:02 PM by  Todd Schroeder (0) 1



Votes:

0

Your Vote:

Up

Down

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 by  Todd Schroeder (0) 1



Votes:

0

Your Vote:

Up

Down

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 by  Todd Schroeder (0) 1

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



Votes:

0

Your Vote:

Up

Down

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]



Please log in or register to enter your reply.


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.