Scheduled task to run a PowerCLI script (and delete a named snapshot)
Posted: August 3, 2012 Filed under: PowerShell / PowerCLI, VMware, Windows | Tags: delete snapshot, powercli, scheduled, scheduled task, script, snapshot 1 CommentI had occasion recently to delete a snapshot at a certain time. It’s easy enough to schedule the snapshot using the vSphere Client and built-in functions, but then, how to delete it on a schedule? Enter PowerCLI and the Windows Task Scheduler.
There was a VMTN forum post by Duncan Epping (@DuncanYB) that suggested using the generic form Get-VM | Get-Snapshot | Remove-Snapshot. This worked a charm for me and I put it into the following script.
Deploy a VM from template with PowerCLI
Posted: February 17, 2012 Filed under: PowerShell / PowerCLI, VMware | Tags: deploy vm from template, deploy vm from template powercli, powercli, small vm, vm powercli Leave a commentNow that I have a small VM for my test lab, I converted it to a template and looked for a cool way to deploy several VMs from this template with PowerCLI. Turns out it’s actually really easy, anti-climactic, even. The good folks over at VMPros.nl have an excellent tutorial on this topic. Alan Renouf (Twitter @alanrenouf) was the first to comment on their blogpost. He included a nice for loop to replace a single line for each VM deployment. I incorporated Alan’s suggestion as well as a few options from the PowerCLI New-VM cmdlet reference page, like adding the VM to a resource pool and then powering on the VM.
Here’s the code:
Add e-mail alerts to all 41 default vSphere 4.1 alarms
Posted: November 3, 2011 Filed under: PowerShell / PowerCLI, VMware | Tags: add email alerts, alarms, alerts, email, Get-AlarmAction, Get-AlarmDefinition, New-AlarmAction, New-AlarmActionTrigger, notification email, powercli, script, scripting, vcenter, vsphere 4 CommentsTowards the end of a customer’s virtualization implementation we’re doing some clean-up of the environment. During the initial setup I was using my own local email address to test various alerting processes, of which there are several. For instance, every SQL Server maintenance task sends a success/failure e-mail alert, the NetApp Virtual Storage Console plug-in can be configured to e-mail an administrator after snapshots are taken, and the Dell iDRAC can send e-mails on hardware status changes. All those are fairly quick to configure or lack a way to script a quick solution. But with 40 default alarms in vSphere, three vCenters, and being lazy as I am, I knew there must be a better solution than right clicking 120 alarms and copying-and-pasting an email address. As the proverb goes, if you repeat it, script it. So I set out to find how PowerCLI could help me.