Automation

 View Only
  • 1.  How do I list the content of the Datastore

    Posted Jan 10, 2012 02:17 AM

    Hi,

    New to VM, but have been lurking in the background. :-) I would like to see what is contained on each LUN via PowerCLI without having to go to Vcenter and browse datastore, I want the browse datastore info. via CLI.

    Hope this makes sense.

    Thanks



  • 2.  RE: How do I list the content of the Datastore

    Posted Jan 10, 2012 03:01 AM

    Hello, Dlouw-

    Welcome to the communities.

    Yes, makes sense.  You can use the "vmstore:" PSDrive to navigate- and browse datastores like you would any other filesystem.

    PS C:\> cd vmstore:
    PS vmstore:\> dir

    Name                           Type                 Id
    ----                           ----                 --
    myDataCenter0                  Datacenter           Datacenter-d...
    myDataCenter1                  Datacenter           Datacenter-d...


    PS vmstore:\> dir .\myDataCenter0\

    Name                               FreeSpaceMB      CapacityMB
    ----                               -----------      ----------
    daterstore01                            321978          476672
    ssd01                                    27132          261632


    PS vmstore:\> cd .\myDataCenter0\daterstore01
    PS vmstore:\myDataCenter0\daterstore01> dir

       Datastore path: [daterstore01]

                LastWriteTime            Type       Length Name
                -------------            ----       ------ ----
          9/11/2011   1:13 PM          Folder              win7test
           9/9/2011  10:43 PM          Folder              testtmpl
          9/18/2011  11:45 PM          Folder              blahh0
         11/25/2011   4:00 PM          Folder              win7test2
          12/7/2011   2:56 PM          Folder              testTemplate
    ...

    The last "dir" above listed the VMs' folders on the given datastore.  You could "cd" (alias for Set-Location) into one of the VMs' folders and list its contents as desired.

    This "vmstore:"  PSDrive gets created with the VimDatastore provider when you add the VMware.VimAutomation.Core PSSnapin to your PowerShell session (manually, via your profile, whatever).  Enjoy.



  • 3.  RE: How do I list the content of the Datastore

    Posted Jan 10, 2012 03:10 AM

    Thanks for the very prompt reply, I will try and figure out how to do what you have said... :-)



  • 4.  RE: How do I list the content of the Datastore

    Posted Jan 10, 2012 03:17 AM

    Is this method still applicable if my hosts are on blades and the storage is on LH nodes?



  • 5.  RE: How do I list the content of the Datastore

    Posted Jan 10, 2012 03:41 AM

    Hello, Dlouw-

    Yes, this should be the same, regardless of the hosts' physical hardware and the storage backend.  As long as the datastores are visible in vCenter, you should be able to navigate them in this manner.

    A couple of notes:

    • you need to have already connected to the vCenter server in your PowerShell/PowerCLI session (by using Connect-VIServer <vcenterNameHere>)
    • if it was not obvious, the datacenter and datastore names in my example are of a sample environment -- you should see _your_ datacenter names and _your_ datastore names when you are navigating the vmstore: PSDrive

    How does that do for you?



  • 6.  RE: How do I list the content of the Datastore

    Posted Jan 10, 2012 03:52 AM

    Thanks, I don't see the vmstore directory?? 



  • 7.  RE: How do I list the content of the Datastore
    Best Answer

    Posted Jan 10, 2012 04:19 AM

    Hello-

    Well, "vmstore" is not a directory, but rather a PowerShell drive (a PSDrive).  So, when you cd or Set-Location to "vmstore:", it is similar to setting the location to the D: drive.  You could use "cd d:\" to change to the D: PSDrive.

    To try to shed more light on this, you can use the Get-PSDrive cmdlet to list all of the current PSDrives in your PowerShell session, like:

    PS C:\> Get-PSDrive

    Name           Used (GB)     Free (GB) Provider      Root
    ----           ---------     --------- --------      ----
    Alias                                  Alias
    C                  31.76         31.62 FileSystem    C:\
    cert                                   Certificate   \
    D                 393.04        538.47 FileSystem    D:\
    ...
    Function                               Function
    HKCU                                   Registry      HKEY_CURRENT_USER
    HKLM                                   Registry      HKEY_LOCAL_MACHINE
    Variable                               Variable
    ...
    vmstore                                VimDatastore  \LastConnectedVCenterServer
    vmstores                               VimDatastore  \
    ...

    Examples of the PSDrives in your PowerShell session:  the Windows volumes on your machine ("C:\", "D:\", etc.), Functions and Variables defined in your PowerShell session ("Function:\" and "Variable:\"), the Windows registry on your machine ("HKLM:\" and "HKCU:\" -- HKeyLocalMachine and HKeyCurrentUser), and so on.  To navigate to any of those, you can use Set-Location or the alias "cd".

    So, you should be able to do a "cd vmstore:\" to initially get to the "vmstore" PSDrive.  How does that do?



  • 8.  RE: How do I list the content of the Datastore

    Posted Jan 10, 2012 04:28 AM

    Okay, so you are officially the man!!!! THANKS



  • 9.  RE: How do I list the content of the Datastore

    Posted Jan 10, 2012 04:45 AM

    One last question, how do I send the ouput / results to a txt file?



  • 10.  RE: How do I list the content of the Datastore

    Posted Jan 10, 2012 05:21 AM

    Answered my own question - Thanks for all the help.