VMware Cloud Community
gpeck29
Enthusiast
Enthusiast

Changing Disk Persistence

I need to change the disk persistence of some VMs for patching and software updates. Any ideas how to go about this? I haven't found a straightfoward way to do this.

0 Kudos
7 Replies
gpeck29
Enthusiast
Enthusiast

Looks like I should hvae dug a little deeper....

$vm = get-vm -name <vmname>

$vm | shutdown-vmguest

$vm | get-harddisk | set-harddisk -persistence nonpersistent

$vm | start-vm seems to work.

Now if I can figure out how to use a CSV file of VM's or even a list of VMs in an Active Directory OU to perform this operations for, I'll be set. I also need to figure out how to wait till the VM is offline before setting the disk persistence.

0 Kudos
kjb007
Immortal
Immortal

You should be able to use wait-task, to wait until the vm is down, or just loop until the state returns poweredOff, and then continue on with your other code.

-KjB

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB
0 Kudos
halr9000
Commander
Commander

Now if I can figure out how to use a CSV file of VM's or even a list of VMs in an Active Directory OU to perform this operations for, I'll be set.

$process = import-csv need_maint.csv
$process | foreach-object {
    $vm = $_.name | get-vm # assumes there is a Name column in the CSV
   # the rest of your steps
}

For AD, check out Quest's AD cmdlets. There is one called Get-QADComputer that will do the trick very nicely. You can specify an OU or LDAP query to it and then for example assign those results to the $process variable above.

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
stephen_ng
Contributor
Contributor

Hmm, this doesn't work for me. I'm using ESX 3.

(Get-HardDisk -VM (Get-VM -Name MyVm)) | Set-HardDisk -Persistence persistent

No matter whether I set it to "persistent" or "nonpersistent", the disk is not independent. How can I configure the disk to be independent using the API?

Thanks,

Steve

0 Kudos
LucD
Leadership
Leadership

As far as I know there is no cmdlet that allows you to change the mode of a hard disk to independent.

You can use the SDK API to configure this.

See here for the different options you have.

An example of this is the add-HD function in .


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
stephen_ng
Contributor
Contributor

Yeah, I wound up going to the underlying API. Kind of a pain but it works.

Steve

$vm = Get-View(Get-VM $NewVmName).ID

$vdcs = New-Object VMware.Vim.VirtualDeviceConfigSpec

$vdcs.Device = $vm.Config.Hardware.Device[10]

$vdcs.Operation = 'edit'

$vdcs.Device.Backing.diskMode = "independent_nonpersistent"

$vmcs = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmcs.DeviceChange = $vdcs

$vm.ReconfigVM($vmcs)

0 Kudos
gpeck29
Enthusiast
Enthusiast

Stephen,

I'm getting errors that indicate that the diskmode property cannot be found for this object. Can you repost your script again, in a code block?

0 Kudos