Close Menu
PowerShell.roPowerShell.ro
  • Home
  • Automation
  • Powershell
  • VMWare
  • Windows
LinkedIn X (Twitter) Facebook
PowerShell.roPowerShell.ro
  • Home
  • Automation
  • Powershell
  • VMWare
  • Windows
LinkedIn Facebook X (Twitter)
PowerShell.roPowerShell.ro
Home»Automation»PowerCLI: Get Storage Paths of ESXi servers from vCenter
Automation

PowerCLI: Get Storage Paths of ESXi servers from vCenter

Catalin CristescuBy Catalin CristescuJuly 18, 2023
Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
Share
Facebook Twitter LinkedIn Pinterest Email

I needed to make an automated script to get all the Storage paths for all ESXi servers. To be noted that the script will retrieve only the ESXis with VMFS datastores and collect the information.

Script

# Retrieve vCenter, ESXi, cluster, and datastore information
$vcu = ""

Connect-VIServer -Server $vcu

$vCenterInfo = $vcu
$esxiHosts = Get-VMHost | Where-Object {
    $datasto = $_ | Get-Datastore
    $datasto | ForEach-Object { $_.ExtensionData.Summary.Type -ne "NFS" }
}
$clusters = Get-Cluster
$datastores = Get-Datastore

$results = @()

foreach ($esxiHost in $esxiHosts) {

    $hbaInfo = Get-VMHostHba -VMHost $esxiHost
    
    foreach ($hba in $hbaInfo) {

        $paths = Get-ScsiLun -Hba $hba

        foreach ($path in $paths) {
           
            $VMHostScsiLunPaths = $path | Get-ScsiLunPath

            
            foreach ($scsiPath in $VMHostScsiLunPaths) {
                $datastore = $datastores | ? {$_.ExtensionData.Info.Vmfs.Extent[0].DiskName -eq $path.canonicalName}

                $property = [ordered]@{
                    "vCenter" = $vCenterInfo
                    "ESXi" = $esxiHost.Name
                    "Cluster" = $esxiHost.Parent.Name
                    "Datastore" = $datastore.Name
                    "DatastoreType" = $datastore.ExtensionData.Summary.Type
                    "CanonicalName" = $path.CanonicalName
                    "PathPolicy" = $path.Multipathpolicy
                    "LUN" = (($path.RunTimeName -Split "L")[1] -as [Int])
                    "HBA" = $hba.Device
                    "Source" = "{0}" -f ((("{0:x}" -f $hba.PortWorldWideName) -split '([a-f0-9]{2})' | where {$_}) -Join ":")
                    "HBAname" = $path.RunTimeName
                    "Status" = $scsiPath.State
                    "Target" = $scsiPath.SanID
                    "Path" = $scsiPath.Name
                    "PathState" = $scsiPath.ExtensionData.PathState
                }

                # Add the object to the results array
                $results += New-Object -TypeName psobject -Property $property
            }
        }
    }
}
$results | Export-Csv -Path "C:\temp\output.csv" -NoTypeInformation

Disconnect-VIServer -Server $vcu -Confirm:$false
nfs paths powercli powershell storage vmfs
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleRemove Snapshots script
Next Article Check the NTP Server on all ESXi Hosts via Powershell
Catalin Cristescu
  • Website

Related Posts

Automation

PowerShell script for automated remediation for CrowdStrike issue

July 20, 2024
VMWare

vExperts stats 2024

May 27, 2024
Automation

Tagging Virtual Machines with the CISTag Module in PowerShell

February 1, 2024

Comments are closed.

Recent Posts
  • PowerShell script for automated remediation for CrowdStrike issue
  • vExperts stats 2024
  • Tagging Virtual Machines with the CISTag Module in PowerShell
  • Update HPE ILO firmware using PowerShell
  • PowerCLI script to check Cluster Overcommitment ratio
Categories
  • Automation (11)
  • Powershell (14)
  • Uncategorized (1)
  • VMWare (15)
  • Windows (2)
About Powershell.ro

Powershell.ro, the ultimate hub for tech enthusiasts! Dive into expert-written articles on PowerShell scripts, VMware, automation, Microsoft technologies, and DevOps practices. Unlock tips, tutorials, and solutions designed to empower IT professionals and boost your skills in automation and infrastructure management.

Recent Posts
  • PowerShell script for automated remediation for CrowdStrike issue
  • vExperts stats 2024
  • Tagging Virtual Machines with the CISTag Module in PowerShell
  • Update HPE ILO firmware using PowerShell
  • PowerCLI script to check Cluster Overcommitment ratio
LinkedIn
© 2025 PowerShell.ro.

Type above and press Enter to search. Press Esc to cancel.