Before we had the VCSA (Vcenter Server Appliance) we had a Windows Vcenter Server.
We had the PowerCLI installed locally.
There, we could say
Get-VM -Name * | Sort-Object | %{
....
to get a list of all VMs registered in Vcenter.
Now we have the Appliance.
I installed the vMA (management assistant) too.
I registered the vcenter appliance, I am successfully connected to it, but I am unable to simply retrieve a list of VMs like above.
It always wants me to connect to a single ESXi host to perform a listing.
Now to me that seems like a step backward.
How would you do this?
Would you use vMA at all? Maybe use vCLI? Or stick with PowerCLI, but then I would need again to install a Windows machine just to run my scripts.....
I'd use a Windows PC or Server with PowerCLI installed... PowerCLI is where the momentum is with VMware, so the expectation is that you'll have a Windows system available to interface with it.
So while it's possible to install VMware without a Windows dependency, it turns out that Windows is actually a dependency :)
You could also use the vCenter API, depending on what you're planning to do with the list of virtual machines...
Also see: Is it possible to deploy VMware vSphere 5.5 without Windows?
I have no experience with the vma, but I suppose it has the vmware Perl SDK installed for you (according to this post virtually ghetto it should). In it you have lots of utils and I think this one is the one you are looking for:
vidiscovery.pl
If you do not wish to enter the credentials every time, then you need to setup the credendial store first.
[edit] Actually, I just tried it and while it kind of works, it is very slow because it gets all the info about every entity. Not very efficient. So I just wrote a very small script and this is all it takes:
This presupposes that you have a $HOME/.visdkrc file in place with the correct info:
And as you said you have the vma, all the libraries should already be there for you. This script gets me all the vm's (just their names in under 1 second). If you do not have a CA in place and your virtual center has a self signed certificate you should set this envvar first or the Perl lwp library will bomb out when running the script:
There is another solution: you can simply access the vCenter DB directly for this kind of stuff.
For reference, here is a one-liner that can be executed directly on the VCSA using the postgres client:
I'm using head, tail and sed to filter out nasty headers, empty lines and spaces at the beginning of the line respectively. Maybe there is a more elegant and shorter way to do that, but I don't care.
Pros:
Cons: