10 Replies Latest reply on Aug 14, 2020 3:46 AM by Gairc17

    New-Harddisk help

    Gairc17 Enthusiast

      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. Re: New-Harddisk help
          LucD Guru
          Community WarriorsvExpertUser Moderators

          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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: New-Harddisk help
            Gairc17 Enthusiast

            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.

            • 3. Re: New-Harddisk help
              LucD Guru
              Community WarriorsUser ModeratorsvExpert

              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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: New-Harddisk help
                Gairc17 Enthusiast

                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

                • 5. Re: New-Harddisk help
                  LucD Guru
                  User ModeratorsvExpertCommunity Warriors

                  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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  1 person found this helpful
                  • 6. Re: New-Harddisk help
                    Gairc17 Enthusiast

                    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?

                    • 7. Re: New-Harddisk help
                      LucD Guru
                      vExpertUser ModeratorsCommunity Warriors

                      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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: New-Harddisk help
                        Gairc17 Enthusiast

                        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

                        • 9. Re: New-Harddisk help
                          LucD Guru
                          User ModeratorsvExpertCommunity Warriors

                          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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                          • 10. Re: New-Harddisk help
                            Gairc17 Enthusiast

                            Thank you.

                             

                            Helpful as always!