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,

1New-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:

1Get-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

01function Set-CVSnapShot{
02<#
03.SYNOPSIS
04Function to Update custom values for VM´s in VMM 2012
05  
06.DESCRIPTION
07Use this function to  set the custom value Snapshot count
08  
09.PARAMETER  VMs
10Use this parameter to update just that VM´s custom snapshot value
11  
12.NOTES
13Author: Niklas Akerlund / RTS
14Date: 2012-04-16
15#>
16    param (
17   [Parameter(Position=0,HelpMessage="A virtual machine pleaze",
18    ValueFromPipeline=$True)]
19    $VMs = " "
20    )
21    
22   if ($VMs -eq " "){
23      $VMs = Get-SCVirtualMachine
24    }else{
25        $VMs = Get-SCVirtualMachine  $VMs
26    }
27     
28   $CustomSnapShot = Get-SCCustomProperty -Name "Snapshot Count"
29    
30    foreach ($VM in $VMs){
31        $count = ($VM | Get-SCVMCheckpoint).Count
32         
33        if($count -ne $null){
34            Set-SCCustomPropertyValue -InputObject $VM -CustomProperty $CustomSnapShot -Value $count 
35        }else{
36            Set-SCCustomPropertyValue -InputObject $VM -CustomProperty $CustomSnapShot -Value
37        }
38   }
39}

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

1# Script to use for scheduled updates of Custom values
2#
3# Niklas Akerlund / RTS 2012-04-16
4 
5ipmo 'C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\bin\psModules\VirtualMachineManager' | Out-Null
6 
7. .\Set-CVSnapshot.ps1
8Set-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)

Leave a comment

name*

email* (not published)

website