New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.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


Snapshot State vCenter 6.5

Votes:

0

Your Vote:

Up

Down

Hi Guys

i'm trying to get the Snapshot state of my VMs monitored in PRTG. We just upgraded our ESXi Environment to 6.5.

Before the Upgrade everything worked fine. But now i'm getting Errors with the old Skript. I had to upgrade PowerCLI from Version 4 to Version 6.5. So i found this article https://kb.paessler.com/en/topic/29313-vmware-snapshots and tried the Skript. Unfortunately "Add-PSSnapin" doesnt work anymore.

So i changed the Line to "Get-Module -Name VMware* -ListAvailable | Import-Module". If i run it trough PowerShell everything workes fine and i'm able to Connect with the vCenter.

But in my Custom Sensor i get the Error "'connect-viserver' is not recognized as a cmdlet, function, operable program, or script file." It seems the Modules arent loaded yet.

If i change the Line to "Import-Module -Name VMware.VimAutomation.Core", then the following Error appears:

Import-Module : Das erforderliche Modul "VMware.VimAutomation.Cis.Core" ist nicht geladen. Laden Sie das Modul, oder entfernen Sie das Modul aus "RequiredModules" in der Datei "C:\Program Files (x86)\VMware\Infrastructure\Po werCLI\Modules\VMware.VimAutomation.Core\VMware.VimAutomation.Core.psd1

It means "The required Module "VMware.VimAutomation.Cis.Core" isnt loaded. Load the Module or remove the Module from the "RequiredModules" in the File VMware.VimAutomation.Core.psd1"

I'm grateful for every hint, i tried already a lot but i'm not very familiar with PowerShell.

Thanks!

esxi powercli powershell powershell-module snapshot vcenter

Created on Dec 6, 2017 10:55:27 AM by  dehu_its (0) 2



16 Replies

Votes:

0

Your Vote:

Up

Down

So i did it by my self. For my Problem above the solution was to put the Modules into Global Scope.

I also changed the Skript for our Monitoring where each VM have its own Sensor. Now it counts how much snapshots per each VM exists.

If you want to use this Skript, you have to put the name of the VM in the Settings/Parameters of the Sensor.

IP_vCenter_or_ESX_Host https '%linuxuser' '%linuxpassword' 'Cluster_name' * 'vm_name'

The final Script:

#---------------------------------------------------------------------------------------------
# Get the number of VM snapshots on ESX host or vCenter
#
# This script requires the installation of the VMware Infrastructure (VI) Toolkit for Windows.
# 
# Args[0]:Server
# Args[1]:Protocol (HTTP/HTTPS)
# Args[2]:User
# Args[3]:Password
# Args[4]:Location (VI container(s), e.g. folders, datacenters, clusters). 
#		  Enclose in ' ' if location name contains spaces.
# Args[5]:VM power state (PoweredOn, PoweredOff, * for all)
#
# Example 1: Snapshot count for single DRS cluster, only powered-on VMs
# 10.23.112.235 https Administrator pass01 'My DRS Cluster' 'PoweredOn'
#
# Example 2: multiple datacenters, all VMs
# 10.23.112.235 https Administrator pass01 'My Data Center 1','My Data Center 2' '*'
# 
#---------------------------------------------------------------------------------------------


Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Sdk" -Scope Global 
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Common" -Scope Global
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Cis.Core" -Scope Global
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Core"



$global:textvar = "OK"

$server=Connect-VIServer -Server $Args[0] -Protocol $Args[1] -User $Args[2] -Password $Args[3]>$Null
$powerstate = [string]$Args[5]
$vm = [string]$Args[6]
$snapshot_count = 0

Get-Snapshot -VM $vm | 
ForEach-Object {
	$snapshot_count = $snapshot_count+1
}



$x=[string]$snapshot_count+":"+$global:textvar




write-host "<prtg>"
write-host "<result>"
write-host "<channel>Snapshots</channel>"
write-host "<value>"
write-host $snapshot_count
write-host "</value>"
write-host "<LimitMode>1</LimitMode>"
write-host "<LimitMaxError>3</LimitMaxError>"
write-host "<LimitMaxWarning>2</LimitMaxWarning>"
write-host "</result>"
write-host "</prtg>"

if you see anything i could do better, please let me know. i usually dont use PowerShell or PowerCLI.

Created on Dec 6, 2017 3:23:46 PM by  dehu_its (0) 2

Last change on Dec 7, 2017 9:24:41 AM by  Torsten Lindner [Paessler Support]



Votes:

0

Your Vote:

Up

Down

We reworked the script so that we get a channel per VM.

#---------------------------------------------------------------------------------------------
# Get the number of VM snapshots on ESX host or vCenter
#
# This script requires the installation of the VMware Infrastructure (VI) Toolkit for Windows.
# 
# Args[0]:Server
# Args[1]:Protocol (HTTP/HTTPS)
# Args[2]:User
# Args[3]:Password
# Args[4]:Location (VI container(s), e.g. folders, datacenters, clusters). 
#		  Enclose in ' ' if location name contains spaces.
# Args[5]:VM power state (PoweredOn, PoweredOff, * for all)
#
# Example 1: 
# IP_vCenter_or_ESX_Host https '%linuxuser' '%linuxpassword' 'Cluster_name' * 'vm_name'
#
#---------------------------------------------------------------------------------------------


Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Sdk" -Scope Global 
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Common" -Scope Global
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Cis.Core" -Scope Global
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Core"



$global:textvar = "OK"

$server=Connect-VIServer -Server $Args[0] -Protocol $Args[1] -User $Args[2] -Password $Args[3]>$Null
$powerstate = [string]$Args[5]
#$vm = [string]$Args[6]
$Servers = Get-VM 
write-host "<prtg>"
foreach ($vm in $Servers)
{
$snapshot_count = 0

Get-Snapshot -VM $vm | 
ForEach-Object {
	$snapshot_count = $snapshot_count+1
}



$x=[string]$snapshot_count+":"+$global:textvar





write-host "<result>"
write-host "<channel>$VM</channel>"
write-host "<value>"
write-host $snapshot_count
write-host "</value>"
write-host "<LimitMode>1</LimitMode>"
write-host "<LimitMaxError>1</LimitMaxError>"
write-host "<LimitMaxWarning>0</LimitMaxWarning>"
write-host "</result>"

}

write-host "</prtg>"

Created on Jan 24, 2018 2:38:46 PM by  Richard Lindner (0)

Last change on Jan 24, 2018 3:06:32 PM by  Torsten Lindner [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi,

could anyone please give me a hint how to get the Modules the script tries to import? I can't find a download for them :-(

VMware.VimAutomation.Sdk VMware.VimAutomation.Common VMware.VimAutomation.Cis.Core VMware.VimAutomation.Cor

Thanks....

Created on Apr 23, 2018 7:45:48 AM by  gindler (0)



Votes:

0

Your Vote:

Up

Down

The modules can be downloaded here. Note that you need a MyVMWare account to obtain it.


Kind regards,
Stephan Linke, Tech Support Team

Created on Apr 23, 2018 11:06:22 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi @ll, I´ve a question, I want you the PS-Script from top of the side but I´m not a Powershell Specialist, so could everyone be so nice and can me explain where and how I have to insert these values in the script?

Args[0]:Server

  1. Args[1]:Protocol (HTTP/HTTPS)
  2. Args[2]:User
  3. Args[3]:Password
  4. Args[4]:Location (VI container(s), e.g. folders, datacenters, clusters).
  5. Enclose in ' ' if location name contains spaces.
  6. Args[5]:VM power state (PoweredOn, PoweredOff, * for all)

I tried something but nothing worked... THX

Created on Jun 27, 2018 10:41:54 AM by  JaBe (0)



Votes:

0

Your Vote:

Up

Down

Hi JaBe,

You'll need to enter these parameters in the parameter field of the custom sensor when creating it:

'https' 'username' 'password' '*'

$Args[4] is seemingly not used within the script, hence I omitted it.


Kind regards,
Stephan Linke, Tech Support Team

Created on Jun 27, 2018 10:59:01 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Good Morning,

I put the Schript on our Probe in following folder C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE\ and created a custom sensor with the needed Parameters. After the check ran following error occured, google can´t help me... any Idea how to fix it?

Antwort nicht wohlgeformt: "(Connect-VIServer : Die Datei oder Assembly "VMware.VimAutomation.Logging.SoapInterceptor, Version=1.0.0.314, Culture=neutral, PublicKeyToken=null" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden. In C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXE\Snap_test.ps1:32 Zeichen:9 + $server=Connect-VIServer -Server $Args[0] -Protocol $Args[1] -User $Args[2] -Pas ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : NotSpecified: (:) [Connect-VIServer], FileNotFou ndException + FullyQualifiedErrorId : System.IO.FileNotFoundException,VMware.VimAutoma tion.ViCore.Cmdlets.Commands.ConnectVIServer Get-Snapshot : Die Datei oder Assembly "VMware.VimAutomation.Logging.SoapInterceptor, Version=1.0.0.314, Culture=neutral, PublicKeyToken=null" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden. In C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXE\Snap_test.ps1:37 Zeichen:1 + Get-Snapshot -VM $vm | + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-Snapshot], FileNotFoundEx ception + FullyQualifiedErrorId : System.IO.FileNotFoundException,VMware.VimAutoma tion.ViCore.Cmdlets.Commands.GetSnapshot <prtg> <result> <channel>Snapshots</channel> <value> 0 </value> <LimitMode>1</LimitMode> <LimitMaxError>3</LimitMaxError> <LimitMaxWarning>2</LimitMaxWarning> </result> </prtg> )" (Code: PE132)

Created on Jun 28, 2018 7:32:35 AM by  JaBe (0)

Last change on Jun 28, 2018 7:48:49 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

You need to put it in the EXEXML directory, since it's outputting XML. Otherwise, is the following requirement installed:


This script requires the installation of the VMware Infrastructure (VI) Toolkit for Windows.





Kind regards,
Stephan Linke, Tech Support Team

Created on Jun 28, 2018 7:50:06 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Stephan, the VI Toolkit is installed on the Probe. Could it be that the custom sensor is missconfigured and if yes, which settings are right?

Created on Jun 28, 2018 9:30:02 AM by  JaBe (0)



Votes:

0

Your Vote:

Up

Down

That I'm unsure of. Is the script itself located on a remote probe?

Created on Jun 28, 2018 10:06:56 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Yes, it´s located on dedicated Windows 7 Professional Machine which act as Probe, the Script is in Folder: C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE\

Created on Jun 28, 2018 11:50:11 AM by  JaBe (0)



Votes:

0

Your Vote:

Up

Down

Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Sdk" -Scope Global 
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Common" -Scope Global
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Cis.Core" -Scope Global
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Core"

What happens when you run these commands in a PowerShell, one by one?

Created on Jun 28, 2018 12:14:57 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

It works without errors...

Created on Jun 29, 2018 6:36:59 AM by  JaBe (0)



Votes:

0

Your Vote:

Up

Down

When you modify the security context setting of the sensor so it uses the credentials of the parent device, does it work then? The script works when executed in plain PowerShell, right?


Kind regards,
Stephan Linke, Tech Support Team

Created on Jun 29, 2018 6:41:41 AM by  Stephan Linke [Paessler Support]



Votes:

1

Your Vote:

Up

Down

Hi

I have been following this thread as I am working on a similar script. The problems was that I would only want the information on the machines with snapshots, and I do not want information on all the other machines as well. I have borrowed a lot from the script above and tweaked it a little. I am no expert in powershell or scripting, but I have tried.

#You need to install PowerCLI and Download VMware Infrastructure Toolkit for Windows
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Sdk" -Scope Global 
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Common" -Scope Global
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Cis.Core" -Scope Global
Import-Module -Name "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Core" 

$server=Connect-VIServer -Server $Args[0] -Protocol $Args[1] -User $Args[2] -Password $Args[3]>$Null #Arguments used as a parameter in PRTG example: vcenter.local https ntofab\User PASSWORD1

$data=Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-30)} #Count how many snapshots that are above x amount of days.
$count=$data.count
$VMdata=Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-30)} | Select VM | Out-String #Display which virtual machines that have the snapshots
$VM=$VMdata.ToString()

write-host "<prtg>"
	write-host "<result>"
	write-host "<channel>Old_snapshot</channel>"
	write-host "<value>$count</value>"
	write-host "</result>"
	write-host "<text>$VM</text>"
write-host "</prtg>"

I hope it can help other users as well.

Created on Aug 8, 2018 9:11:15 AM by  Jacobnm (10)

Last change on Aug 8, 2018 9:48:27 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Jacob,

Thanks for sharing! :)


Kind regards,
Stephan Linke, Tech Support Team

Created on Aug 8, 2018 9:48:58 AM by  Stephan Linke [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.