Question: 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.....

Answer: 
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](http://www.virtuallyghetto.com/2010/05/getting-started-with-vsphere-sdk-for.html) it should). In it you have lots of utils and I think this one is the one you are looking for: 

[vidiscovery.pl](https://www.vmware.com/support/developer/viperltoolkit/doc/utilityappsdoc/vidiscovery.html)

If you do not wish to enter the credentials every time, then you need to setup the [credendial store](http://developercenter.vmware.com/web/dp/doc/preview?id=157#https%3A%2F%2Fvdc-repo.vmware.com%2Fvmwb-repository%2Fdcr%2F55a8bd37-3cb5-47bf-b523-cdc55a9d29c6%2F0a25a243-2c31-4093-b351-ae2065dc490f%2Fdoc%2Fviperl_credentialstore.8.1.html) 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:

```perl
#!/usr/bin/perl

use strict;
use warnings;

use VMware::VIRuntime;

# read/validate options and connect to the server
Opts::parse();
Opts::validate();
Util::connect();

my $vm_views =
  Vim::find_entity_views(view_type => 'VirtualMachine',
                       properties => ['name'], );

foreach  my $view ( sort @$vm_views) {      
  print $view->{'name'}, "\n";
}

# disconnect from the server
Util::disconnect();                                  

```

This presupposes that you have a $HOME/.visdkrc file in place with the correct info:

```
VI_PROTOCOL=https
VI_SERVER=fqdn
VI_SERVICEPATH=/sdk
VI_USERNAME=username
VI_PASSWORD=pwd

```

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:

```
export PERL_LWP_SSL_VERIFY_HOSTNAME=0

```
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:

> 
> /opt/vmware/vpostgres/1.0/bin/psql --pset pager=off --pset footer=off
>  --command 'SELECT name FROM vpx\_vm\_config\_info ORDER BY name;' -U vc VCDB | tail -n +3 | head -n -1 | sed 's/^[ ]\*//g'
> 
> 
> 

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:

* No extra VM (vMA) necessary to obtain a list of VMs.
* Fast.

Cons: 

* Somewhat hacky.
* And probably very unsupported.