Src/Private/Get-ScsiDeviceDetail.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function Get-ScsiDeviceDetail {
    <#
    .SYNOPSIS
    Helper function to return Scsi device information for a specific host and a specific datastore.
    .PARAMETER VMHosts
    This parameter accepts a list of host objects returned from the Get-VMHost cmdlet
    .PARAMETER VMHostMoRef
    This parameter specifies, by MoRef Id, the specific host of interest from with the $VMHosts array.
    .PARAMETER DatastoreDiskName
    This parameter specifies, by disk name, the specific datastore of interest.
    .EXAMPLE
    $VMHosts = Get-VMHost
    Get-ScsiDeviceDetail -AllVMHosts $VMHosts -VMHostMoRef 'HostSystem-host-131' -DatastoreDiskName 'naa.6005076801810082480000000001d9fe'
    DisplayName : IBM Fibre Channel Disk (naa.6005076801810082480000000001d9fe)
    Ssd : False
    LocalDisk : False
    CanonicalName : naa.6005076801810082480000000001d9fe
    Vendor : IBM
    Model : 2145
    Multipath Policy : Round Robin
    CapacityGB : 512
    .NOTES
    Author: Ryan Kowalewski
    #>


    [CmdLetBinding()]
    param (
        [Parameter(Mandatory = $true)]
        $VMHosts,
        [Parameter(Mandatory = $true)]
        $VMHostMoRef,
        [Parameter(Mandatory = $true)]
        $DatastoreDiskName
    )

    $VMHostObj = $VMHosts | Where-Object { $_.Id -eq $VMHostMoRef }
    $ScsiDisk = $VMHostObj.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object {
        $_.CanonicalName -eq $DatastoreDiskName
    }
    $Multipath = $VMHostObj.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | Where-Object {
        $_.Lun -eq $ScsiDisk.Key
    }
    $CapacityGB = [math]::Round((($ScsiDisk.Capacity.BlockSize * $ScsiDisk.Capacity.Block) / 1024 / 1024 / 1024), 2)

    [PSCustomObject]@{
        'DisplayName' = $ScsiDisk.DisplayName
        'Ssd' = $ScsiDisk.Ssd
        'LocalDisk' = $ScsiDisk.LocalDisk
        'CanonicalName' = $ScsiDisk.CanonicalName
        'Vendor' = $ScsiDisk.Vendor
        'Model' = $ScsiDisk.Model
        'MultipathPolicy' = switch ($Multipath.Policy.Policy) {
            'VMW_PSP_RR' { 'Round Robin' }
            'VMW_PSP_FIXED' { 'Fixed' }
            'VMW_PSP_MRU' { 'Most Recently Used' }
            default { $Multipath.Policy.Policy }
        }
        'Paths' = ($Multipath.Path).Count
        'CapacityGB' = $CapacityGB
    }
}