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
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
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
HI,
The New-HardDisk cmdlet has the needed parameters for these actions (Check the help link above).
Regards,
Maya
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
this throws an error
At C:\temp\test.ps1:4 char:9
+ $vm | New-HardDisk -CapacityGB 10
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-HardDisk], VimException
+ FullyQualifiedErrorId : Core_ObnArgumentTransformationAttribute_Transform_InvalidPipelineArgument,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk
Below is the script i'm trying
$vms=Get-Content "c:\temp\batch.txt"
foreach ($vm in $vms)
{
$vm|New-HardDisk -CapacityGB 10
}
What do you have in $vm?
A String with the name of the VM?
Try doing
Get-VM -Name $vm | New-HardDisk -CapacityGB 10
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD for your reply..
After adding the line as you mentioned getting following error.
New-HardDisk : 23/02/2023 17:35:56 New-HardDisk The operation for the entity "xcpXXXXX" failed with the following message: "A general system error occurred: PBM error occurred
during PreReconfigureCallback: Fault cause: vmodl.fault.SystemError
;
"
At C:\temp\test.ps1:4 char:22
+ Get-VM -Name $vm | New-HardDisk -CapacityGB 10
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-HardDisk], SystemError
+ FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk
Regards,
Kumar
See KB2118557, this error occurs when the Profile-Driven Storage service is not running or is not accepting connections
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
