none
Hyper-V servers

    Question

  • Hi,

    Is there a way to list all hyper-v servers (physical machines which are running hyper-v) from powershell? There is a way when all servers have at least one VM but what to do with does that do not have any?

    Thanks.


    Monday, July 22, 2013 1:36 PM

All replies

  • Not sure what you are asking, I would google that, I think I have seen a script or two related to powershell and finding hyper-v servers.  I found this and blogged on it as to how to find your hyper-v servers on your network

    http://stephanco.blogspot.com/2013/01/how-to-find-hyper-v-servers-on-your.html

    to find a list of the mv's running on that vhost server at the console you can use this powershell script i wrote

    reporting.codeplex.com

    Hope this helps


    James_Stephan@yahoo.com visit my blog stephanco.blogspot.com

    Monday, July 22, 2013 1:51 PM
  • There is no problem to find VMs on hyper-v host. What i want to do is to see which computers on my network are hyper-v hosts. Is that possible to do from powershell?
    Monday, July 22, 2013 2:12 PM
  • If you can query the machine, then you can query if it has the Hyper-V Role installed, or you can query if the VMMS is there and running (the virtual machine management service - the manager side of the hypervisor), or you can query if the machine (through WMI) responds to the virtualization namespace.


    Brian Ehlert
    http://ITProctology.blogspot.com
    Learn. Apply. Repeat.
    Disclaimer: Attempting change is of your own free will.

    Monday, July 22, 2013 2:39 PM
    Moderator
  • There is no problem to find VMs on hyper-v host. What i want to do is to see which computers on my network are hyper-v hosts. Is that possible to do from powershell?

    Yes , it is possible .

    I Create a script but there is problem that i say in the End.

    Copy and paste the following script into your Windows PowerShell session.

    function Invoke-WindowsFeatureHyper-V {
        param (
            [parameter(mandatory)]
            [string[]] $ComputerNames
        )
    
        # Deploy the features on multiple computers simultaneously.
        $jobs = @()
        foreach($ComputerName in $ComputerNames) {
            $jobs += Start-Job -Command {
                Get-WindowsFeature hyper-v -ComputerName $using:ComputerName 
            } 
        }
        
        Receive-Job -Job $jobs -Wait | Select-Object Name,Installed 
    }

    Run the function by doing the following.
    Create a variable in which to store the names of your target computers, separated by commas. In the following example, the variable $ServerNames stores the names of target servers HY-ZAHEDI01 and HY-ZAHEDI02. Press Enter.

    # Sample Invocation
    $ServerNames = 'HY-ZAHEDI01' ,'HY-ZAHEDI02'
    Invoke-WindowsFeatureHyper-V -ComputerNames $ServerNames 

    and the out put :

    THE PROBLEM :it doesnt show Server name and i dont know how show server name .

    but this show in order you put server name in $ServerNames .

    Best Regards.


    Whenever you see a helpful reply, click on Alternate Text Vote As Helpful & click on Alternate Text Mark As Answer if a post answers your question.

    LinkedIn:   Facebook:   

    • Proposed as answer by VR38DETTMVP Wednesday, July 24, 2013 7:50 AM
    Monday, July 22, 2013 3:41 PM
  • Put your servers in an array and call them one by one using a loop.

    You are in control of what server you run "Invoke-WindowsFeatureHyper-V against and therefore you already know what Computername is being called.

    The only other way to know is to also have your function return the computer name as well as the filter of the installed features.  But why make a second call (unless your DNS is wrong) to verify information that you already knew.


    Brian Ehlert
    http://ITProctology.blogspot.com
    Learn. Apply. Repeat.
    Disclaimer: Attempting change is of your own free will.

    Monday, July 22, 2013 4:01 PM
    Moderator
  • Put your servers in an array and call them one by one using a loop.

    You are in control of what server you run "Invoke-WindowsFeatureHyper-V against and therefore you already know what Computername is being called.

    The only other way to know is to also have your function return the computer name as well as the filter of the installed features.  But why make a second call (unless your DNS is wrong) to verify information that you already knew.


    Brian Ehlert
    http://ITProctology.blogspot.com
    Learn. Apply. Repeat.
    Disclaimer: Attempting change is of your own free will.

    thanks BrianEh

    but I'm new with Powershell and try to solve and if i can , i put the result here.


    Whenever you see a helpful reply, click on Alternate Text Vote As Helpful & click on Alternate Text Mark As Answer if a post answers your question.

    LinkedIn:   Facebook:   

    Monday, July 22, 2013 4:36 PM
  • You just change the level that the foreach happens and you don't need a function to do your invocation and build an output.

    And change the output you produce.  You also don't need the $jobs

    Just to simplify it down to more of the basics that are required:

    $ServerNames = 'HY-ZAHEDI01' ,'HY-ZAHEDI02'
    
    foreach($ServerName in $ServerNames) {
        $hvFeature = Get-WindowsFeature hyper-v -ComputerName $ServerName 
        if ($hvFeature){
            $ServerName + ", " + $hvFeature
        }
    }


    Brian Ehlert
    http://ITProctology.blogspot.com
    Learn. Apply. Repeat.
    Disclaimer: Attempting change is of your own free will.


    Monday, July 22, 2013 5:08 PM
    Moderator
  • Thanks a lot BrianEh

    Finally i can Create .

    $ComputerName = @('HY-ZAHEDI01', 'HY-ZAHEDI02')
    foreach ($i in $ComputerName)
    {Invoke-Command { Get-WindowsFeature hyper-v } –computername $i | Select-Object PSComputerName , Installed
    }

    Whenever you see a helpful reply, click on Alternate Text Vote As Helpful & click on Alternate Text Mark As Answer if a post answers your question.

    LinkedIn:   Facebook:   

    Monday, July 22, 2013 5:21 PM
  • Still my question is partially answered. In your script there is the list of servers, but what i need is to generate that list dinamicly by quering all computers in network that have Hyper-V role instaled. Is that possible in any way?
    Tuesday, July 23, 2013 6:38 AM
  • I also want to do something similar, time ago.

    And found this:

    http://www.hyper-v.nu/archives/hvredevoort/2011/10/collecting-data-from-hyper-v-hosts-and-vms/#more-2341

    This is a WMI srcipt that queries WMI name spaces and when it finds the Hyper-V role, collect some info.

    But first, you need to save in the same directory as the VBScript, a file with the name “machinelist.txt”, that will be used by the script.

    If you want to run in your LAN, just fill up “machinelist.txt” with the IP addresses for the range that you are using and lets see what happens.

    Post the results, please.


    • Edited by AlexitoRG Wednesday, July 24, 2013 12:35 AM Corrected sintaxis
    Wednesday, July 24, 2013 12:34 AM
  • Thanks for taking time to answer. I managed to do same thing that script is doing but that is not the solution. I want to be able to find all host just by queryng the domain. Script solution is asking IP info. But, i managed to get my host from network thought VMM cmdlets. I'm not done yet so i will post solution when all is up and running. 
    Wednesday, July 24, 2013 6:01 AM
  • Hi,

    I would like to check if there is any update.

    Thanks.


    Best Regards
    Jeremy Wu

    Tuesday, July 30, 2013 8:17 AM
    Moderator
  • Hi, 

    Work is still in progress. I have something else to finish but i can tell you that through VMM cmdlets you can find all hosts in system. Also you can use VMM cmdlets for much more. You can see command list on: http://technet.microsoft.com/en-us/library/hh801697.aspx

    Only problem is VMM server on which you need to connect. It can be single point of failure if you not make it highly available.

    Tuesday, July 30, 2013 9:06 AM