Good morning,
I decided to see if I can automate removal og RDMs from a Windows cluster node in order to migrate.
This turned out not to be difficult at all, and the following works:
Get-VM node02 | Get-HardDisk -DiskType RawPhysical, RawVirtual | Remove-HardDisk -Confirm:$false
The problem is that this command also deletes the SCSI controllers.
Is there a way to remove the RDM pointers/disks and still keep the SCSI controllers?
NM, I figured it out.
Since I had riun the first script in this thread, the $hdnames variable was there.
when I after a restart of the PS editor it is no longer there,
It worked when I ran:
$vmName = 'node02'
$vm = Get-VM -Name $vmName
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
Get-HardDisk -VM $vm -DiskType RawVirtual,RawPhysical -PipelineVariable hd |
ForEach-Object -Process {
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.Device = $hd.ExtensionData
$dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::remove
$spec.DeviceChange += $dev
}
$vm.ExtensionData.ReconfigVM($spec)
So, just delete all RDM disks, removing the -Name $hdnames
Yes, but you will have to use the API method.
Something like this for example (it removes 3 harddisks while keeping the SCSI controllers to which they are connected)
$hdNames = 'Hard disk 2','Hard disk 3','Hard disk 4'
$vm = Get-VM -Name $vmName
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
Get-HardDisk -VM $vm -Name $hdNames -PipelineVariable hd |
ForEach-Object -Process {
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.Device = $hd.ExtensionData
$dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::remove
$spec.DeviceChange += $dev
}
$vm.ExtensionData.ReconfigVM($spec)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That will work, thank you.
However, it will require me to fill in the $hdnames, which amounts to a fair bit of work with 36 of htem.
Is there a way to make the $hdnames variable read form the configuration, some working version of:
$hdNames = Get-HardDisk -DiskType RawPhysical, RawVirtual
this does not work, but you see where I am trying to go with this?
If you want to remove all RDM disks you could do
$vm = Get-VM -Name $vmName
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
Get-HardDisk -VM $vm -Name $hdNames -DiskType RawVirtual,RawPhysical -PipelineVariable hd |
ForEach-Object -Process {
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.Device = $hd.ExtensionData
$dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::remove
$spec.DeviceChange += $dev
}
$vm.ExtensionData.ReconfigVM($spec)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That is what I want 🙂
Thank you, oh Grand Wizard of The PowerCLI 🙂
Worked beautifully until today..
When I run this now, I get:
Get-HardDisk : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:9 char:28
+ Get-HardDisk -VM $vm -Name $hdNames -DiskType RawVirtual,RawPhysical ...
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-HardDisk], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.GetHardDisk
The name is the VM name, and I just copy whatever Get-VM gives me back, but for some reason the name seems to be invalid....?
(I just remember, I patched my vCenter last night, but this should still work?)
NM, I figured it out.
Since I had riun the first script in this thread, the $hdnames variable was there.
when I after a restart of the PS editor it is no longer there,
It worked when I ran:
$vmName = 'node02'
$vm = Get-VM -Name $vmName
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
Get-HardDisk -VM $vm -DiskType RawVirtual,RawPhysical -PipelineVariable hd |
ForEach-Object -Process {
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.Device = $hd.ExtensionData
$dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::remove
$spec.DeviceChange += $dev
}
$vm.ExtensionData.ReconfigVM($spec)
So, just delete all RDM disks, removing the -Name $hdnames