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

Hyper-V get a list of snapshots

Votes:

0

Hi,

snapshots that are not deleted can often lead to problems. Also it can negatively affect the performance. So I want to see which Hyper-V machine has snapshots. Probably with an option to only warn if the snapshot persists for longer than 2 weeks.

I have found this article online http://blog.abakus.de/artikel/prtg-network-monitor-teil-3-snapshots-hyper-v/ and I tried to modify the script to instead work with the powershell cmd Get-VMSnapshot but I just couldn't get it to work.

Maybe someone already has a script that does that or can point me in the right direction?

thanks, Dominik

checkpoint hyper-v snapshot

Created on Jul 10, 2017 8:43:18 AM



Best Answer

Accepted Answer

Votes:

2

Found a solution:

$x= 0
$i= Invoke-Command –ComputerName 'Hostname' –ScriptBlock{Get-VMSnapshot -VMName * | measure}
$i=$i.Count


if ($i  -eq 0) {
  $x=[string]$i+":OK"
  write-host $x
  exit 0
}
ElseIf ($i -eq 5) {
  $x=[string]$i+": 5 Snapshots"
  write-host $x

  exit 1
}
ElseIf ($i -lt 5) {
  $x=[string]$i+": <5 Snapshots"
  write-host $x

  exit 1
}


ElseIf ($i -gt 5) {
  $x=[string]$i+": >5 Snapshots"
  write-host $x
  exit 1
}

Else 
{
  $x=[string]$i+":Invalid"
  write-host $x
  exit 2
}

cheers dominik

Created on Jul 19, 2017 12:49:18 PM



11 Replies

Votes:

0

Hey Dominik Protzek,
Thanks for your KB-posting.

If you are able to convert and evaluate the return-values of the $list = Get-SCVMCheckpoint -VMMServer $server command line you should be able to force the sensor in PRTG into a warning/error state by using the result

<prtg>
   <error>1</error>
   <text>Your error message</text>
</prtg>

However, please note that we cannot support you in writing custom scripts.

Best regards,
Sven

Created on Jul 12, 2017 11:08:52 AM by  Sven Roggenhofer [Paessler Technical Support]



Accepted Answer

Votes:

2

Found a solution:

$x= 0
$i= Invoke-Command –ComputerName 'Hostname' –ScriptBlock{Get-VMSnapshot -VMName * | measure}
$i=$i.Count


if ($i  -eq 0) {
  $x=[string]$i+":OK"
  write-host $x
  exit 0
}
ElseIf ($i -eq 5) {
  $x=[string]$i+": 5 Snapshots"
  write-host $x

  exit 1
}
ElseIf ($i -lt 5) {
  $x=[string]$i+": <5 Snapshots"
  write-host $x

  exit 1
}


ElseIf ($i -gt 5) {
  $x=[string]$i+": >5 Snapshots"
  write-host $x
  exit 1
}

Else 
{
  $x=[string]$i+":Invalid"
  write-host $x
  exit 2
}

cheers dominik

Created on Jul 19, 2017 12:49:18 PM



Votes:

0

Hey Dominik,

Thank you very much for sharing this. We really appreciate it.

Cheers,
Sven

Created on Jul 20, 2017 5:40:36 AM by  Sven Roggenhofer [Paessler Technical Support]



Votes:

0

Good Day,
Im Trying to setup this script.

The Value on PRTG shows 0 even if i have 6 snapshots. I renamed the hostname as expected. Its added as an EXE/Script. Any assistance would be great.

Any assistance Would be Great.

$x= 0
$i= Invoke-Command –ComputerName 'Hostname' –ScriptBlock{Get-VMSnapshot -VMName * | measure}
$i=$i.Count


if ($i  -eq 0) {
  $x=[string]$i+":OK"
  write-host $x
  exit 0
}
ElseIf ($i -eq 5) {
  $x=[string]$i+": 5 Snapshots"
  write-host $x

  exit 1
}
ElseIf ($i -lt 5) {
  $x=[string]$i+": <5 Snapshots"
  write-host $x

  exit 1
}


ElseIf ($i -gt 5) {
  $x=[string]$i+": >5 Snapshots"
  write-host $x
  exit 1
}

Else 
{
  $x=[string]$i+":Invalid"
  write-host $x
  exit 2
}

Created on Nov 2, 2020 2:20:15 PM

Last change on Nov 3, 2020 11:04:24 AM by  Sebastian Kniege [Paessler Support]



Votes:

0

Did you adjust the VMname as well?
What result do you get when you run the script manually outside of PRTG?


Kind regards,
Sasa Ignjatovic, Tech Support Team

Created on Nov 3, 2020 12:37:02 PM by  Sasa Ignjatovic [Paessler Support]



Votes:

0

HI Sasa, Thanks for the reply.

When i run the Script manually Powershell just instantly closes. No i did not since the * means all snapshots.

if i run this script bellow Manually it shows all snapshots on the Server.

Get-VMSnapshot –VMname *

Regards,

Created on Nov 3, 2020 12:56:32 PM



Votes:

0

Does the Probe (running the sensor) run on the same system as Hyper-V?
Did you run powershell as a administrator? It is best to first make sure that the script runs correctly outside of PRTG, before using it in a sensor.


Kind regards,
Sasa Ignjatovic, Tech Support Team

Created on Nov 4, 2020 10:57:44 AM by  Sasa Ignjatovic [Paessler Support]



Votes:

0

This works great thanks.

We initially had the same problem as Sebastian Kniege with the 0 checkpoints result. The problem was that the sensor was set to "Use security context of probe service" which didn't have access to our Hyper-V hosts. After setting it to "Use Windows credentials of parent device" it worked fine. Just make sure that these windows credentials have enough access to run this powershell script on your hosts.

Created on Feb 25, 2021 2:43:45 PM



Votes:

0

Hi, The script/sensor seems to work when there are no snapshots, but when there is at least 1 snapshot, it fails with message ‘Response not well-formed: “( )” (code: PE132)’. I tried running it directly on the probe and it runs fine.

Any ideas?

Tony

Created on Mar 8, 2023 2:42:04 PM



Votes:

0

Hello Tony,
If it's running fine manually, feel free to send us screenshots of the result as well as log files of the sensor to [email protected], if you want us to take a closer look.

Created on Mar 9, 2023 7:07:07 AM by  Timo Dambach [Paessler Support]



Votes:

0

I believe I resolved the issue. Apparently PRTG does not like the "<" and ">" symbols in the return string/message. I removed them and it worked.

For example;

ElseIf ($i -lt 5) {
  $x=[string]$i+": <5 Snapshots"
  write-host $x

I change this to:

ElseIf ($i -lt 5) {
  $x=[string]$i+": under 5 Snapshots"
  write-host $x

Tony

Created on Mar 9, 2023 2:28:20 PM

Last change on Mar 10, 2023 12:07:09 PM by  Felix Wiesneth [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.