VMware Cloud Community
NeedToKnowBasis
Enthusiast
Enthusiast
Jump to solution

Specifying Disk Partitions in PowerCLI Script

I am trying to create a PowerCLI script that will create VM's based on settings that are taken from a CSV file. The CSV file is a result of a VBA script extracting data from an Excel spreadsheet that users will have entered their desired settings.
What I have so far:
$CSVPath = "C:\NewVMList.csv"  
$CSVFILE = Import-CSV $CSVPath 
$VMhost = Get-vmhost "$($CSVFile.VMHost)" $PortGroup = Get-VirtualPortgroup -name "$($CSVFile.VLAN)" -VMhost $VMhost  New-VM -Name "$($CSVFile.Name)" -MemoryGB "$($CSVFile.MemoryGB)" -NumCPU "$($CSVFile.NumCPU)" -portgroup $Portgroup -DiskGB "$($CSVFile.C_System)"
The CSV file that it will be referencing for the values will have 3 cells that are available for the various partitions to be assigned space (C:\, D:\, M:(app data)).
What I would like to know is if there is a function that I can use within my PowerCLI script that can assign the various partitions the appropriate amount of space based on the CSV file or if this would need to be done manually?
Would it require something other than the -DiskGB "$($CSVFile.C_System)" to create partitions, as this seems (I assume) to reference the overall disk space being allocated?
Thank you for any help you may provide
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There is a difference between the VM harddisks and the guest OS partitions (C, D and M).

To assign harddisks to your VM, you can indeed use the DiskGB parameter on the New-VM cmdlet.

The parameter expects an array of values, and the cmdlet will assign a harddisk to the VM for each number you pass on the DiskGB parameter.

Assigning drive letters in the guest OS, is independent of assigning harddisks to the VM.

The guest OS, obviously Windows in this case, has an algorithm to assign default drive letters to the attached disks.

The default would be that these harddisks get the drive letters C, D and E.

You can change the drive letters with a script that has to run inside the guest OS.

This can be done remotely (over the network) or through the Invoke-VMScript cmdlet.

Such a script could look like this

$eDrive = Get-WmiObject -Class win32_volume -Filter “DriveLetter = ‘E:'”

Set-WmiInstance -input $eDrive -Arguments @{DriveLetter=”M:”; Label=”AppData”}


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

View solution in original post

0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

There is a difference between the VM harddisks and the guest OS partitions (C, D and M).

To assign harddisks to your VM, you can indeed use the DiskGB parameter on the New-VM cmdlet.

The parameter expects an array of values, and the cmdlet will assign a harddisk to the VM for each number you pass on the DiskGB parameter.

Assigning drive letters in the guest OS, is independent of assigning harddisks to the VM.

The guest OS, obviously Windows in this case, has an algorithm to assign default drive letters to the attached disks.

The default would be that these harddisks get the drive letters C, D and E.

You can change the drive letters with a script that has to run inside the guest OS.

This can be done remotely (over the network) or through the Invoke-VMScript cmdlet.

Such a script could look like this

$eDrive = Get-WmiObject -Class win32_volume -Filter “DriveLetter = ‘E:'”

Set-WmiInstance -input $eDrive -Arguments @{DriveLetter=”M:”; Label=”AppData”}


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

0 Kudos