Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
This also may be relevent: blogs.technet.com/b/jeevanbisht/archive/2012/02/12/… –  Greg Bray Jan 29 at 2:00

3 Answers 3

I would bet you are using two different Hyper-V PowerShell modules:

NAME
  Get-VMHost

SYNOPSIS
  Lists Hyper-V servers registered with Active Directory.

this is the Get-VMhost cmdlet from pshyperv.codeplex.com, it list multiple Hyper-V hosts, in your case 3

NAME
  Get-VMHost

SYNOPSIS
 Gets a Hyper-V host.

This is the Get-VMhost cmdlet that comes with Hyper-V 3 on Server 2012+, it simply lists information about one specific host, it never lists multiple hosts.

If both modules are loaded, it seems ISE picks a different preference over PoweShell with these modules.

If you have the built-on cmdlets in 2012 I would not use the third-party cmdlets, it is just confusing, it certainly confused you.

What's the value of your $env:psmodulepath ?

share|improve this answer
    
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 –  slybloty Jan 29 at 21:32
    
@slybloty - So do you have the codeplex HyperV module installed? If not, it seems System Center also brings some Hyper-V related modules. Compare the command Get-Module | select Name,Path in PowerShell and ise, it lists all loaded modules and you should look for any Hyper-V related modules. You can use Remove-Module to unload a module from the current session to avoid the conflict in cmdlet names. –  Peter Hahndorf Jan 29 at 21:59
    
I have updated the question with information about the Hyper-V modules used. –  slybloty Jun 1 at 21:03

It looks like Peter is on the right track. Have you tried:

  1. Removing the Microsoft.HyperV.PowerShell.dll module from PS console with Remove-Module cmdlet
  2. Import the module referenced in PowerGUI?

Use this command to verify the command is being used from the correct module.

Get-Module (get-command Get-VMHost).ModuleName | select Name, Path

Alternatively use the fully qualified name after verifying the module in imported.

Hyper-V\Get-VMHost "hyperv01svr"
share|improve this answer
    
I have awarded the bounty to this answer because it led me to the best way (as of now) to address this issue I have. I still don't know what causes the discrepancy between the 2 platforms and how to eliminate it, but at least I am blocked by it. –  slybloty Jun 4 at 20:10

The Host has the ability to set a default formatting for different types, which will be used when you call the select-object cmdlet and send the results to out-default. It may also be that in this case the cmdlet is changing the output based on the value of $host.name.

If you want the same output you can try passing it through format-list or format-table instead of select. In some cases you may also need to pass it to out-string to "lock" the output, as some hosts do not support the format cmdlets (especially when run as a script or in non-interactive mode).

If you really want to inspect the output it would be best to save it to a variable using ... | Set-Variable testing or $testing = ... and then use $testing | Get-Member to see if the same object was returned. In some cases you may need to add the -Force flag to include the PSObject ATS and ETS methods that are used to wrap the base type.

Examples:

Get-VMHost | ft Name | Out-String
Get-VM | Set-Variable VMs
$VMs | Select -First 1 | Get-Member
$VMs | Select -First 1 | GM -Force

I don't have access to a HyperV server for testing, but the above is what I usually use to test odd behavior between different hosts.

share|improve this answer
    
My problem is not output formatting. It's the fact that I get different information from the different places. Check the number of hosts and the number and names of the VMs. Completely different. That's the problem I want fix. –  slybloty Jan 29 at 15:34
    
    
That blog does not address the reason why there are 2 different lists of VMs and the fact that I don't know which is accurate and how to retrieve the correct one. –  slybloty Jan 29 at 19:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.