VMware Cloud Community
GordonPM
Enthusiast
Enthusiast
Jump to solution

ScsiLun and matched Datastore report?

I'm trying to formulate a report using PowerCLI, which will list all the available LUNs, along with if they are connected to a datastore and if so, which hosts are connected

Desired output would be something like:

CanonicalName : (Always present)

LunUUID            : (Always present)

Datastore          : (Blank if not connected to Datastore)

FreeSpaceGB   : (If connected to a datastore)

CapacityGB       : (Always present)

FilePath             : (File system path e.g /vmfs/volumes/5ddddd67-7cfcf0c8-d747-48ff3772cc60/

ConnectedHosts: (List of connected hosts)

From examples I've seen, it seems that I wil have to match the result of Get-ScsiLun to Get-Datastore to retrieve all the information I need, so I've got this far:

$Clustername = 'AMD'


$ClusterHosts = Get-Cluster $Clustername | Get-VMHost


Write-Host "Retrieving cluster datastore details..." -NoNewline

$DSdetail = Get-Datastore | ForEach-Object {

    $CanonicalName = (Get-View $_).Info.Vmfs.Extent.diskname

    $DSpath =  ([string]$_.ExtensionData.Info.Url).replace("ds://","")

    [pscustomobject]@{

        CanonicalName = $CanonicalName

        Datastore     = $_.Name

        FreeSpaceGB   = $_.FreeSpaceGB

        CapacityGB    = $_.CapacityGB

        FilePath      = $DSpath

    }

    Write-Host "." -NoNewline

}

Write-Host "`r`nDone"

$LunDetail = ForEach($VMHost in $ClusterHosts) {

    Write-Host "Retrieving LUNs from $VMHost"

    $LunsGet-ScsiLun -VmHost $VMHost

    Write-Host "Matching LUNs to Datastores"

    $Luns | ForEach-Object {

        If ($_.CanonicalName -in $DSdetail.CanonicalName) {

            $MatchedDS = $DSdetail | Where-Object CanonicalName -eq $_.CanonicalName

        }


    }

}

However I'm struggling with trying to get my desired output from here, especially getting all the VMHosts into a single field. Can someone point me in the right direction please?

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There are a couple of alternative versions in the Comments that avoid that hyphen

I suspect that the errors on the type originate from the issue with the hyphen.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

You might want to have a look at my LUN Report – Datastore, RDM And Node Visibility post.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

GordonPM
Enthusiast
Enthusiast
Jump to solution

Thanks Luc

I get a bunch of errors around adding the type if I run that script as-is, but I'll see if I can deconstruct it a bit as I dont need the csv formatting stuff.

Reply
0 Kudos
GordonPM
Enthusiast
Enthusiast
Jump to solution

Also worth mentoning, that the output won't work in my environment as we have hyphens in the ESX host names and your last loop splits on a hyphen.....

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

There are a couple of alternative versions in the Comments that avoid that hyphen

I suspect that the errors on the type originate from the issue with the hyphen.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos