This article applies to PRTG Network Monitor 9 or later, installed on a 64bit OS


Can I use the 64bit version of Powershell in an EXE/Script Sensor in PRTG?


How to Use 64bit Powershell with EXE/Script Sensors

The short answer is: Yes, you can do so. Please see the following description for details.

Background

Sometimes you may need to use the 64bit version of Powershell for some special queries. But as PRTG is a 32bit application it cannot create 64bit child processes.

Solution

You have to add an additional layer between the Powershell and PRTG to get this running. As PRTG can start 64bit applications and this application further can create a 64bit child process we just create this application.

To solve this issue, you can write a little C# program which does nothing else than starting the 64bit Powershell, passing arguments to it and then give back the results to PRTG.

This can be done with the following code:

using System.Diagnostics;
static class Program {
    static int Main(string[] args) {
        ProcessStartInfo i = new ProcessStartInfo("powershell", args[0]);
        i.UseShellExecute = false;
        using(Process p = Process.Start(i)) {
            p.WaitForExit();
            return p.ExitCode;
        }
    }
}

The code has to be compiled in Visual Studio using the "Any CPU" option. This setting will force the program running in 64bit and it will create 64bit child processes.

Now just place the .exe file in the "Custom Sensors" sub directory of your PRTG installation folder and add an EXE/Script Sensor or a EXE/Script Advanced Sensor with the .exe file as executable.

Important

Please note that the code shown above is only an example and will just give back the raw output of the Powershell command to PRTG. In most cases this output will not be formatted for usage in PRTG. Please extend the code to fit your needs.


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.