Home > Automation, Hyper-V, Powershell, SCVMM, Virtualization > A PowerShell function for Snapshot reporting in VMM2012

A PowerShell function for Snapshot reporting in VMM2012

Hello

I am in the hotel waiting for the MMS 2012 to start so there is time for some automation ;-). Last week when I was teaching a course one of the attendes said after I showed the custom value function, that he also wanted a similar function for easy in the console check how many snapshots every VM had. In the VMM 2012 console I have not found an built-in function to actually show this.

I have modified the function and created the run script, this is scheduled to run once a hour so you have a updated view of your environment. At least in the Hyper-V for Windows 2008 R2 it is not recommended to use in production.

It is quite easy to create a new custom property that we then will populate,

New-SCCustomProperty -Name "Snapshot Count" -Description "" -AddMember @("VM")

In the GUI there is no way to remove a custom property, I can only remove it from assigned properties. During the course I created an property just for showing and want to get rid of it. Of course there is a powershell cmdlet for that:

Get-SCCustomProperty -Name "Muuuu" | Remove-SCCustomProperty

But now to the part of getting the script to show snapshots (yes I know, in VMM it is called Checkpoints but i refuse to call it that)

First I have the PowerShell function

function Set-CVSnapShot{
<#
.SYNOPSIS
Function to Update custom values for VM´s in VMM 2012
 
.DESCRIPTION
Use this function to  set the custom value Snapshot count
 
.PARAMETER  VMs
Use this parameter to update just that VM´s custom snapshot value
 
.NOTES
Author: Niklas Akerlund / RTS
Date: 2012-04-16
#>
    param (
   [Parameter(Position=0,HelpMessage="A virtual machine pleaze",
    ValueFromPipeline=$True)]
    $VMs = " "
    )
   
  	if ($VMs -eq " "){
    	$VMs = Get-SCVirtualMachine
	}else{
		$VMs = Get-SCVirtualMachine  $VMs
	}
	
  	$CustomSnapShot = Get-SCCustomProperty -Name "Snapshot Count"
   
	foreach ($VM in $VMs){
		$count = ($VM | Get-SCVMCheckpoint).Count
		
	    if($count -ne $null){
	        Set-SCCustomPropertyValue -InputObject $VM -CustomProperty $CustomSnapShot -Value $count 
	    }else{
	        Set-SCCustomPropertyValue -InputObject $VM -CustomProperty $CustomSnapShot -Value 0 
	    }
   }
}

then I have a very easy script that I task scheduled in my VMM server

# Script to use for scheduled updates of Custom values
#
# Niklas Akerlund / RTS 2012-04-16

ipmo 'C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\bin\psModules\VirtualMachineManager' | Out-Null

. .\Set-CVSnapshot.ps1
Set-CVSnapshot

And in the VMM Console it looks like this

I will talk to some VMM responsibles at MMS and see if they find an interest and build the view instead of me running it in a sheduled task (as the information is there in the database)

  1. No comments yet.
  1. No trackbacks yet.