Quantcast
Channel: VMware Communities : Discussion List - Automation Tools
Viewing all articles
Browse latest Browse all 9071

Any idea why this simple script to increase disk size is failing

$
0
0

Found a script that should theoretically increase the disk size on a .csv list of VM's.  Unfortunately however it fails, and in honesty I dont have any idea why, using F8 to step through it you can see where it fails below.  Any suggestions would be greatly appreciated, this is vSphere 6.5 if its relevant.

 

 

write-Host "Loading Automation Tools"

 

Add-PSSnapin VMware.VimAutomation.Core

 

 

 

 

 

 

# Establish Connection

Connect-VIServer -Server SecretServer -User ME -Password SecretPassword

 

 

Import-Csv -Path 'C:\temp\testvms.csv' | %{

   $VMx = $_.Name

   $vm = get-vm |?{$_.Name -eq $VMx}

   $HD = get-harddisk -VM $vm.Name -Name "Hard disk 1"

   $NewCap = [decimal]::round($HD.CapacityGB + 20)

   $HD | Set-harddisk -CapacityGB  $NewCap

}

 

OUTPUT...

 

SecretServer... 443   hidden\ServerMe      

Get-HardDisk : 16/04/2018 09:17:07    Get-HardDisk        Exception has been thrown by the target of an invocation.    At

C:\temp\IncreaseDisk120GB.ps1:13 char:10

+    $HD = get-harddisk -VM $vm.Name -Name "Hard disk 1"

+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-HardDisk], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.GetHard

   Disk

 

Set-HardDisk : Cannot validate argument on parameter 'HardDisk'. The argument is null. Provide a valid value for the

argument, and then try running the command again.At C:\temp\IncreaseDisk120GB.ps1:15 char:10

+    $HD | Set-harddisk -CapacityGB  $NewCap

+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Set-HardDisk], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.Set

   HardDisk

 

Get-HardDisk : 16/04/2018 09:17:07    Get-HardDisk        Exception has been thrown by the target of an invocation.    At

C:\temp\IncreaseDisk120GB.ps1:13 char:10

+    $HD = get-harddisk -VM $vm.Name -Name "Hard disk 1"

+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-HardDisk], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.GetHard

   Disk

 

Set-HardDisk : Cannot validate argument on parameter 'HardDisk'. The argument is null. Provide a valid value for the

argument, and then try running the command again.At C:\temp\IncreaseDisk120GB.ps1:15 char:10

+    $HD | Set-harddisk -CapacityGB  $NewCap

+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Set-HardDisk], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.Set

   HardDisk

 

Get-HardDisk : 16/04/2018 09:17:07    Get-HardDisk        Exception has been thrown by the target of an invocation.    At

C:\temp\IncreaseDisk120GB.ps1:13 char:10

+    $HD = get-harddisk -VM $vm.Name -Name "Hard disk 1"

+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-HardDisk], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.GetHard

   Disk

 

Set-HardDisk : Cannot validate argument on parameter 'HardDisk'. The argument is null. Provide a valid value for the

argument, and then try running the command again.At C:\temp\IncreaseDisk120GB.ps1:15 char:10

+    $HD | Set-harddisk -CapacityGB  $NewCap

+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Set-HardDisk], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.Set

   HardDisk

 

 

 

 

 

 

 

PS H:\>


Viewing all articles
Browse latest Browse all 9071

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>