We are trying to change all Hard Disks except the OS Drive (Hard Disk 1) on our SQL VMs to the Paravirtual SCSI controller. We have scripted adding the new controller to the VM but when we run the script below to change the controller, it adds 1 drive to Controller 1 bus 0 and fails to add the rest of the disks to other bus'. Script fails with "Invalid configuration for device '0'" Any help is appreciated...
$VMs = "ServerName"
foreach($VM in $VMs){
$controller = Get-ScsiController -Name "SCSI Controller 1" -VM $VM
$HardDisks = Get-HardDisk -VM $VM | where {$_.Name -notlike "Hard Disk 1"}}
foreach($HardDisk in $HardDisks){
Set-HardDisk $HardDisk -Controller $controller -Confirm:$false
}
Did you check the vpxd log for more clues on that error?
Which PowerCLI version are you using?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If I continue to run the script it will eventually assign the controller 1 to all disks (except Disk 1 of course) but places them on bus 1, 2, 3, 4 (of controller 1) and nothing on bus 0.
The actual error...
That seems to show that vSphere is changing Labels and Ids.
That could explain why your Harddisk references are not up-to-date anymore after the 1st change.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is there a way to script it where it changes only the data drives (not C Drive) to "Controller 1" (Paravirtual) or am I to change them all manually?
We created a "workaround" script. It seems to work without changing the disk labels.
$VMs = "TargetVM"
#Step 1: Change Disk that is named 'Hard Disk 2' only to Paravirtual Controller
foreach($VM in $VMs){
$controller = Get-ScsiController -Name "SCSI Controller 1" -VM $VM
$HardDisks = Get-VM $VM | Get-HardDisk | where {$_.Name -eq "Hard Disk 2"}
foreach($HardDisk in $HardDisks){
Set-HardDisk $HardDisk -Controller $controller -Confirm:$false
}
}
#Step 2: Clear the existing values for $HarDisks and $HardDisk variables
$HardDisks = $null
$HardDisk = $null
#Step 3: Change All Disks that are not using 'SCSI_ID:0' to Paravirtual. As a result, this will EXCLUDE Hard Disk 1 (Bus:0/SCSI_ID:0) and Hard Disk 2 (Bus:1/SCSI_ID:0). Disks are processed in order via Name.
foreach($VM in $VMs){
$controller = Get-ScsiController -Name "SCSI Controller 1" -VM $VM
$HardDisks = Get-VM $VM | Get-HardDisk | where {$_.ExtensionData.UnitNumber -notlike "0"} | Sort Name
foreach($HardDisk in $HardDisks){
Set-HardDisk $HardDisk -Controller $controller -Confirm:$false
}
}