VMware Cloud Community
Gairc17
Enthusiast
Enthusiast
Jump to solution

New-Harddisk help

Hello,

I am looking to add the additional hard disk option when create a new VM. I have used the below

$addition = Read-Host "Y/N"

If ($addition -eq "Y") {

$disk2 = Read-Host etc...} # enter amount in GB for additional disk

otherwise if "n" it will just continue.

For the New-VM part of the script, i have added the same as the above

If ($addition -eq "Y") {

New-HardDisk -VM

What would be the correct parameters to create a basic additional disk as im not sure how much it needs, and is there a better way to do this?

Thanks

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I'm not sure you understood what I said, the CapacityGB parameter only accepts 1 value.
You can not pass an array to that parameter.

If you want to add multiple harddisks to a VM you will have to call New-Harddisk multiple times.

In a Foreach loop for example.

$disksizes | ForEach-Object -Process {

    New-HardDisk -VM $vm -CapacityGB $_ -StorageFormat EagerZeroedThick

}


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

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

On the New-VM cmdlet you can also add additional harddisks with the DiskGB parameter.

If you specify two values on that parameter, 2 harddisks will be created.

If the VM already exists, then the New-Harddisk cmdlet is te correct way.

You cmdlet that cmdlet once for each harddisk you want to add.


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

Reply
0 Kudos
Gairc17
Enthusiast
Enthusiast
Jump to solution

Ah I see, so I can specify say two values in a variable like 10,20 (C drive and additional drive)?

How would you add the additional disk when deploying from a template? The -DiskGB isnt used in the cmd because the C drive is already present in the template.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

When you are using a Template with the New-VM cmdlet, the DiskGB parameter is not available.

The New-VM cmdlet has several different parametersets.

When you are using a Template with the New-VM cmdlet, you will have to add additional harddisks after the VM has been created with the New-Harddik cmdlet.


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

Reply
0 Kudos
Gairc17
Enthusiast
Enthusiast
Jump to solution

What would be the standard parameters for a New-Harddisk for a new VM deployment?

New-HardDisk -VM -CapacityGB  -Datastore  -StorageFormat

Would be useful to see when you do it via the GUI what it does in the background

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you are on vSphere 6.7U2 you can look at what API calls the Web Client does, via Code Capture.
Via these API calls you can understand which cmdlets and parameters to use.


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

Gairc17
Enthusiast
Enthusiast
Jump to solution

That's really useful to know, thanks for that!

I am seeing this come up more and more for additional disk creation when deploying from a template

$diskSizes = @()

do {

    $diskSize = Read-Host -Prompt "Additional disk (size in GB or 'no' to stop)"

    if($diskSize -ne 'no'){

        $diskSizes += $diskSize

    }

}

until($diskSize -eq 'no')

if($diskSizes.Count -gt 0){

    New-HardDisk -VM $vm -CapacityGB $diskSizes -StorageFormat EagerZeroedThick | New-ScsiController -Type ParaVirtual -Confirm:$false | Out-Null

}

Is this a better way then the code mentioned in the original question?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, that will not work.


The CapacityGB parameter on the New-Harddisk cmdlet only accepts 1 value.

The DiskGB parameter on the New-VM cmdlet accepts an array of values.


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

Gairc17
Enthusiast
Enthusiast
Jump to solution

In theory its a better method to the original one I posted?

To confirm

This will add just one new disk

New-HardDisk -VM $vm -CapacityGB $diskSizes -StorageFormat EagerZeroedThick | New-ScsiController -Type ParaVirtual -Confirm:$false | Out-Null

This will add multiple if set

New-HardDisk -VM $vm -DiskGB $diskSizes -StorageFormat EagerZeroedThick | New-ScsiController -Type ParaVirtual -Confirm:$false | Out-Null

Hope I've understood that correctly

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm not sure you understood what I said, the CapacityGB parameter only accepts 1 value.
You can not pass an array to that parameter.

If you want to add multiple harddisks to a VM you will have to call New-Harddisk multiple times.

In a Foreach loop for example.

$disksizes | ForEach-Object -Process {

    New-HardDisk -VM $vm -CapacityGB $_ -StorageFormat EagerZeroedThick

}


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

Reply
0 Kudos
Gairc17
Enthusiast
Enthusiast
Jump to solution

Thank you.

Helpful as always!

Reply
0 Kudos