VMware Cloud Community
lexajum
Contributor
Contributor
Jump to solution

Get only main folders

Hello

As you know most of the vcenter folder structures are nested.

I only want to get main folders in vcenter.(I have only one datacenter)

As far as i know there is recurse feature in Powershell . If you write -depth and its degree, it only gives you the specific directory that is given the depth by you.

Similarly how can we indicate depth in powercli especially to get only main folders?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do

 

Get-Datacenter | Get-Folder -Name vm | Get-Folder -NoRecursion
    

 


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Euh, Get-Folder with the NoRecursion switch?


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

0 Kudos
lexajum
Contributor
Contributor
Jump to solution

Hi Mr. Luc

When i write "Get-Folder -NoRecursion"  it only gives one folder which it's type datacenter. Is is root folder.

At the attachment you will see there are 16 folders inside "xxx Datacenter"

I want to get only these 16 folders.

 

mr.luc.png

0 Kudos
a_p_
Leadership
Leadership
Jump to solution

I currently don't have access to a system, but after reading the documentation, I'd try s.th. like:

Get-Folder -Location (Get-Folder -NoRecursion)

André

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do

 

Get-Datacenter | Get-Folder -Name vm | Get-Folder -NoRecursion
    

 


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

0 Kudos
lexajum
Contributor
Contributor
Jump to solution

Thank you Mr Luc. It works.

By the way why did we pipe Get-Datacenter and get-folder and get folder again?

 

0 Kudos
lexajum
Contributor
Contributor
Jump to solution

Hello Andre Thanks for your replay. But it gave me the whole folders including child folders

0 Kudos