Srinivas_k
Enthusiast
Enthusiast

How to get Datastore belongs to which compute cluster

Hi,

I am trying to figure out how to get Datastore belongs to which compute cluster that fits in below script, please help me on this.

Thank you in advance.

if(-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue))

{

   Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue

}

$Date = Get-Date -Format 'dd_MMM_yyyy hh_mm_ss tt'

$Vcenters = Read-Host "enter vc name with fqdn"

$Output = $Vcenters.Split(".")[0]

Connect-VIServer $Vcenters -ErrorAction SilentlyContinue

Get-Datastore | Select Name,

@{N='DSCapacityGB';E={[math]::Round($_.CapacityGB,2)}},

@{N='DSProvisionedSpaceGB';E={[math]::Round(($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB)}},

@{N='DSFreespaceGB';E={[math]::Round($_.FreespaceGB,2)}},

@{N='DSFreePercent';E={[math]::Round(($_.Extensiondata.Summary.FreeSpace / $_.ExtensionData.Summary.Capacity)*100)}},

@{N='DSNAA';E={$DSNAA = $_ | Get-View;$DSNAA.Info.Vmfs.Extent.diskname }},

@{N='DSType';E={$_.type}} |Export-Csv ".\$Output.$Date.csv" -NoTypeInformation -Append

Disconnect-VIServer -Server * -Force -confirm:$false

0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership

You can add the following line to your script after the line containing the Get-Datastore command to get the cluster a datastore belongs to:

@{N='Cluster';E={($_ | Get-VMHost | Select -ExpandProperty Parent | Sort-Object -Unique).Name}},

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
Srinivas_k
Enthusiast
Enthusiast

Thank you for the help.

But Datastore will be presented to multiple esxi host so how the output would be, i am running the script it is taking long time.

0 Kudos