I hope someone can shed some light on this as I can't find a similar question elsewhere.
I recently accidentally typed a powershell command "get-vmswitch" into my PowerCLI window. Every Get-* command I typed after that retrieved information from the locally installed Hyper-V instead of the vCenter server I had been connected to.
I can repeat the behavior every time.
Open PowerCLI on my 2012 R2 laptop
connect-VIServer 192.168.0.16
get-VM displays the VMs managed by my vCenter server
get-VM -server 192.168.0.16 #also works
get-vmswitch #displays the network adapters on my 2012R2 laptop
get-vm #displays the Hyper-V VMs on my laptop
get-vm -server 192.168.0.16 # throws an error no parameter matches server
$displayviserver #displays the expected vCenter IP address
connect-viserver #appears to work, but all commands still act against the local machine
My lab is a collection of laptops running Hyper-V and ESXi.
I know that get-vmswitch is a powershell command for Hyper-V, but how does it subvert my PowerCLI session?
Is there a way to recover the session other than closing powerCLI and re-opening it?
LucD,
Thanks!. Your answer is correct. I asked the same question on powershell.com and got most of your answer, but Peter Jurgens added:
/********************************************************************************
Accessing VMware cmdlets from any powershell session is as easy as loading the Snap-In:
Add-PSSnapin vmware*
That will load all registered snap-ins beginning with vmware.
Hope this helps.
EDIT: I stumbled across a blog post from Jeffrey Hicks regarding this exact issue...
http://mcpmag.com/articles/2013/08/20/powershell-name-duplicates.aspx
*******************************************************************************/
http://powershell.com/cs/forums/p/19916/42912.aspx
I added your extra bits to that thread too so anyone stumbling across either thread will get the most complete answer.
Between the two of you, I learned a lot about PS and PowerCLI this week. As an old bash-head moving over to more Windows/VMware, I need to continue that trend.
enjoy,
Von
What I think happened is the following.
One way to make the distinction, is to prefix the cmdlets with the namespace.
VMware.VimAutomation.Core\Get-VM
Hyper-V\Get-VM
Another option is to define your own prefix when loading a module
Remove-Module -Name Hyper-V
Import-Module -Name Hyper-V -Prefix MS
Get-MSVM
In this example, the Hyper-V cmdlets will now have the noun prefixed with MS
Note that you can't do this for PowerCLI, since PowerCLI comes as a pssnapin, not a module.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Thanks!. Your answer is correct. I asked the same question on powershell.com and got most of your answer, but Peter Jurgens added:
/********************************************************************************
Accessing VMware cmdlets from any powershell session is as easy as loading the Snap-In:
Add-PSSnapin vmware*
That will load all registered snap-ins beginning with vmware.
Hope this helps.
EDIT: I stumbled across a blog post from Jeffrey Hicks regarding this exact issue...
http://mcpmag.com/articles/2013/08/20/powershell-name-duplicates.aspx
*******************************************************************************/
http://powershell.com/cs/forums/p/19916/42912.aspx
I added your extra bits to that thread too so anyone stumbling across either thread will get the most complete answer.
Between the two of you, I learned a lot about PS and PowerCLI this week. As an old bash-head moving over to more Windows/VMware, I need to continue that trend.
enjoy,
Von