VMware Cloud Community
MRoushdy
Hot Shot
Hot Shot
Jump to solution

Get-VMhost and the related datastores to it

Hello, I need to list all of my hosts, and the related datastores to each, and also count these datastores per host, but the last part is optional I may do it manually for the sake of making the script simpler now.

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

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-VMHost -PipelineVariable esx |

   ForEach-Object -Process {

   $ds = Get-Datastore -RelatedObject $_

   $ds | Select @{N = 'VMHost'; E = {$esx.Name}},

   @{N = 'TotalDS'; E = {$ds.Count}},

  Name

}


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

View solution in original post

Reply
0 Kudos
3 Replies
MRoushdy
Hot Shot
Hot Shot
Jump to solution

This command dod the trick, but I still need to count if possible please.

get-vmhost | select name, @{N="Datastore"; E={Get-Datastore -VMHost $_}}

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

Try something like this

Get-VMHost -PipelineVariable esx |

   ForEach-Object -Process {

   $ds = Get-Datastore -RelatedObject $_

   $ds | Select @{N = 'VMHost'; E = {$esx.Name}},

   @{N = 'TotalDS'; E = {$ds.Count}},

  Name

}


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

Reply
0 Kudos
MRoushdy
Hot Shot
Hot Shot
Jump to solution

That's what I'm talking about.   Thank you!

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