Automation

 View Only
  • 1.  How to get Datastore belongs to which compute cluster

    Posted Mar 31, 2017 05:19 AM

    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



  • 2.  RE: How to get Datastore belongs to which compute cluster

    Posted Mar 31, 2017 06:01 AM

    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}},



  • 3.  RE: How to get Datastore belongs to which compute cluster

    Posted Mar 31, 2017 07:17 AM

    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.