VMware Cloud Community
DaddyDee10
Contributor
Contributor

Datastore Cluster & Host Report

Hi,

Having run a PowerCLI script to determine how many datastores are 90% full or more.  I now need to provide the Storage team with a list of Datastore Clusters, containing ESXi hosts and datastores in order for them to provision additional LUNS (it would appear, what they see SAN array side, defers from what is seen vSphere side?)

Could somone kindly provide a ready made script for this? 

The below script only provides cluster details, whereas the requirement is for Datastore Cluster, Host and Datastore details?

foreach ($Cluster in (Get-Cluster)) {

foreach ($VMHost in (Get-VMHost -Location $Cluster)) {

$VMHost | Get-Datastore |

Select-Object -Property @{Name="Cluster";Expression={$Cluster.Name}},

="VMHost";Expression={$VMHost.Name}},

="Datastore";Expression={$_.Name}}

Export-Csv "d:\Scripts\Report1.csv" -NoTypeInformation -UseCulture

Thanks for all your efforts in advance.

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

You mean something like this ?

foreach($dsc in Get-DatastoreCluster){

  foreach($ds in (Get-Datastore -RelatedObject $dsc)){

    Get-VMHost -Datastore $ds |

    Select -Property @{N='VMHost';E={$_.Name}},

      @{N='DatastoreCluster';E={$dsc.Name}},

      @{N='Datastore';E={$ds.Name}}

  }

}


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

Reply
0 Kudos
DaddyDee10
Contributor
Contributor

Cheers for that LucD.  Smiley Happy

I've added the below as attached.

It would appear that the Export-Csv command was not recognised as the following 'Input-Object' message appeared at the end.

Any ideas why?

Thanks in advance.

PowerGUI Screenshot.JPG

Reply
0 Kudos
LucD
Leadership
Leadership

The ForEach statement doesn't place anything on the pipeline.

You can bypass that by using the Call operator (&).

Something like this

&{foreach($dsc in Get-DatastoreCluster){

  foreach($ds in (Get-Datastore -RelatedObject $dsc)){

    Get-VMHost -Datastore $ds |

    Select -Property @{N='VMHost';E={$_.Name}},

      @{N='DatastoreCluster';E={$dsc.Name}},

      @{N='Datastore';E={$ds.Name}}

  }

}} | Export-Csv "d:\Scripts\Report1.csv" -NoTypeInformation -UseCulture


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

Reply
0 Kudos
DaddyDee10
Contributor
Contributor

LucD, you're the dogs bollocks!!  Smiley Wink.. Many thanks.  That did the trick!!

Reply
0 Kudos