VMware Cloud Community
Skagnola
Enthusiast
Enthusiast
Jump to solution

Interactive Hard Disk Edit Function

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

Tags (2)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try piping that to Out-Default

Get-HardDisk $VM | Select CapacityGB,Filename | Out-Default


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

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

Try piping that to Out-Default

Get-HardDisk $VM | Select CapacityGB,Filename | Out-Default


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

Skagnola
Enthusiast
Enthusiast
Jump to solution

Thanks, Luc! that got me further!

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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

0 Kudos
Skagnola
Enthusiast
Enthusiast
Jump to solution

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.

0 Kudos