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

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

  1. 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 .

  2. 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.

  3. 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 🙂

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

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.