PowerCLI

 View Only
Expand all | Collapse all

How do I get all VMs for a VIserver

  • 1.  How do I get all VMs for a VIserver

    Posted Jul 20, 2017 03:21 AM

    Hi,

    I import module vmware.powercli, then issue a Connect-VIServer -server MyVMVIServer.acme.com and after I enter my creds, im connected on port 443.

    I can issue a Get-VM myvmbox -Server MyVMVIServer.acme.com -Location somedatacenter and I get info about myvmbox, however is there a way to just give me all the VMs and their properties under a VIServer such as MYVMVIServer the way I can do with Powershell using a filter like 'Get-AdDomainController -Filter *' which will give me everything.

    This is a new install of VMWare with NSX which im not really familiar with, so wondering how I can get all VMs returned.

    Thanks in advance.



  • 2.  RE: How do I get all VMs for a VIserver

    Posted Jul 20, 2017 04:23 AM

    Hi,

    If you are only connected to one vCenter/VIServer you can just use Get-VM which will return all machines if no parameters are specified; the cmdlet supports accepts a -Name argument which you can also use for filtering and accepts wildcards;

    Eg. Get-VM -Name My*

    Will return all VMs with the name that starts with My

    For usage of the cmdlet please refer: Get-VM - PowerCLI System.Collections.Hashtable.ModuleName Help Reference

    Hope this helps,

    Adrian



  • 3.  RE: How do I get all VMs for a VIserver

    Posted Jul 20, 2017 04:49 AM

    The Get-VM cmdlet doesn't have a Filter parameter, but with the Name parameter you do filtering.

    A few examples (and there others in the Examples of the cmdlet's Help).

    # Use the * as a placeholder for any number of characters

    Get-VM -Name MyVM*

    Get-VM -Name *1

    # Use the ? as a placeholder for one character

    Get-VM -Name MyVM?

    Get-VM -Name My?M

    With the Get-View cmdlet you do have a Filter parameter which accepts RegEx expressions, but be aware that this cmdlet returns vSphere objects, where Get-VM returns .Net objects.

    The difference between these two is another subject.

    Get-View -ViewType VirtualMachine -Filter @{'Name'="\w1$"}



  • 4.  RE: How do I get all VMs for a VIserver

    Posted Jul 20, 2017 11:59 AM

    Thanks for the responses.

    I performed the following after a reboot:

    1. Import-module Vmware.PowerCLI....I see the right messages

    2. Connect-VIServer -Server MyVIServer.com......enter credentials and I see a connection to Port 443 is made

    3. Get-VM -Name N*

    I get no results even though we have at least 50 machines I can see in the console beginning with N*.

    Any suggestions?



  • 5.  RE: How do I get all VMs for a VIserver

    Posted Jul 20, 2017 12:23 PM

    First check if the connection is actually there, display the content of $global:defaultviservers.

    Is the intended vCenter in the list?

    Check if any VMs are returned, just do a Get-VM without any parameter.



  • 6.  RE: How do I get all VMs for a VIserver

    Posted Jul 20, 2017 01:07 PM

    Thanks for the response.

    $global:defaultviservers lists out the connection fine, however a Get-VM lists nothing.

    If I execute 'Get-VM MyVM -Server MyVMServer -Location therightlocale', what returns is the Name, PowerState, Num CPUs, MemoryGB properties.

    So Im stumped here!



  • 7.  RE: How do I get all VMs for a VIserver

    Posted Jul 20, 2017 01:35 PM

    Does the account you used to connect have the required permissions to view all locations and VMs.

    Could you show a screenshot of the last Get-VM you mentioned?



  • 8.  RE: How do I get all VMs for a VIserver

    Posted Jul 20, 2017 02:44 PM

    but when a do a Get-VM, either with or without the Server specified, I get no output.



  • 9.  RE: How do I get all VMs for a VIserver

    Posted Jul 20, 2017 02:58 PM

    What type of object did you pass on the Location parameter?

    Is that a Folder, a Cluster...

    You might be missing some permissions on parts of the vSphere infrastructure (at least with the account you used for the Connect-VIServer).

    Could be that you are only allowed to "see" VMs in a specific Folder, Cluster...



  • 10.  RE: How do I get all VMs for a VIserver
    Best Answer

    Posted Jul 20, 2017 03:05 PM

    That location is a DataCenter.

    Im thinking it may be permissions related.  Let me go to the folks who set this up and ask the question.  I will post what they say.



  • 11.  RE: How do I get all VMs for a VIserver

    Posted Jul 21, 2017 10:14 PM

    It was a permission issue.   Once I found the right person, permissions were tweaked and now I can see all VMs.

    Thanks for responding