PowerCLI: Change Persistence mode (on the fly)


image

When you have some vmdk’s with the Independent Persistent mode enabled. You might get problems with Storage vMotion (some DMotion errors). I was able to fix this with disabling  the Independent mode and create and remove a snapshot of the VM. But within the vSphere client you’re not able to change the Independent setting of a running VM. With PowerCLI you can!

The first one-liner will return all the vmdk’s with the Independet Persistent mode enabled:

Get-VM | % { Get-HardDisk -VM $_ | Where {$_.Persistence -eq "IndependentPersistent"} }

This is what you see in the console.

image

Within the vSphere client, you can’t change this setting while the VM is powered on.

image

But why use the vSphere client when we have PowerCLI ;-). If you run the following one-liner, it will return all the vmdk’s with Independent Persistent mode enabled. The next step is to disable this setting.

Get-VM | % { Get-HardDisk -VM $_ | Where {$_.Persistence -eq "IndependentPersistent"} | `
% {Set-HardDisk -HardDisk $_ -Persistence "Persistent" -Confirm:$false} }

This is the output you’ll see:

image

When you check the settings within the vSphere client, you’ll notice that the Independent mode is disabled.

image

Advertisements

10 thoughts on “PowerCLI: Change Persistence mode (on the fly)

  1. Pingback: Liens du jour #5 - Hypervisor.fr

  2. karthikeyan

    can you tell how to do it for a single VM. when i run the first command i am getting many VM Disks ,of that i need to change the setting for one particular VM .

    Reply
  3. karthikeyan

    i have just ran for the Vsphere 4.1 host and the VM is in Running state and upon execution it throws an error that the Vm should be in the powered off state.

    Reply
  4. Mike

    Im currently using VMWare 5.1 and trying to write a script with PowerGUI using CLI commandlets.

    I have found a bug with command “Set-HardDisk” – it appears deprecated from a storage vMotion perspective, but when setting it to persistent from IndependentPersistent, my script only works if the -confirm switch isnt set.

    If I remove the switch, by default my script prompts me, when I say yes… it works (the VM is off by the way). I’ve run it via PowerCLI and via PowerGUI – neither work and both errors say the same thing… “Invalid value passed for the SizeKB parameter.” even when I havent used this switch.

    Any thoughts would be much appreciated 🙂

    Reply
  5. Abdul Khan

    Hats off to you partner! I performed this in production with 10 hosts and 170 VM’s. Worked like a charm – no complaints!

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s