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

Monitoring grace period on terminal server



Hi there,

I´m stuck a little and hope, someone can help me out...

I try to monitor the remaining days (grace period) on a terminal server with PRTG. On the server, this can pretty easy be done with an elevated prompt:

{{{C:\WINDOWS\system32>wmic /namespace:
root\CIMV2\TerminalServices PATH Win32_TerminalServiceSetting WHERE (__CLASS !="") CALL GetGracePeriodDays

<servername>\root\CIMV2\TerminalServices:Win32_TerminalServiceSetting.ServerName="servername")->GetGracePeriodDays() wird ausgeführt Methode wurde ausgeführt. Ausgabeparameter: instance of __PARAMETERS { DaysLeft = 20; ReturnValue = 0; };}}}

I think, the correct way is a wmicustomsensor, but I don´t know how the WQL-Script should look... Can anybody help me out?

Additionally, warning and error notifications would be fine, like its done for the SSL-Certificates.

Thanks in advance!

prtg terminalserver wmi

Created on Oct 7, 2020 6:16:06 AM

8 Replies




To get the grace period days, you can use the WMI custom sensor as you already mentioned. Here is the manual of the sensor: https://www.paessler.com/manuals/prtg/wmi_custom_sensor

You can find examples of wql files under C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\WMI WQL scripts. The files simply contain the request you make on the system to get the value you want, here is an example:

SELECT FreeMegabytes FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk WHERE Name='_Total'

You can use the WMI Tester tool to test your query before adding the sensor in PRTG. Here is the link of the tool: https://www.paessler.com/tools/wmitester. To do so, simply use the custom option under advanced and make sure that you hae provided the right Namespace in the settings

Otherwise, you also have the possibility to write a small PowerShell script which will execute the same query and return the data in PRTG, with the EXE/Script sensors. In that case, the script must return a response which follows the structure mentioned in the manual: https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors

Kind regards.

Created on Oct 8, 2020 6:42:07 AM by  Florian Lesage [Paessler Support]



Hi Florian, thanks for your fast reply. I mastered the WQL-File... SELECT GetGracePeriodDays FROM Win32_TerminalServiceSetting and the Namespace has to be set to \root\CIMV2\TerminalServices

But now building a WMI custom sensor with this leads to "80041003: The current user does not have permission to perform the action."

The user is in the domain administrators group and additionally in the local administrators group on the monitored (member)server.

crosstest: Running the wmic-stuff from #1 with an unelevated prompt needs to "permission denied"

Can you help out?


Created on Oct 8, 2020 8:28:53 AM

Last change on Oct 8, 2020 8:28:53 AM



Which account did you configured under Credentials for Windows Systems in the parent device settings ? Can you please make sure that it is the Administrator user account ?

Does the sensor work normally afterwards ?

Regarding the Namespace, you can configure it directly when you add the sensor or in its settings. Therefore, please use the following namespace without the backslash "\" at the beginning:


Let me know if you still have the issue regarding the permissions.


Created on Oct 8, 2020 10:05:39 AM by  Florian Lesage [Paessler Support]




the namespace is set to root\CIMV2\TerminalServices (it was already before, sorry). It does not work.

Inheritance ist set to on. The user (lets call him Malo) is domain administrator and member of the local administrator group on this server. This works with all my sensors and servers.

If he does the wmic-thing from Post #1 locally with an elevated prompt, everything is fine. When he does it with an unelevated prompt, he´ll get "permission denied"

Hence PRTG also has a permission issue, I guess that PRTG accesses the server "unelevated".

But how can PRTG access the server "elevated"? Any (local?) group missing?

I´m pretty lost, thanks for any help...

Created on Oct 8, 2020 11:41:21 AM




I would like to propose the other approach that I already mentioned before. That would be more reliable to execute the request via a custom script (in PowerShell) which would execute the WMI query remotely and return the result in PRTG.

In addition, the script would allow you to execute the query with the administrator account that you can pass to the script via the parameter field in PRTG, with the placeholders %windowsuser and %windowspassword.

Therefore, the cmdlet to use should look like: Get-WmiObject -Namespace "root\CIMV2\TerminalServices" -Query "SELECT GetGracePeriodDays FROM Win32_TerminalServiceSetting" -ComputerName "" -Credentials $credentials

Where $credential is a PScredential object which contains the username and password of the Administratror account.

The response returned by the script should follow the structure mentioned in the manual: https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors

Here is the manuals of the EXE/Script sensors:


Created on Oct 9, 2020 7:20:58 AM by  Florian Lesage [Paessler Support]



Florian, the correct cmdlet in PS is (Invoke-WmiMethod -PATH (gwmi -namespace root\cimv2\terminalservices -class win32_terminalservicesetting).__PATH -name GetGracePeriodDays).daysleft But this is also working only with an elevated PS and I bet, if I build a matching sensor in PRTG, I will also run into permission issues :( but I will give it a try...

If it does not work, I think I will not invest more efford in this case...


Created on Oct 9, 2020 8:47:13 AM



Florian, the created sensor leads to Antwort nicht wohlgeformt: "(Invoke-WmiMethod : In C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXE\Powershell Script - Grace period.ps1:1 Zeichen:2 + (Invoke-WmiMethod -PATH (gwmi -namespace root\cimv2\terminalservices ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Invoke-WmiMethod], FileNotFoundException + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.InvokeWmiMethod )" (Code: PE132)

I don´t know what is wrong. The script runs perfect locally, but not with PRTG. This is kinda frustrating :(

PS C:\WINDOWS\system32> (Invoke-WmiMethod -PATH (gwmi -namespace root\cimv2\terminalservices -class win32_terminalservicesetting).__PATH -name GetGracePeriodDays).daysleft 117 I´ll give up for this week, thanks so far... Have a nice weekend

Created on Oct 9, 2020 9:19:17 AM



I will contact you by email so it will be easier to figure out where the issue is.

Nevertheless, regarding te script, you have to provide the credentials of the Administrator account to execute the request from PRTG, otherwise the sensor will return the same error you already got. We can work on it next week.

Have a nice weekend.

Created on Oct 9, 2020 9:26:46 AM by  Florian Lesage [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.