I updated my VI Toolkit (the scripting thing) to 1.5 from 1.0 on Tuesday, and I discovered an issue with one of my scripts. Modifications of drive states from IndependentPeristent to IndependentNon-Persistent no longer work, generating the following message:
Set-HardDisk : 12/02/2009 13:30:22 Set-HardDisk C9875D59-A700-4FDC-AE1D-8DF0189623B9 Changing virtual hard disk persistance from "IndependentPersistent" to "IndependentNonPersistent" is not supported. At C:\vmbop\VMBOp.ps1:163 char:58+ Set-Harddisk -VM (get-content $strVMList) | Set-HardDisk <<<<-Persistence IndependentNonPersistent
While this is a slight pain as far as the script is concerned, the reason is slightly more concerning.
The bit that changes drive persistence is as follows:
Get-Harddisk -VM $objVM | Set-HardDisk -Persistence IndependentNonPersistent
I thought that maybe the syntax had changed in this latest version, so I ran help against the Set-HardDisk command, which showed me the following:
-Persistence Specifies the disk persistence mode. The valid values are: Persistent, NonPersistent, IndependentPersistent, IndependentNonPersistent, and Undoable. This parameter is supported only when the disk type is set to "rawVirtual" or "flat". Note that the 'NonPersistent' and 'Undoable' persistence policies are deprecated and will be discontinued in future releases. Their usage is not recommended because they do not work with snapshots and are not supported on ESX 3.5 and higher.
I changed the command to:
Get-Harddisk -VM $objVM | Set-HardDisk -Persistence NonPersistent
Which resulted in the following:
WARNING: Consider using another persistence policy because 'NonPersistent' is deprecated and will be discontinued in a future release. Also it doesn't work with snapshots and is not supported on ESX 3.5 and higher.
And then errored with:
Set-HardDisk : 13/02/2009 14:15:53 Set-HardDisk 2A59A949-0BCF-4E7A-8837-4D3583D27C8A Changing virtual hard disk persistance from "IndependentPersistent" to "NonPersistent" is not supported. At line:1 char:48 + Get-Harddisk -VM MSIBenchmarking | Set-HardDisk <<<< -Persistence NonPersistent
If VMware remove non-persistent functionality for disks, then this is going to cause me some trouble, as circumstances dictate that I can't use snapshots.
Also, does anyone know how to fix the script so that it will work in VI Toolkit 1.5? :smileygrin:
Looks like a bug. We change the behavior of this cmdlet, and I believe it was because IndependentNonpersistent disks can't be created on 3.5. Does that match your experience?
I've asked the dev team to look in to it.
Ok, I'm still investigating this, and trying to fix the script. Just to clarify...
I can convert an existing Independent Non-persistent drive to Independent Persistent using:
Get-Harddisk -VM MachineName| Set-HardDisk -Persistence IndependentPersistent
But I cannot go the other way, running:
Get-Harddisk -VM MachineName| Set-HardDisk -Persistence NonPersistent
...gets me:
Set-HardDisk : 16/02/2009 14:30:48 Set-HardDisk A7CAA7AF-D4C7-4097-B81B-1EA9C1B7C710 Changing virtual hard disk persistance from "IndependentPersistent" to "IndependentNonPersistent" is not supported. At line:1 char:45 + Get-Harddisk -VM MachineName| Set-HardDisk <<<< -Persistence IndependentNonPersistent
and running:
Get-Harddisk -VM MachineName| Set-HardDisk -Persistence NonPersistent
Gets me:
WARNING: Consider using another persistence policy because 'NonPersistent' is deprecated and will be discontinued in a future release. Also it doesn't work with snapshots and is not supported on ESX 3.5 and higher. Set-HardDisk : 16/02/2009 14:32:42 Set-HardDisk A7CAA7AF-D4C7-4097-B81B-1EA9C1B7C710 Changing virtual hard disk persistance from "IndependentPersistent" to "NonPersistent" is not supported. At line:1 char:45 + Get-Harddisk -VM MachineName| Set-HardDisk <<<< -Persistence NonPersistent
Can anyone explain how to go about converting persistent disks to non-persistent using VI Toolkit 1.5? Ironically, the example from Get-Help Set-HardDisk, shows:
-------------- Example 1 -------------- C:\PS>$myVM = Get-VM -Name WinXP2 Shutdown-VMGuest -VM $myVM $myVM | Get-HardDisk | Set-HardDisk -Persistence NonPersistent Changes the persistence of the WinXP2 virtual machine hard disk to NonPersi stent.
And this doesn't work - is this just a bug in the new VI toolkit?
Looks like a bug. We change the behavior of this cmdlet, and I believe it was because IndependentNonpersistent disks can't be created on 3.5. Does that match your experience?
I've asked the dev team to look in to it.
Here is a workarownd of that issue, using the .Net toolkit
$vmView = Get-View -ID (Get-VM -Name "vmName").ID #Obtain the view of the VM where disk needs to be modified $currentHD = $vmView.Config.Hardware.Device[10] #From the VM view obtain the device for the hard disk that will be modified. You should select the one that's your disk $newHD = New-Object "VMware.Vim.VirtualDisk" #Create new VirtualDisk object #For the created VirtualDisk object you should provide some mandatory properties, that you could take from the hard disk that will be modified $newHD.CapacityInKB = $currentHD.CapacityInKB $newHD.Key = $currentHD.Key $newHD.ControllerKey = $currentHD.ControllerKey $newHD.UnitNumber = $currentHD.UnitNumber $newHD.Backing = New-Object "VMware.Vim.VirtualDiskFlatVer2BackingInfo" #Create new object for the new disk backing $newHD.Backing.DiskMode = "independent_nonpersistent" #Select the desired DiskMode $newHD.Backing.FileName = $currentHD.Backing.FileName #FilleName is also mandatory so you should obtain it from the current disk $vdcs = New-Object "VMware.Vim.VirtualDeviceConfigSpec" #Create a device configuration spec $vdcs.Device = $newHD #For the device property pass the newly created disk $vdcs.Operation = 'Edit' #Specify that you will edit the disk $cs = New-Object "VMware.Vim.VirtualMachineConfigSpec" #Ceate a VM configuration spec $cs.DeviceChange = $vdcs #For the device change specify the created device configuration spec $vmView.ReconfigVM($cs) #Execute ReconfigVM method for the VM view with the created VM configuration spec
I know that this is not quite convenient, but for now its a workaround
Looks like PowerCLI v4.0 resolves this issue.