Virtual Machines List from PowerShell vs PowerShell ISE and PowerGUI
- by slybloty
I am confused to why I have different information based on where I try to retrieve it from. I have 3 Windows 2012 servers (G0, G1, and G2) running Hyper-V. The following situation is captured from one server which I use to run scripts and control the others.
What I'm trying to do is to get a list of the virtual machines in existence on these 3 machines:
Using PowerGUI and PowerShell ISE:
PS > Get-VMHost | select name
Name
----
G0.nothing.com
G2.nothing.com
G1.nothing.com
PS > Get-VMHost | Get-VM | select name
Name
----
VM1628856-4
VM1628856-2
VM1628856-6
VM1628856-3
VM1628856-1
VM1628856-5
Using PowerShell:
PS > Get-VMHost | select name
Name
----
G0
PS > Get-VM
Name State CPUUsage(%) MemoryAssigned(M) Uptime Status
---- ----- ----------- ----------------- ------ ------
VM1107610-1 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1390728-1 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-1 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-10 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-2 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-3 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-4 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-5 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-6 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-7 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-8 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1393540-9 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
VM1833022-1 OffCritical 0 0 00:00:00 Cannot connect to virtual machine configuration storage
My main concern is that I don't have reliable information from the 3 tools. The Hyper-V Manager application shows the same list as the PowerShell does. But if I run my scripts from the other two tools, which is what I mostly do, I don't have the same information available, therefore I can't manipulate the same VMs.
I've also noticed that the Virtual Machine Manager shows the same list of VMs as the first two tools, PowerGUI and PowerShell ISE.
Which information is valid? And how can I retrieve the correct list of VMs?
EDIT 1
The $env:psmodulepath value:
PS > $env:psmodulepath
C:\Users\administrator\Documents\WindowsPowerShell\Modules;
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;
C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\;
C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\bin\Configuration Providers\;
C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\bin\psModules\;
C:\Program Files (x86)\QLogic Corporation\QInstaller\Modules
EDIT 2
PowerShell is using this Hyper-V module:
C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.HyperV.PowerShell\v4.0_6.3.0.0__31bf3856ad364e35\Microsoft.HyperV.PowerShell.dll
And PowerGUI is using this one:
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Hyper-V\Hyper-V.psd1
If I try to load the module used by PowerShell onto PowerGUI I still get the same different results.
How can I receive the correct information listed under Hyper-V using PowerGUI or PowerShell ISE?