prasanna22kumar
Contributor
Contributor

Script to add new hard disk to multiple VM's

Hi All/Lucd,

Kindly help me in powershell Script to add new hard disk (10 GB) to multiple VM's.

Thanks in advance.

Regards,

Kumar

0 Kudos
4 Replies
mpeneva
VMware Employee
VMware Employee

Hi,

You need to use the New-HardDisk command. Here is its documentation link: https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.core/commands/new-harddisk/#C...

In your case, I would do something like :

foreach ($vm in $vms){

  $vm | New-HardDisk -CapacityGB 10 [any_other_settings if needed to be added] | Out-Null

}

Regards,

Maya

0 Kudos
prasanna22kumar
Contributor
Contributor

Hi Maya,

Thanks for your reply..

If I want include 'Thin Provisioning' and create the disk on default location of the VM reside datastore.

Thanks in advance 

Regards,

Kumar 

0 Kudos
mpeneva
VMware Employee
VMware Employee

HI,

The New-HardDisk cmdlet has the needed parameters for these actions (Check the help link above).

Regards,

Maya

0 Kudos
prasanna22kumar
Contributor
Contributor

Hello Maya,

Getting error can help me out..Please

New-HardDisk : 23/06/2022 10:30:12 New-HardDisk Strings as pipeline input are not supported.
At C:\temp\win.ps1:6 char:9
+ $vm | New-HardDisk -CapacityGB 10 -DiskType PMem
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-HardDisk], VimException
+ FullyQualifiedErrorId : Core_ObnArgumentTransformationAttribute_Transform_InvalidPipelineArgument,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk

New-HardDisk : 23/06/2022 10:30:12 New-HardDisk Strings as pipeline input are not supported.
At C:\temp\win.ps1:6 char:9
+ $vm | New-HardDisk -CapacityGB 10 -DiskType PMem
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-HardDisk], VimException
+ FullyQualifiedErrorId : Core_ObnArgumentTransformationAttribute_Transform_InvalidPipelineArgument,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk

0 Kudos