Get VMFS Datastores That Were Upgraded From VMFS3 – PowerCLI

I found that I wasn’t taking full advantage of VAAI because some of my VMFS-5 datastores had different block sizes. This was causing some VM deployments to sporadically run long. After some digging I found a few articles on the differences between upgrading a VMFS datastore and building on new. One good article is VMFS5 VMFS-3, What’s the Deal?

Ok, now that I know that upgrading a VMFS datastore has some drawbacks, I want to identify them all so I can rebuild them all new. I could just look for any VMFS-5 datastores with block sizes that aren’t set to 1MB, but that wouldn’t grab everything since VMFS-3 could use 1MB as well. That’s when I stumbled on another great blog about detecting the upgraded datastores by start sector using ESXCLI How to detect VMFS3 and VMFS3 Upgraded Datastores with PowerCLI; Now with more sugar!.

Great post and super simple way to get the NAA ID’s, but it still left me having to do some manual work. I’d have multiple entries for the same datastore and I’d have to coorelate the NAA ID back to a datastore name for my other scripts. I also wanted just VMFS-5 upgraded datastores, so I have a example usage at the bottom which filters out anything not VMFS-5

I did struggle with how to best do this. I couldn’t find an easy way to pull the datastore name from the NAA ID, so I’m just scanning all the datastores on a host looking for a match. That also required me to build a custom object to store the ESXi host name with each NAA ID in order to do this scan later. Not ideal, but it gets me what I wanted.

Function Code:

Get-DatastoresWithStartSector

function Get-DatastoresWithStartSector ($StartSector) {
    
    $customResults = @()
    $datastores = @()
    
    #search through all hosts for datastores with a start sector value of $StartSector
    Get-VMHost | % {
        
        try {
            $esxcli = Get-EsxCli -VMHost $_ -ErrorAction Stop
        
            $foundDevices = $esxcli.storage.core.device.partition.list() | ?{ $_.StartSector -eq $StartSector }
            
            foreach ($device in $foundDevices) {
                $customResults += New-Object PSObject -Property @{
                    NAA = $device.Device
                    VMHost = $_
                }
            }
        }
        catch {
            Write-Host "Get-EsxCli error on host" -ForegroundColor Magenta
            Write-Host "$_" -ForegroundColor Magenta
        }
    }
    
    #remove duplicates from the list gathered above and match the datastore name to device number
    foreach ( $custom in ($customResults | Sort NAA -Unique) ) {
        $datastores += Get-Datastore -VMHost $custom.VMHost | ?{$_.ExtensionData.Info.Vmfs.Extent.diskname -eq $custom.NAA}
    }
    
    return $datastores | Sort Name
}

#EXAMPLE: get all datastores with old start sector that are at VMFS version 5
#Get-DatastoresWithStartSector 128 | ?{$_.ExtensionData.Info.vmfs.MajorVersion -ne 5}

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>