When writing a script I ran into a problem where the Get-VM cmdlet didn’t act the way I expected it to. I executed the command $VM = Get-VM [MyVMName] -ComputerName [MyVMHost] and got the error:
Get-SCVirtualMachine : A parameter cannot be found that matches parameter name ‘ComputerName’.
At line:1 char:22
+ $VM = Get-VM [MyVMName] -ComputerName [MyVMHost]
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-SCVirtualMachine], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.SystemCenter.VirtualMachineManager.Cmdlets.GetVMCmdlet
When looking into the help-contents I could of course clearly see that indeed there was no parameter named ‘Computername’ while I was sure I got this exact parameter from the help-contents.
Looking further into the problem I found the following:
In other words:
There are two commands for ‘Get-VM’: Microsoft introduced a Get-VM-cmdlet Hyper-V powershell module in Windows 2012 which DOES contain a parameter -Computername. The original Get-VM cmdlet which was part of the SCVMM 2008 R2 powershell snap-in is now renamed to Get-SCVirtualMachine in VMM 2012 but an alias ‘Get-VM’ was also created in the new module. This is probably for backward compatibility purposes but leads to conflicting results when importing both modules in the same script.