Sunday, May 4, 2014

Creating checkpoints with VMM cmdlets

Recently, a customer asked me a question.
“How can we easily create snapshots on every virtual machine created after a specific date, that are currently running?”

I really like these questions, because it let me show how powerful System Center’s powershell cmdlets can be.
This is related to System Center Virtual Machine Manager, and if we dive into the module, I’ll show you what I found.

The interesting part here is that the customer would this to happen if the virtual machines are created after a specific date, and is in a running state, meaning that someone is most likely using – and paying for those virtual machines (especially interesting if they are using Windows Azure Pack).

If we run the following cmdlet, we can see the different properties related to “Get-SCVirtualMachine”

As you can see, we have a property called “AddedTime” together with “Status”.

Instead of putting steroids into this simple task, by creating a script, I am much more interesting in solving these simple tasks with the shell itself. In the end of the day, that is what Powershell is all about. Solve complex tasks and time-consuming tasks (if doing it manually) with a one-liner!

So here’s the cmdlet that will create checkpoints on every running virtual machine, created after a specific date.

Get-SCVirtualMachine | Where-Object {$_.AddedTime -gt "04-30-2014" -and $_.status -eq "Running"} | New-SCVMCheckpoint -Description "Checkpoint of VM created after a given date" -ErrorAction Ignore – RunAsynchronously

That’s all for now, but I’ll share other cool stuff you can perform in your cloud fabric with VMM cmdlets later.

No comments: