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.

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

How can I count the number of Virtual Machines running in my vSphere environment?



Your Vote:



Is there a sensor in PRTG to count the number of VMs that are running on my servers?

count custom-script-exe prtg vmware vmware-monitoring

Created on Jan 16, 2017 12:26:07 PM by  Dieter Loskarn [Paessler Support]

Last change on Aug 7, 2019 7:11:07 AM by  Maike Guba [Paessler Support]

3 Replies

Accepted Answer



Your Vote:



This article applies to PRTG Network Monitor 19 or later

How to Monitor the Number of Running Virtual Machines

Currently, there is no built-in sensor in PRTG but you can use the following script to determine the number of virtual machines running on your servers. The script is a wrapper that runs a metascan that is normally used in the Add Sensor dialog.

Simply copy and paste the following code into a new .ps1 file and save it to the \Custom Sensors\EXE subfolder of your PRTG program directory. Then add a new EXE/Script sensor to your PRTG installation using this script on the device you want to monitor the number of virtual machines. This is your vCenter server or vSphere host.

For example, you can place a sensor tht counts VMs on each host in your cluster and additionally add a Sensor Factory sensor to your vCenter server that

  • a) accumulates the number of VMs to a total value.
  • b) accumulates the number of VMs to one channel per dedicated sensor on the hosts.

This way, you can monitor moving VMs per vMotion on your systems.

If you add channels for host CPU and RAM usage to this sensor, you will get a picture of DRS efficiency, too.

Note: If you want to run the script on a remote probe, it is necessary to place the script on the computer that runs the remote probe.



# add this script as an exe-sensor with the following parameters
# -server %host -user %linuxuser -pass %linuxpassword
# You can use linux-credentials to hide the password used to access the vSphere-Server.
# You need read-only permissions only to retrieve the number of vms.

# determine the path for the script to build a relative absolute path to 'vmwaresensor.exe'
$scriptpath = Split-Path $script:MyInvocation.MyCommand.Path
# run a regular 'MetaScan' that returns all machines located on the target server
$vms = & "$($scriptpath)\..\..\Sensor System\VMWareSensor.exe" -s="$($server)" -u="$($user)" -p="$($pass)" -meta -type=vm

try {
    # load the result-text as xml
    $vmsxml = [xml]$vms

    # if an error occured
    if ($vmsxml.prtg.SelectNodes("error").count -eq 1) {
        $errortext = $vmsxml.prtg.SelectNodes("text").innertext.trim()
        # return the message to PRTG
        write-host "-1:$($errortext)"
    # else
    } else {
        $vmcount = ($vmsxml.prtg.SelectNodes("result")).count
        # return the number of machines
        write-host "$($vmcount):OK"
} catch {
    write-host "-1:An Error occured, please check the sensor manually; $($_.Exception.Message) at Line $($_.invocationinfo.ScriptLineNumber)"

Created on Jan 16, 2017 12:30:00 PM by  Dieter Loskarn [Paessler Support]

Last change on Sep 11, 2019 5:32:07 AM by  Maike Guba [Paessler Support]



Your Vote:




I am trying this script, but it gets a System Error: Please enter the VMware user and password in the device (code: PE022). Other sensors are working on same device.

What might be wrong?


Created on Jun 16, 2017 12:36:57 AM by  nferreira (0)



Your Vote:



As this is a custom script and you can’t use the vCenter-Credentials via placeholders within parameters please enter the credentials in the linux-part of the sensor settings page. Now you can use the parameter string as described (‘-server %host -user %linuxuser -pass %linuxpassword’)

Please keep in mind that this solution is to hide the password from other users who may be allowed to see the parameter settings for this sensor. If you don’t have such users a parameter string like ‘-server %host -user readonlyuser -pass readonlypass’ may be valid for you too but this is not recommended for obvious reasons.

Best regards, Dieter

Created on Jun 19, 2017 12:34:38 PM by  Dieter Loskarn [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.