Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 176760

Addin multiple disks on diffrent SCSI controllers via PowerCLI script

$
0
0

I am trying to create a Powercli script for adding additional disks to Sql vms. Scripts runs fine but the disks labels wont create evenly across multiple scsi controllers.

 

Ideally this is what I am trying to get.

 

Hard disk 1  on SCSI 0:1
Hard disk 2  on SCSI 0:2
Hard disk 3  on SCSI 1:1
Hard disk 4  on SCSI 1:2
Hard disk 5  on SCSI 2:1
Hard disk 6  on SCSI 2:2
Hard disk 7  on SCSI 3:1
Hard disk 8  on SCSI 3:2

Hard disk 9  on SCSI 3:3


But this is what I get.


Hard disk 7  on SCSI 0:1
Hard disk 2  on SCSI 0:2
Hard disk 8  on SCSI 1:1
Hard disk 6  on SCSI 1:2
Hard disk 9  on SCSI 2:1
Hard disk 4  on SCSI 2:2
Hard disk 10  on SCSI 3:1
Hard disk 5  on SCSI 3:2

Hard disk 3  on SCSI 3:3

_________________________________________________________________________


Here is my script.

$VMname = Read-Host " Enter the VM hostname"

$D=Read-Host "Enter D drive GB Size"

$E=Read-Host "Enter E drive GB Size"

$SYSTEMDBS1 = Read-Host "Enter SYSTEMDB1 GB Size"

$DATA1 = Read-Host "Enter DATA1 GB Size"

$LOGS1 = Read-Host "Enter LOGS1 GB Size"

$DBA_ADMIN_LOGS1 = Read-Host "Enter DBA_ADMIN_LOGS1 GB Size"

$TEMPDB1 = Read-Host "Enter TEMPDB1 GB Size"

$DBA_ADMIN_DATA1 = Read-Host "Enter DBA_ADMIN_DATA1 GB Size"

$DBAUTILITY = Read-Host "Enter DBAUTILITY GB Size"

 

 

stop-vm -vm $VMname -confirm:$false

Start-sleep -s 5

$VM= get-vm -Name $VMname

 

 

##Adding D and E Drive

New-HardDisk -VM  $VM -CapacityGB  $D -DiskType Flat -StorageFormat Thin

New-HardDisk -VM  $VM -CapacityGB  $E -DiskType Flat -StorageFormat Thin

 

 

foreach ($HardDisk in (1))

{

 

 

$VM | New-HardDisk  -CapacityGB   $SYSTEMDBS1  -DiskType Flat -StorageFormat Thin | New-ScsiController -Type ParaVirtual

##

$hdskToChange = Get-HardDisk -VM $VM -Name "Hard disk 4"

##$VM | Get-HardDisk -Name "Hard Disk 3"

## create a new VirtualMachineConfigSpec, with which to make the change to the VM's disk

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

## create a new VirtualDeviceConfigSpec

$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange[0].operation = "edit"

## populate the "device" property with the existing info from the hard disk to change

$spec.deviceChange[0].device = $hdskToChange.ExtensionData

## then, change the second part of the SCSI ID (the UnitNumber)

$spec.deviceChange[0].device.unitNumber = 0

## reconfig the VM with the updated ConfigSpec (VM must be powered off)

$VM.ExtensionData.ReconfigVM_Task($spec)

 

 

Start-Sleep -s 5

New-HardDisk -VM  $VM -CapacityGB  $DATA1 -DiskType Flat -StorageFormat Thin -Controller "SCSI Controller 1"

}

 

## Disks on Controller 2

foreach ($HardDisk in (1))

{

 

$VM | New-HardDisk  -CapacityGB  $LOGS1 -DiskType Flat -StorageFormat Thin | New-ScsiController -Type ParaVirtual

##

$hdskToChange = Get-HardDisk -VM $VM -Name "Hard disk 6"

##$VM | Get-HardDisk -Name "Hard Disk 3"

## create a new VirtualMachineConfigSpec, with which to make the change to the VM's disk

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

## create a new VirtualDeviceConfigSpec

$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange[0].operation = "edit"

## populate the "device" property with the existing info from the hard disk to change

$spec.deviceChange[0].device = $hdskToChange.ExtensionData

## then, change the second part of the SCSI ID (the UnitNumber)

$spec.deviceChange[0].device.unitNumber = 0

## reconfig the VM with the updated ConfigSpec (VM must be powered off)

$VM.ExtensionData.ReconfigVM_Task($spec)

 

 

Start-Sleep -s 5

 

 

New-HardDisk -VM  $VM -CapacityGB  $DBA_ADMIN_LOGS1 -DiskType Flat -StorageFormat Thin -Controller "SCSI Controller 2"

}

 

## For Disk on Controller 3

 

foreach ($HardDisk in (1))

{

 

 

$VM | New-HardDisk  -CapacityGB  $TEMPDB1 -DiskType Flat -StorageFormat Thin | New-ScsiController -Type ParaVirtual

##

$hdskToChange = Get-HardDisk -VM $VM -Name "Hard disk 8"

##$VM | Get-HardDisk -Name "Hard Disk 3"

## create a new VirtualMachineConfigSpec, with which to make the change to the VM's disk

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

## create a new VirtualDeviceConfigSpec

$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange[0].operation = "edit"

## populate the "device" property with the existing info from the hard disk to change

$spec.deviceChange[0].device = $hdskToChange.ExtensionData

## then, change the second part of the SCSI ID (the UnitNumber)

$spec.deviceChange[0].device.unitNumber = 0

## reconfig the VM with the updated ConfigSpec (VM must be powered off)

$VM.ExtensionData.ReconfigVM_Task($spec)

 

 

Start-Sleep -s 5

 

 

New-HardDisk -VM  $VM -CapacityGB  $DBA_ADMIN_DATA1 -DiskType Flat -StorageFormat Thin -Controller "SCSI Controller 3"

 

 

New-HardDisk -VM  $VM -CapacityGB  $DBAUTILITY -DiskType Flat -StorageFormat Thin -Controller "SCSI Controller 3"

}

 

Start-sleep -s 2

## Start VM

Start-VM -VM $VM -confirm:$false

_____________________________________________________________________________________________________________________



 

Any help would be appreciated.


Thank You




Viewing all articles
Browse latest Browse all 176760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>