Created
July 17, 2020 20:26
-
-
Save vScripter/5752d7350bcee2a7d2ea63bba843de0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-RDM { | |
[OutputType([System.Management.Automation.PSCustomObject])] | |
[cmdletbinding(DefaultParameterSetName = 'default')] | |
param ( | |
[parameter( | |
Mandatory = $true, | |
ValueFromPipeline = $true, | |
Position = 0, | |
ParameterSetName = 'default')] | |
[alias('VM')] | |
[VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine[]] | |
$Name | |
) | |
BEGIN { | |
Write-Verbose -Message "[$($PSCmdlet.MyInvocation.MyCommand.Name)] Processing Started" | |
} # end BEGIN | |
PROCESS { | |
foreach ($guest in $Name) { | |
Write-Verbose -Message "[$($PSCmdlet.MyInvocation.MyCommand.Name)] Working on VM {$($guest.Name)}" | |
$rdmTest = $null | |
$rdmTest = Get-HardDisk -VM $guest -DiskType 'RawPhysical','RawVirtual' | |
$esxcli = $null | |
$esxcli = Get-VMHost -VM $guest | Get-EsxCli -V2 | |
if ($rdmTest -and $esxcli) { | |
try { | |
ForEach ($rdm in $rdmTest) { | |
Write-Verbose -Message "[$($PSCmdlet.MyInvocation.MyCommand.Name)] Working on SCSi Device {$($rdm.ScsiCanonicalName)}" | |
$esxcliStorage = $null | |
$esxcliStorage = $esxcli.storage.core.device.list.invoke() | Where-Object { $psitem.Device -eq $rdm.ScsiCanonicalName } | |
[PSCustomObject]@{ | |
VM = $rdm.Parent.toString() | |
DiskType = $rdm.DiskType | |
FileName = $rdm.FileName | |
DiskName = $rdm.Name | |
ID = $rdm.Id | |
ParentID = $rdm.ParentID | |
ScsiCanonicalName = $rdm.ScsiCanonicalName | |
CompatibilityMode = $rdm.ExtensionData.Backing.CompatibilityMode | |
DisplayName = $esxcliStorage.DisplayName | |
IsPerenniallyReserved = $esxcliStorage.IsPerenniallyReserved | |
IsRDMCapable = $esxcliStorage.IsRDMCapable | |
IsSharedClusterwide = $esxcliStorage.IsSharedClusterwide | |
Model = $esxcliStorage.Model | |
VAAIStatus = $esxcliStorage.VAAIStatus | |
Vendor = $esxcliStorage.Vendor | |
vCenter = ([uri]$guest.ExtensionData.Client.ServiceUrl).Host | |
} # end pscustomobject | |
} # end foreach | |
} catch { | |
Write-Warning -Message "[$($PSCmdlet.MyInvocation.MyCommand.Name)][ERROR] Could not process VM {$($guest.Name)}. $_ " | |
} # end try/catch | |
} else { | |
Write-Verbose -Message "[$($PSCmdlet.MyInvocation.MyCommand.Name)][INFO] No RDM Found for VM {$($guest.Name)}. $_ " | |
} # end if/else $rdmTest | |
}# end foreach $guest | |
} # end PROCESS | |
END { | |
Write-Verbose -Message "[$($PSCmdlet.MyInvocation.MyCommand.Name)] Processing Complete" | |
} # end END | |
} # end function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment