VMware Cloud Community
MRoushdy
Hot Shot
Hot Shot
Jump to solution

using "foreach"

Hello,

What's the simplest syntax for using "foreach" please?. The goal is to list items of a specific container, like, I have datastores in folders, and I need to list folder names with the mean of each datastore, each in a separate line, for example:

Folder     Datastore Name

####      ##############

folder1     datastore1

folder1     datastore2

folder2     datastore3

etc.,

Thank you,

vEXPERT - VCAP-DCV - Blog: arabitnetwork.com | YouTube: youtube.com/c/MohamedRoushdy
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If I understand the question correctly, you don't even need any form of 'foreach'.

A simple pipeline construct will work.

Something like this for example

Get-Folder -Type Datastore | Get-Datastore |

Select ParentFolder,Name


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

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

If I understand the question correctly, you don't even need any form of 'foreach'.

A simple pipeline construct will work.

Something like this for example

Get-Folder -Type Datastore | Get-Datastore |

Select ParentFolder,Name


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

Reply
0 Kudos
MRoushdy
Hot Shot
Hot Shot
Jump to solution

That did the trick, but I wanted also to seize the opportunity to learn about "foreach" with PowerCLi.

Thanks,

vEXPERT - VCAP-DCV - Blog: arabitnetwork.com | YouTube: youtube.com/c/MohamedRoushdy
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you want a foreach, you could do like this

Get-Folder -Type Datastore | ForEach-Object -Process {

    Get-Datastore -Location $_ |

    Select ParentFolder,Name

}


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

Reply
0 Kudos