Automation

 View Only
  • 1.  Changing Disk Persistence

    Posted May 01, 2008 02:18 AM

    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.



  • 2.  RE: Changing Disk Persistence

    Posted May 01, 2008 02:56 AM

    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.



  • 3.  RE: Changing Disk Persistence

    Posted May 01, 2008 03:19 AM

    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



  • 4.  RE: Changing Disk Persistence

    Posted May 01, 2008 12:32 PM

    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)



  • 5.  RE: Changing Disk Persistence

    Posted May 09, 2008 03:33 AM

    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



  • 6.  RE: Changing Disk Persistence

    Posted May 09, 2008 07:37 AM

    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 .



  • 7.  RE: Changing Disk Persistence

    Posted May 09, 2008 04:46 PM

    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)



  • 8.  RE: Changing Disk Persistence

    Posted May 19, 2008 07:41 PM

    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?