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


Article Comments

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


Jul, 2017 - Permalink

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


Jul, 2017 - Permalink

Hey Dominik,

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

Cheers,
Sven


Jul, 2017 - Permalink

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
}

Nov, 2020 - Permalink

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


Nov, 2020 - Permalink

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,


Nov, 2020 - Permalink

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


Nov, 2020 - Permalink

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.


Feb, 2021 - Permalink

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


Mar, 2023 - Permalink

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 support@paessler.com, if you want us to take a closer look.


Mar, 2023 - Permalink

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


Mar, 2023 - Permalink