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

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

Your Vote:

Up

Down

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 by  Dominik Protzek (60) 1 1



Best Answer

Accepted Answer

Votes:

1

Your Vote:

Up

Down

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 by  Dominik Protzek (60) 1 1



8 Replies

Votes:

0

Your Vote:

Up

Down

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:

1

Your Vote:

Up

Down

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 by  Dominik Protzek (60) 1 1



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  Louis96 (0) 1

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



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  Louis96 (0) 1



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  OuSUMErg (0)



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.