Skip to content

Get-DatastoreCluster

VMware: Retrieves names of the available datastore clusters

#Requires -Version 5.1
#Requires -Modules VMware.VimAutomation.Core
[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$VIServer,
    [Parameter(Mandatory = $true)]
    [pscredential]$VICredential
)
Process {
    $vmServer = $null
    try {
        $vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
        $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        $result = Get-VMHost -Server $vmServer -ErrorAction Stop | Sort-Object Name
        foreach ($item in $result) {
            [PSCustomObject]@{
                Timestamp    = $timestamp
                Value        = $item.Id
                DisplayValue = $item.Name
            }
        }
    }
    catch { throw }
    finally { if ($null -ne $vmServer) { Disconnect-VIServer -Server $vmServer -Force -Confirm:$false -ErrorAction SilentlyContinue } }
}

IP address or DNS name of the vSphere server

PSCredential object for authenticating with the server

An interactive directory of PowerShell scripts.