You're passing a virtual machine object instead of a string to get-wmiObject -ComputerName
. When I do that, get-wmiObject throws an RPC error. You might try -computerName $vm.guest.Hostname
instead of -computerName $vm
.
In the commented line, your use of %
should return a remainder, which will always be a whole number or zero. Maybe you were expecting a quotient instead, and wanted to evaluate if it's an integer?
PS C:\temp> (1 / 2) -isnot [int]
True
PS C:\temp> (2 / 1) -isnot [int]
False
Recent Windows OS align their partitions automatically, so there's that. Here's a good post about alignment generally on VMware, including a link to a more detailed discussion of guest partitions.