PowerCLI checks for vSphere Datastores

Over the last couple of days, I have posted a handful of PowerCLI scripts to check a vSphere environment. These checks have looked at general cluster level reporting, networking and virtual machines. Today I’m posting a couple of checks that look at datastores. I hope you find these checks useful.

In my environment, local disks contain the text boot or local. The following code will return a list of non-shared datastores that do not follow this naming convention. This could indicate local disk that doesn’t follow a standard naming convention.
[cc lang=”powershell”]
Get-View -ViewType Datastore -Property Name, Summary |
?{$_.Summary.MultipleHostAccess -eq $false -And $_.Name -notmatch “boot|local”} |
Select Name, @{N=”Datastore Type”;E={$_.Summary.Type}},
@{N=”Capacity (GB)”;E={[math]::round( $_.Summary.Capacity/1GB , 0)}} |
Sort-Object Name
[/cc]

The following script will return a list of datastores reporting as not accessible. I’ve seen this happen after removing datastores from hosts where array based snapshots had been previously presented. Typically an HBA re-scan will clear up this issue.
[cc lang=”powershell”]
Get-View -ViewType Datastore -Property Name, Summary |
?{$_.Summary.Accessible -eq $false} |
Select-Object name, @{N=”Datastore Type”;E={$_.Summary.Type}},
@{N=”Capacity (GB)”;E={[math]::round( $_.Summary.Capacity/1GB , 0)}} |
Sort-Object Name
[/cc]

I try to keep the VMFS block size and version consistent on all shared storage in my environment. The following code will show VMFS datastores if inconsistent block sizes or VMFS versions are not using the most common configuration detected in the environment.
[cc lang=”powershell”]
$vmfsDs = Get-View -ViewType Datastore -Property Name, Summary, Info, Host |
?{$_.Summary.Type -eq ‘VMFS’ -and $_.Summary.MultipleHostAccess -eq $true} |
Select-Object Name, @{N=”VMFS Version”;E={$_.Info.Vmfs.Version}},
@{N=”Block Size (MB)”;E={$_.Info.Vmfs.BlockSizeMB}},
@{N=”Host Count”;E={@($_.Host).Count}}

if ( ($vmfsDs | Select-Object -Property “Block Size (MB)” -Unique | Measure-Object).Count -gt 1 -or
($vmfsDs | Select-Object -Property “VMFS Version” -Unique | Measure-Object).Count -gt 1) {
$standardVmfsBlockSize = (($vmfsDs | Group-Object -Property “Block Size (MB)”) | Sort-Object Count -Descending | Select-Object -First 1).Name
$standardVmfsVersion = (($vmfsDs | Group-Object -Property “VMFS Version”) | Sort-Object Count -Descending | Select-Object -First 1).Name
$vmfsDs | ?{$_.”Block Size (MB)” -ne $standardVmfsBlockSize -or $_.”VMFS Version” -ne $standardVmfsVersion } |
Sort-Object Name
}
[/cc]

I hope someone else finds these checks useful.

This entry was posted in Scripting, Virtualization. Bookmark the permalink.

Leave a Reply

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

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.