If i remove the foreach i get an error message (See below). My script seems to work fine. I tried it on 5 vms this morning.
Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or
empty. Supply an argument that is not null or empty and then try the command ag
ain.
At C:\Users\baptisec_pc\Desktop\VDI\PowerCLI Scripts\VMMemory2.ps1:2 char:13
+ Get-VM -Name <<<< $_ |
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValid
ationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
ation.ViCore.Cmdlets.Commands.GetVM