This one has been annoying me for a bit. It was an issue in PowerCLI 6.3, and it still an issue after upgrading to PowerCLI 6.5 We're still running on ESXi 5.5 (2718055).
When you use New-VM and add a single disk, SCSI Controller 0 gets created, and the disk is assigned to LUN 0.
If I then do a New-HardDisk | New-ScsiController then the first disk on the Controller is assigned to LUN 1. The next time I call it for the same controller, the disk is assigned to LUN 0, and the next time it's assigned to LUN 2, 3, 4 etc (which makes sense).
I think there's a couple of issues here. Firstly, there seems to be a bug with New-ScsiController in adding the first disk to LUN 1 (its behaviour after that seems reasonable). Secondly, when adding new disks via New-HardDisk (and New-ScsiController) should allow me to specify which LUN I want to use. It shouldn't make me add to the next available LUN, then rely on me to go back in and mess around with VMware.Vim.VirtualDeviceConfigSpec and ExtensionData to change it.
Has anyone else come across the same issue? Is there any cleaner way to put the disk at the LUN I want, or is ExtensionData the best there is at the moment.
Graham
(Sorry for not posting in here first Alan - I didn't have my Weetabix this morning).
$DefaultDatastore = "zzShunt-C1"
$DefaultCluster = "Test Cluster"
$DefaultResourcePool = "Live Pool"
$DefaultFolder = "Build Servers"
$DefaultHost = "vmserver80.ceicmhb"
$vm = "test-gwm-002v"
$DiskSize = 10
$Datastore = $DefaultDatastore
$myTargetVMHost = Get-VMHost -Name $DefaultHost
New-VM -Name $vm -ResourcePool $myTargetVMHost -Datastore $DefaultDatastore -NumCPU 2 -MemoryGB 4 -DiskGB 40 -NetworkName "dvVMGuestAreaB" -Floppy -CD -DiskStorageFormat Thin -GuestID winNetDatacenterGuest -Version v8
$NewHD = New-HardDisk -VM $vm -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore
$NewSCSI = New-ScsiController -HardDisk $NewHD -Type ParaVirtual -BusSharingMode NoSharing -Confirm:$false
$NewHD = New-HardDisk -VM $vm -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore
$NewSCSI = New-ScsiController -HardDisk $NewHD -Type ParaVirtual -BusSharingMode NoSharing -Confirm:$false
$NewHD = New-HardDisk -VM $vm -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore
$NewSCSI = New-ScsiController -HardDisk $NewHD -Type ParaVirtual -BusSharingMode NoSharing -Confirm:$false
At this point disk 0 is LUN 0 on controller 0, all the other disks are LUN 1 on their respective controllers.
$ScsiController0 = get-vm $vm | Get-ScsiController | where name -EQ "SCSI controller 0"
$ScsiController1 = get-vm $vm | Get-ScsiController | where name -EQ "SCSI controller 1"
$ScsiController2 = get-vm $vm | Get-ScsiController | where name -EQ "SCSI controller 2"
$ScsiController3 = get-vm $vm | Get-ScsiController | where name -EQ "SCSI controller 3"
$fred = (get-vm $vm | New-HardDisk -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore -Controller $ScsiController0)
$fred = (get-vm $vm | New-HardDisk -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore -Controller $ScsiController1)
$fred = (get-vm $vm | New-HardDisk -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore -Controller $ScsiController2)
$fred = (get-vm $vm | New-HardDisk -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore -Controller $ScsiController3)
Now, the new disk on controller 0 is LUN 1, the new disk on all the other controllers is LUN 0.
Repeat the last 4 lines again, and all the new disks presented are on LUN 2 on the controllers.