Link to home
Start Free TrialLog in
Avatar of gateguard
gateguard

asked on

Using vSphere-CLI how can I list the contents of a datastore?

This command:

vmware-cmd.pl --config esxi.ini -l

will list all the registered virtual machines on a server specified in the esxi.ini file.

But it will only list the registered virtual machines.

I would like to list the entire contents (either all folders or all files, I don't care which) on an ESXi 4.1 server, or on one of its datastores.

I know how to list the datastores:

vifs.pl --config esxi.ini -S

But I want to learn how I can list the CONTENTS of each datastore.

Thanks.
Avatar of Andrew Hancock (VMware vExpert PRO / EE Fellow/British Beekeeper)
Andrew Hancock (VMware vExpert PRO / EE Fellow/British Beekeeper)
Flag of United Kingdom of Great Britain and Northern Ireland image

I would recommend using the following, also VMware recommends the use of PowerCLI, which is PowerShell interface with vSphere-specific additions.

http://communities.vmware.com/community/vmtn/server/vsphere/automationtools/powercli

One of the simplest PowerCLI examples, and something which is actually extremely useful on its own, is the Get-VM cmdlet. Which lists VMs.

PowerCLI can be a bit overwhelming to use,  But it can be enhanced with a nice toolset and a library of preconfigured scripts to jump-start your mass changes, which is possible with PowerGUI

http://powergui.org/index.jspa

and

VMware Community Pack

http://www.virtu-al.net/featured-scripts/vmware-powerpack/

It's also worth looking at The free VMware Guest Console

http://labs.vmware.com/flings/vgc
The free VMware Guest Console, an experimental application created by VMware Labs, is a great tool for managing vSphere VM processes and files. You can view, sort and kill processes across all VMs, and you can also run a script on all Windows or Linux VMs.
List all the directories:

 vifs --server <connection_options> -D "[StorageName] vm"

http://www.vmware.com/support/developer/vcli/vcli41/doc/reference/vifs.html
Avatar of gateguard
gateguard

ASKER

hanccocka, I'm going to look at your suggestions in a bit but for now,

bgoering, your answer is EXACTLY what I was looking for EXCEPT I have never been able to successfully run that command.  No matter what value I use for [StorageName] I get some error saying that storage doesn't exist.  And I believe I've tried every available string and their combinations that I gleaned from running the "vifs.pl --configi -S"  and "vicfg-scsidevs.pl  --list"   and    "vicfg-mpath.pl --list"   commands.

Where do I get the [StorageName] from?

It's not:

Device: naa.5000cca369c5d091 (or naa.5000cca369c5d091)

It's not:

datastore2

It's not:

   Console Device: /vmfs/devices/disks/t10.ATA_____WDC_WD2001FASS2D00W2B0________________________WD2DWMAY00861311
   Devfs Path: /vmfs/devices/disks/t10.ATA_____WDC_WD2001FASS2D00W2B0________________________WD2DWMAY00861311

or any combination of any of that stuff.

So yes, "[StorageName] vm"   ... example, please.

Thanks.





storage name should be the label datastore2 the friendly name.
if you ise --listds -s

what datastore names are returnef.

vifs.pl --config esxi.ini --listds -s

Like this?  Because it says my options are invalid.
ok, got it.

here it is from one server:



Content Listing
---------------

datastore2


but when I try to use "datastore2" in place of "StorageName" I get an error...

but I'm going to try that again.

ASKER CERTIFIED SOLUTION
Avatar of bgoering
bgoering
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
well that is the returned datastore name its expecting
Also works with

-D

instead of

--dir
GET https://192.168.111.196/folder/vm?dsName=datastore2 unsuccessful : 404 Not F
ound
Error: Can not list directory '[datastore2] vm'.

using this command:

vifs.pl --config esxi.ini -D "[datastore2] vm"
maybe --config esxi.ini is not correct, or needs a simplier statement
If you want to drill down you can:

C:\Program Files (x86)\VMware\VMware vSphere CLI\bin>vifs.pl --server vsphere1 -D "[datastore1] fw"
Enter username: root
Enter password:

Content Listing
---------------

fw-flat.vmdk
fw.vmdk
fw.vmsd
fw.vmx
fw.vmxf
m0n0wall.nvram
vmware-1.log
vmware.log

C:\Program Files (x86)\VMware\VMware vSphere CLI\bin>
That worked, exactly as you have it typed, I used the exact same format and it worked.

Thank you, thank you!
-
what if you run

vifs.pl --server <esx servername> --dir "[datastore2]"
You are welcome