VMware Cloud Community
vandreytrindade
Enthusiast
Enthusiast
Jump to solution

Get datastore folders with PowerCLI

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?

Att, Vandrey Trindade
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

vandreytrindade
Enthusiast
Enthusiast
Jump to solution

LucD,

Thanks for the fast reply!

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

Error.png

Att, Vandrey Trindade
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vandreytrindade
Enthusiast
Enthusiast
Jump to solution

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!

Att, Vandrey Trindade
Reply
0 Kudos