Consider the following Powershell snippet:
[Uint64] $Memory = 1GB
[string] $MemoryFromString = \"1GB\"
[Uint64] $ConvertedMemory = [Convert]::ToUInt64($Memor
Your problem is that the ToUint64
doesn't understand the Powershell syntax. You could get around it by doing:
($MemoryFromString / 1GB) * 1GB
As the $MemoryFromString
will be converted its numeric value before the division.
This works because at the point of division Powershell attempts to convert the string to a number using its rules, rather than the .Net rules that are baked into ToUInt64
. As part of the conversion if spots the GB
suffix and applies it rules to expand the "1GB"
string to 1073741824
EDIT: Or as PetSerAl pointed out, you can just do:
($MemoryFromString / 1)