param ([string]$cluname, [int]$nofile = 0, [int]$html = 0, [int]$onlydead = 1, [int]$onlyvmfs = 0, [int]$onlyfree = 0, [int]$minVMFSsizeGB = 1, [int]$invokehtml = 0, [int]$noconsole = 0) #version 2.3 if ($global:DefaultVIServer.ProductLine -ne "vpx"){Write-Host -ForegroundColor Red "You must be connected to a vCenter to run this script !";break} if ($cluname) { $hosts = Get-View -ViewType ClusterComputeResource -Filter @{"Name" = $cluname } -Property Host|select -ExpandProperty Host|%{get-view $_ -property ConfigManager,runtime,name,parent}|?{$_.Runtime.ConnectionState -eq "Connected" -or $_.Runtime.ConnectionState -eq "Maintenance"} } else { $hosts = Get-View -property ConfigManager,runtime,name,parent -ViewType hostsystem |?{$_.Runtime.ConnectionState -eq "Connected" -or $_.Runtime.ConnectionState -eq "Maintenance"} } if ($cluname) { $datastorelist = Get-View -ViewType ClusterComputeResource -Filter @{"Name" = $cluname} -property datastore|select -ExpandProperty datastore|%{get-view $_ -property info}|?{$_.info.vmfs} } else {$datastorelist = Get-View -ViewType datastore -property info|?{$_.info.vmfs}} $dslist = @() $clusters = Get-View -ViewType ClusterComputeResource -property name foreach ($h in $hosts) { $hss = Get-View $h.ConfigManager.StorageSystem -Property StorageDeviceInfo if ($onlydead -eq "1") { $lunpath = $hss|%{$_.StorageDeviceInfo.multipathinfo.lun}|%{$_.path}|?{$_.State -eq "dead"} } elseif ($onlydead -eq "0") { $lunpath = $hss|%{$_.StorageDeviceInfo.multipathinfo.lun}|%{$_.path} } foreach ($path in $lunpath) { $lun = $hss.StorageDeviceInfo.ScsiLun |?{$path.Lun -match $_.Uuid}|select -First 1 if ($lun) { if ($lun.LunType -match "cdrom") { $luncapa = 0 } else { $luncapa = $lun.capacity.block * $lun.capacity.blocksize if ($luncapa/1GB -lt "1") {$luncapa = "$([math]::Round($luncapa/1MB,0))" + " MB"} elseif ($luncapa/1GB -lt "1000") {$luncapa = "$([math]::Round($luncapa/1GB,0))" + " GB"} elseif ($luncapa/1GB -ge "1000") {$luncapa = "$([math]::Round($luncapa/1TB,0))" + " TB"} } $plug = $hss.StorageDeviceInfo.PlugStoreTopology.Path|?{$_.name -match $path.name} if ($plug) { $PSTadapter = $hss.StorageDeviceInfo.PlugStoreTopology.Adapter|?{$_.Key -eq $plug.Adapter} $adapter = $hss.StorageDeviceInfo.HostBusAdapter|?{$_.Key -eq $PSTadapter.adapter} $runtime = $adapter.Device + ":C" + $($plug.ChannelNumber) + ":T" + $($plug.TargetNumber) + ":L" + $($plug.LunNumber) } if ($h.Parent.Type -eq "ClusterComputeResource") { $ParentCluster = ($clusters|?{$_.moref.value -eq $h.Parent.Value}).name } else { $ParentCluster = "" } } if ($adapter -is [VMware.Vim.HostFibreChannelHba] -or $adapter -is [VMware.Vim.HostInternetScsiHba] -or $adapter -is [VMware.Vim.HostBlockHba]) { if ($lun.LunType -match "cdrom") { $dsname = "";$dsuuid = "cdrom" } else { foreach ($ds in $datastorelist) { foreach ($dsext in $ds.info.vmfs.extent) { if ($dsext.diskname -match $lun.CanonicalName) { $dsname = $ds.info.vmfs.name $dsuuid = $ds.info.vmfs.uuid } } } } if (($lun.capacity.block * $lun.capacity.blocksize / 1GB) -ge $minVMFSsizeGB) { $extinfo = "" | select ClusterName, ESX, CanonicalName, Runtime, State, IsWorkingPath, LunSize, Datastore, UUID, LunType, Vendor, Model, Revision, opState $extinfo.ClusterName = $ParentCluster $extinfo.ESX = $h.name $extinfo.CanonicalName = $lun.CanonicalName $extinfo.Runtime = $runtime $extinfo.State = $path.State $extinfo.IsWorkingPath = $path.IsWorkingPath $extinfo.LunSize = $luncapa $extinfo.Datastore = $dsname $extinfo.UUID = $dsuuid $extinfo.LunType = $lun.LunType $extinfo.Vendor = $lun.Vendor $extinfo.Model = $lun.Model $extinfo.Revision = $lun.Revision $extinfo.opState = [string]$lun.operationalState $dslist += $extinfo } Remove-Variable lun,plug,adapter,dsname,dsuuid,runtime,luncapa,ParentCluster -ErrorAction SilentlyContinue -WarningAction SilentlyContinue } } } if ($onlyfree -eq "1"){$dslist = $dslist|?{!$_.UUID -or !$_.Datastore}} if ($onlyvmfs -eq "1"){$dslist = $dslist|?{$_.Datastore}} if (!$noconsole){$dslist |sort ClusterName,ESX,CanonicalName,Runtime| ft} if ($nofile -eq "0" -and $html -eq "0"){$dslist |sort ClusterName,ESX,CanonicalName,Runtime| ConvertTo-Csv -NoTypeInformation -Delimiter ";"|%{$_.Replace('"','')}|out-file -encoding ASCII -filepath ./dslist.csv} if ($nofile -eq "0" -and $html -eq "1") { $css = '' $dslist|sort ClusterName,ESX,CanonicalName,Runtime|ConvertTo-Html -head $css -Title "scsi path list"|out-file -encoding ASCII -filepath ./dslist.html } if ($invokehtml){Invoke-Item ./dslist.html}