如果我运行命令:
Resize-VHD -ComputerName $VMhost -Path "D:\VMs\$VMname\Virtual Hard Disks\$vmname.vhdx" -SizeBytes 70GB
Powershell 足够聪明,可以理解 70GB 是什么,接受争论并调整驱动器大小,
但是,如果我这样做:
$drivesize = "70GB"
Resize-VHD -ComputerName $VMhost -Path "D:\VMs\$VMname\Virtual Hard Disks\$vmname.vhdx" -SizeBytes $drivesize
我收到以下错误:
Resize-VHD : Cannot bind parameter 'SizeBytes'. Cannot convert value "70GB" to type "System.UInt64". Error: "Input string was
not in a correct format."
At line:22 char:100
+ ... D:\VMs\$VMname\Virtual Hard Disks\$vmname.vhdx" -SizeBytes $drivesize
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Resize-VHD], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Vhd.PowerShell.Cmdlets.ResizeVhd
我认为这是一个变量类型问题,错误说明了很多,我只是不知道如何解决它。
编辑:
如果我将值写入$drivesize
控制台,我会得到:
PS C:\Windows\system32> $drivesize
70GB