Hello!
I am working on a function that will moderately ask for interaction from the user when calling it up. My issue is right from the beginning, when I am trying to list the current hard disks, it is not showing up - as if the line in the function is not there
#Interactive hard disk expansion
function Add-VMDiskSpace {
[cmdltbind()]
param(
[Parameter(Mandatory=$true)][string]$VM,[string]$IncreaseSpaceGB ='20'
)
process {
#Show current disks
Write-Host "Current disks..." -ForegroundColor Yellow
Get-HardDisk $VM | Select CapacityGB,Name<--- Being skipped and going right to the prompt in the next line
#Input name of disk to increase
$HardDisk = Read-Host -Prompt "Specify hard disk name to resize"
#Get the size of disk
$Size = Get-HardDisk -Name $HardDisk | Select-Object -ExpandProperty CapacityGB
#Increase size of disk by the $IncreaseSpaceGB
Get-HardDisk -Name $HardDisk $VM | Set-HardDisk -CapacityGB ($Size + $IncreaseSpaceGB) -Confirm:$true
#Notify operation is complete
Write-Host "Disk has been expanded." -ForegroundColor Green
}
}
Have not been able to get much further yet, as I'm scratching my head as to why the first piece won't show up. The idea is to show the list of disks for the person to choose from, rather than doing it in a separate command sequence.
The function call is as
Add-VMDiskSpace -VM testvm -IncreaseSpaceGB 5
... and for me, goes to ...
Specify hard disk name to resize:
But there is no error as if the param is not being read or is seen as null. Not sure if there is a syntax issue with the mandatory params or not. Or something elsewhere.
EDIT: Changed the
| Select CapacityGB,FileName
to
| Select CapacityGB,Name
Try piping that to Out-Default
Get-HardDisk $VM | Select CapacityGB,Filename | Out-Default
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try piping that to Out-Default
Get-HardDisk $VM | Select CapacityGB,Filename | Out-Default
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, Luc! that got me further!
Hi LucD,
when using the above script, I am getting the below error, please help
Specify hard disk name to resize: [DS_Local_Vol_1] aurvpvcn/aurvpvcn_3.vmdk
Get-HardDisk : 3/7/2018 7:19:18 AM Get-HardDisk Please specify at least one of the following: Path, Datastore, VirtualMachine, Template or Snapshot.
At C:\Users\adm.jmadhu\Documents\WindowsPowerShell\Modules\Add-VMDiskSpace.psm1:16 char:17
+ $Size = Get-HardDisk -Name $HardDisk | Select-Object -ExpandProperty Cap ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-HardDisk], ViError
+ FullyQualifiedErrorId : Core_VirtualDeviceGetter_GetMoListFromCmdletParameter_InsufficientParameters,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.GetHardDisk
Hey, ganapa2000
I had to modify my line
Get-HardDisk $VM | Select CapacityGB,Filename | Out-Default
to
Get-HardDisk $VM | Select CapacityGB,Name| Out-Default
See if that works for you, using the hard disk names that are returned with the capacity visible of the one you want to modify.