Latest Stories
Storage Field Day 18 – It’s As Intense As Storage Field Day Gets Forward Networks: Bringing Sanity To A Network Near You Multicloud : the buzzword we’ll keep hearing in 2019? Cisco HyperFlex 2019 Edition: Mixed Feelings The Solid-State Memory Industry Will Be Exciting in 2019

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
This content is 7 years old. Please, read this page keeping its age in your mind.

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

RSS Latest Podcast Episodes

  • EP16 – Rubrik: beyond Data Protection and into Data Management – with Filip Verloy
  • EP15 – Promethium: a data context solution for governance and analytics – Kaycee Lai
  • EP14 – AI / Technology and the Magic World of Regulations, Transparency and Ethics – Live at NetApp Insight with Greg Knieriemen (Part 2)
  • EP13 – NetApp Insight with Greg Kniereman Part 1

A note to our readers

kamshin.com has a strict no advertisement policy. We've been around since 2008; countless hours were put into creating content and maintaining the site.

Donations help us offset the hosting, maintenance and content creation costs, while continuing to give an unbiased perspective to our readers.

You can help us by sending us any amount of cryptocurrency at the following addresses:

Ethereum Classic:
ETC
0xb0eBc9CaDB4850b89BB56c401c0DF17cE9ec0aC7

Bitcoin:
BTC
3DVnhf9RkM8hPGDAKKVccUmrJyWaMEQSbp



Thank you!

Upcoming Events

There are no upcoming events at this time.

Categories

  • Active Directory (5)
  • Certifications (8)
  • Conferences (21)
  • Cryptocurrencies (7)
  • Design (1)
  • General (84)
  • Nutanix (4)
  • Rants (2)
  • Storage (32)
  • Tech Field Day (37)
  • Worth reading (4)

Latest Tweets

My Tweets

Popular posts this week

  • Cisco HyperFlex 2019 Edition: Mixed Feelings
  • My move from Gmail to ProtonMail: a comprehensive report on gaining back my privacy
  • Firefox on MacOS: insane battery drain, subpar performance and endless frustration
  • What future for Intel Optane?
  • Open Convergence: the next evolution of HCI?

Categories

  • Active Directory
  • Certifications
  • Conferences
  • Cryptocurrencies
  • Design
  • 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

We use anonymized Google Analytics cookies to analyze the traffic and trends on this website. We're not collecting any personal information, we don't care about your habits, your gender, your sexual orientation and your shopping interests. We don't even care to know if you're a human, a sentient AI or a dog/cat pretending to be interested in Enterprise IT.Accept CookiesReject Cookies
Revoke Cookies