Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4693
  • Last Modified:

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.
0
gateguard
Asked:
gateguard
  • 9
  • 5
  • 5
1 Solution
 
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
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
0
 
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
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.
0
 
bgoeringCommented:
List all the directories:

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

http://www.vmware.com/support/developer/vcli/vcli41/doc/reference/vifs.html
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gateguardAuthor Commented:
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.





0
 
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
storage name should be the label datastore2 the friendly name.
0
 
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
if you ise --listds -s

what datastore names are returnef.

0
 
gateguardAuthor Commented:
vifs.pl --config esxi.ini --listds -s

Like this?  Because it says my options are invalid.
0
 
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
drop the -s
0
 
gateguardAuthor Commented:
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.

0
 
bgoeringCommented:
Here is a run from my lab box local datastore as a target (ESXi 4.1 U1)

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

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

ARR/
CapModel/
ESAV2057Disk/
ESVA2057/
ISOs/
NTPVM/
Nessus/
RHEL6/
WSUS/
Win2k3Test/
Win2k8R2Test/
Zimbra/
cpuid/
fw/
fw1/
fw2/
homedc1/
vSphere Management Assistant (vM/

C:\Program Files (x86)\VMware\VMware vSphere CLI\bin>
0
 
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
well that is the returned datastore name its expecting
0
 
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
missing the --dir option
0
 
bgoeringCommented:
Also works with

-D

instead of

--dir
0
 
gateguardAuthor Commented:
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"
0
 
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
maybe --config esxi.ini is not correct, or needs a simplier statement
0
 
bgoeringCommented:
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>
0
 
gateguardAuthor Commented:
That worked, exactly as you have it typed, I used the exact same format and it worked.

Thank you, thank you!
-
0
 
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
what if you run

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 9
  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now