VMware Cloud Community
JLogan2016
Enthusiast
Enthusiast

Adding Disks and SCSI controllers

I am working on a script for a number of SQL servers in which we break out the data drives on different SCSI controllers. Code is below:

$oVCenter = "myServer"

$oVM = "myMachine"

Connect-VIServer -Server $oVCenter | Out-Null

$vm = Get-VM $oVM

#region SCSI #1

    $newSCSI1 = New-HardDisk -VM $vm -CapacityGB 1024 -StorageFormat EagerZeroedThick |        #P at 1:1

                                    New-ScsiController -Type ParaVirtual -Confirm:$false

   

    $newNDrive = New-HardDisk -VM $vm -CapacityGB 1024 -StorageFormat EagerZeroedThick -Controller $newSCSI1 #N at 1:0

#endregion SCSI #1

#region SCSI #2

    $newSCSI2 = New-HardDisk -VM $vm -CapacityGB 15 -StorageFormat EagerZeroedThick |          #Q at 2:1

                                    New-ScsiController -Type ParaVirtual -Confirm:$false

#endregion SCSI #2

#region SCSI #3

    $newSCSI3 = New-HardDisk -VM $vm -CapacityGB 25 -StorageFormat EagerZeroedThick |          #R at 3:1

                                    New-ScsiController -Type ParaVirtual -Confirm:$false

    New-HardDisk -VM $vm -CapacityGB 20 -StorageFormat EagerZeroedThick -Controller $newSCSI3  #O at 3:0

#endregion SCSI #3

Disconnect-VIServer -Server $sServer -Confirm:$false

The code works just fine. I am merely curious why it seems to always drop a new hdd in slot 1 when creating a new controller. The first call, for example, creates the controller and puts the drive at 1:1. The next drive I create and point at that controller goes to 1:0. Thereafter it seems drives are added in order: 1:2, 1:3, etc. As it stands, the sole drive I am creating on controller 2 is slotted in 2:1 and then I have to move it to 2:0 manually.

So, I am just wondering, is there a reason for the behavior I am seeing? Secondary to this, is there an easy way to create and/or move a disk to the controller and slot that I want? I did some googling, and have been looking at Set-HardDisk doc but am not seeing it a way to call the slot, only the controller.

0 Kudos
7 Replies
LucD
Leadership
Leadership

Not with a cmdlet I'm afraid.

You will have to use the API method.

Have a look at 5. Re: Script for attaching multiple existing disk to VM with specific scsi bus number and device numbe...


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
JLogan2016
Enthusiast
Enthusiast

Thanks for this, as always.

0 Kudos
JLogan2016
Enthusiast
Enthusiast

I guess I am a little more confused than I originally thought. I am using the script you linked to, and have set up my spreadsheet similarly. My understanding was that the script would create both the controllers and the drives, and then move the drives to the appropriate slots on the controllers. However, if I run the script against a machine that has no drives (aside from the OS drive), it creates the controllers but then fails to create the drives:

Header 1Header 2Header 3Header 4
vmnamedatastorepathscsibusnumberunitnumber
LC-SERV03[dStore02]LC-SERV03/LC-SERV03_1.vmdk10
LC-SERV03[dStore02]LC-SERV03/LC-SERV03_2.vmdk11
LC-SERV03[dStore02]LC-SERV03/LC-SERV03_3.vmdk20
LC-SERV03[dStore02]LC-SERV03/LC-SERV03_4.vmdk30
LC-SERV03[dStore02]LC-SERV03/LC-SERV03_5.vmdk31

"File[]/<vmfs path>/LC-SERV03/LC-SERV03_1.vmdk was not found"

I figured I would need to create the disks before hand, and just run this to move them to the appropriate spots. When the disks are already created, however, the script does not error out but instead creates 5 additional disks. So I end up with 10 total, with 5 correctly moved to the Controllers/Slots specified in the csv.

0 Kudos
LucD
Leadership
Leadership

I suspect that might be caused by the CSV file.

The Header1, Header2... shouldn't be there,  headers should say vmname, datastorepath...


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
JLogan2016
Enthusiast
Enthusiast

Sorry for the delay in response. The Header1, 2, and 3 is just the forum formatting when I created the table. The actual csv does have the appropriate headers in it.

0 Kudos
LucD
Leadership
Leadership

Ok, and is "File[]/<vmfs path>/LC-SERV03/LC-SERV03_1.vmdk was not found" the actual error you are getting?
Or did you edit that? Especially the <vmfs path> part.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
JLogan2016
Enthusiast
Enthusiast

Sorry for the delay in response. Below is the error that I am getting in full.

Exception calling "ReconfigVM" with "1" argument(s): "File []/vmfs/volumes/5949b5cf-c05120e7-4ed7-000c29428f0c/LC-SERV03/LC-SERV03_5.vmdk was not found"

At line:53 char:9

+         $vm.ExtensionData.ReconfigVM($spec)

+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : VimException

vmnamedatastorepath scsibusnumber unitnumber
LC-SERV03[dStore03]/LC-SERV03/LC-SERV03_1.vmdk10
LC-SERV03[dStore03]/LC-SERV03/LC-SERV03_1.vmdk11
LC-SERV03[dStore03]/LC-SERV03/LC-SERV03_1.vmdk20
LC-SERV03[dStore03]/LC-SERV03/LC-SERV03_1.vmdk30

I should mention, I have tried both with and without the / after the datastore name in the csv file

0 Kudos