PowerCLI

 View Only
  • 1.  Get datastore folders with PowerCLI

    Posted Sep 19, 2016 12:28 PM

    Hi,

    I'm trying to search all the folders that exists on different datastores in my organization using PowerCLI.

    The thing is that I found some commands to get the VMs folders.

    But what about folders that are non VM related or VMs that are not in the inventory?



  • 2.  RE: Get datastore folders with PowerCLI
    Best Answer

    Posted Sep 19, 2016 12:33 PM

    You can use the VimDatastore provider.

    Something like

    $ds = Get-Datastore -Name MyDS

    New-PSDrive -Name TgtDS -Location $ds -PSProvider VimDatastore -Root '\' | Out-Null

    Get-ChildItem -Path TgtDS: -Recurse

    Remove-PSDrive -Name TgtDS



  • 3.  RE: Get datastore folders with PowerCLI

    Posted Sep 19, 2016 12:54 PM

    LucD,

    Thanks for the fast reply!

    It worked for local datastores, tried on a storage datastore and it shown me this error:



  • 4.  RE: Get datastore folders with PowerCLI

    Posted Sep 19, 2016 01:02 PM

    You have multiple datastores with the same name?

    That means $ds is an array of datastore objects.

    Try picking one of the entries for the New-PSDrive cmdlet



  • 5.  RE: Get datastore folders with PowerCLI

    Posted Sep 19, 2016 01:03 PM

    LucD,

    No, I have the same datastore linked on multiple servers.

    Tried with this one "$ds = Get-Datastore -Name VMDATA01 | select -First 1" and worked!

    Thanks!