Latest Stories
Social Media Limbo kamshin.com on hiatus Some thoughts on the new MacBook Pro Opportunities And Challenges With Personal Health Data – Looking at Garmin Data How The 2020 Pandemic Shaped My Year, And How My Family And I Coped With COVID

kamshin

  • Home
  • All Posts
  • Categories
    • General
    • Tech Field Day
    • Storage
    • Nutanix
    • Certifications
    • Conferences
    • Worth reading
    • Design
    • Rants
    • Active Directory
  • Media & Press
  • Podcast
  • About me
    • About me
    • Where is Max?
    • Disclosure & Policies

Using Virtual Machine custom attributes with PowerCLI for snapshotting

February 24, 2012

FacebookTwitter

Here's a light one to end the week in a good mood! Expect no complex engineering though, PowerCLI scripts to manage snapshots must be very common around!

I manage a small environment where uber-scripting skills are not required. But for the sake of efficiency, laziness and "intellectual effort", here's what I use to patch my machines. All my VMs have custom attributes which include among others Business Owner, Primary IT Administrator, Emergency contact and an obscure one called "IsMirroredToDR". For historical reasons we have a software called HP Storage Mirroring for Virtual Infrastructure (SMVI) which works with ESX 4 (not ESXi), it does a great job but sometimes is a pain when things go wrong. This program creates snapshots and replicates them from production to DR sites at regular intervals for business recovery/continuity purposes.

Now whenever I need to patch servers I of course create snapshots in case something would go wrong. I however need to take special care of the VMs which have the IsMirroredToDR custom attribute set to True. I therefore use the script below to automatically create a snapshot on all VMs that are not mirrored to our DR site, and filter out VMs that are being mirrored so I can take care of those later. Once I have properly stopped all the mirroring processes and ensured all snapshots for these mirrored VMs have been deleted (as in consolidated to the base VMDKs), I then change the "False" to "True", run the script again et voila, even mirrored VMs are snapshotted ðŸ™‚

I had also tested a version where I also filtered VMs per datacenter, but I somehow didn't save it.

I hope this code snippet will be useful to someone, though it's definitely not rocket science.

Have a nice weekend!

 

#Get a list of VMs who have the IsMirroredToDR custom attribute set to false, then sort ascending
$VMs = @(Get-VM|Get-Annotation -CustomAttribute "IsMirroredToDR" | Where {$_.Value -eq "False"} | Sort-Object AnnotatedEntity)

#begin action on each filtered VM (comment/uncomment as appropriate)
ForEach ($VM in $VMs) { 

#****CREATE SNAPSHOTS****
#New-Snapshot -VM $VM.AnnotatedEntity -Name BeforePatch

}

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Reddit (Opens in new window)

Related

A note to our readers

kamshin.com has a strict no advertisement policy. If you enjoy this website, please consider making a donation to one of these non-profit organizations that I personally support:


People in Need - Czech Republic

A Czech-based non-governmental, non-profit organization founded on the ideals of humanism, freedom, equality and solidarity, helping people in the Czech Republic and in the entire world.

People In Need Logo

Greenpeace

Hopefully this one doesn't requires any explanation. Act for our planet. Act now.

Greenpeace Logo

826 National

US-based charity. An international proof point for writing as a tool for young people to ignite and channel their creativity, explore identity, advocate for themselves and their community, and achieve academic and professional success.

826 National Logo

 


Electronic Frontier Foundation

The leading nonprofit defending digital privacy, free speech, and innovation.

EFF Logo

 


Thank you!

RSS Latest Podcast Episodes

  • EP 30 -Rose Ross Chief Tech Trailblazer on the Tech Trailblazer awards
  • EP29 – Imagine the possibilities to manage your data with Data Dynamics StorageX – with Piyush Mehta
  • EP28 – Introducing Clumio, A Cloud-Based Data Platform Launching With Data Protection As A Service – with Poojan Kumar
  • EP27 – VAST Data – A Revolutionary Storage Platform For The Next Decade – with Howard Marks

Categories

  • Active Directory (5)
  • Certifications (8)
  • Conferences (22)
  • Design (1)
  • Featured (1)
  • General (88)
  • Nutanix (4)
  • Rants (2)
  • Storage (38)
  • Tech Field Day (44)
  • Worth reading (4)

Latest Tweets

My Tweets

Popular posts this week

  • Using Virtual Machine custom attributes with PowerCLI for snapshotting
  • EventID 2080 - DsAccess & SACL Right fix
  • Cisco HyperFlex: Break-thru or Me-too?
  • Virtual Machines - Size matters!
  • Rubrik - A Refreshing Approach to Backups

Categories

  • Active Directory
  • Certifications
  • Conferences
  • Design
  • Featured
  • General
  • Nutanix
  • Rants
  • Storage
  • Tech Field Day
  • Worth reading

Pages

  • Blog
  • Disclosure & Policies
  • Home
  • Media & Press
  • VCAP5-DCD Resources
  • VCP5 Certification Resources
  • About me

Archives

Copyright ©2016 kamshin