Skip to content

Instantly share code, notes, and snippets.

@fsackur
Last active November 10, 2023 03:27
Show Gist options
  • Save fsackur/afb34f3f93310fea2f60393abae8da98 to your computer and use it in GitHub Desktop.
Save fsackur/afb34f3f93310fea2f60393abae8da98 to your computer and use it in GitHub Desktop.
<#
.Synopsis
Provides a mapping of Windows drive letters to WWNs using inq.exe from EMC
.Description
Gets all volumes in Windows and provides device ID, drive letter and WWN.
You must have inq.exe available.
.Parameter Path
Path to inq.exe (defaults to the current directory)
.Example
C:\PS> Get-InqWwn
DriveLetter DeviceID WWN Product
----------- -------- --- -------
C \\.\PHYSICALDRIVE0 N/A Virtual disk
S \\.\PHYSICALDRIVE1 60000970000295700488533032313832 SYMMETRIX
\\.\PHYSICALDRIVE2 60000970000295700488533032423536 SYMMETRIX
T \\.\PHYSICALDRIVE3 60000970000295700488533034393635 SYMMETRIX
.Author
Freddie Sackur
.Notes
An obvious prerequisite is that you have already downloaded inq.exe.
Usage is subject to the MIT license, viewable at https://opensource.org/licenses/MIT. No warranty
is provided. Copyright © 2017 Freddie Sackur
.Link
https://freddiesackur.wordpress.com/2017/10/08/wrapping-external-utilities-using-emcs-inq-exe-as-an-example/
.Link
ftp://ftp.emc.com/pub/symm3000/inquiry/
.Link
https://community.emc.com/thread/116665?start=0&tstart=0
#>
function Get-InqWwn {
[CmdletBinding(DefaultParameterSetName='WWN')]
[OutputType([psobject[]])]
param(
[Parameter()]
[string]$Path = '.\inq.exe'
)
try {
if (-not (Test-Path $Path -PathType Leaf -ErrorAction Stop)) {
$InqPath = Join-Path $Path 'inq.exe'
} else {
$InqPath = $Path
}
$InqPath = (Resolve-Path $InqPath -ErrorAction Stop).Path
} catch [System.Management.Automation.ItemNotFoundException] {
throw New-Object System.Management.Automation.ItemNotFoundException ("Please provide the path to inq.exe")
}
$Output = New-Object 'System.Collections.Generic.List[psobject]'
$WWNs = Invoke-Inq -WWN -Path $Path
$WinVols = Invoke-Inq -WinVol -Path $Path
foreach ($Disk in $WWNs) {
$WinVol = $WinVols | ?{$_.DEVICE -eq $Disk.DEVICE}
if ($WinVol) {
Add-Member -InputObject $WinVol -MemberType NoteProperty -Name 'WWN' -Value (
$Disk.WWN
)
$Output.Add($WinVol)
} else {
$Output.Add($Disk)
}
}
$Output | select (
@{Name = 'DriveLetter'; Expression = {$_.'WIN vol'}},
@{Name = 'DeviceID'; Expression = {$_.DEVICE}},
'WWN',
@{Name = 'Product'; Expression = {$_.PROD}}
)
}
<#
.Synopsis
Pull information about attached LUNs using inq.exe from EMC
.Description
Allows use of -WWN and -WinVol switches to retrieve device from within an OS to ensure that
OS Support and Storage or Virtualisation teasm are talking about the same disk before making
changes
.Author
Freddie Sackur
.Notes
An obvious prerequisite is that you have already downloaded inq.exe.
Usage is subject to the MIT license, viewable at https://opensource.org/licenses/MIT. No warranty
is provided. Copyright © 2017 Freddie Sackur
.Link
https://freddiesackur.wordpress.com/2017/10/08/wrapping-external-utilities-using-emcs-inq-exe-as-an-example/
.Link
ftp://ftp.emc.com/pub/symm3000/inquiry/
.Link
https://community.emc.com/thread/116665?start=0&tstart=0
#>
function Invoke-Inq {
[CmdletBinding(DefaultParameterSetName='WWN')]
[OutputType([psobject[]])]
param(
[Parameter()]
[string]$Path = '.\inq.exe',
[Parameter(ParameterSetName='WWN')]
[switch]$WWN,
[Parameter(ParameterSetName='WinVol')]
[switch]$WinVol
)
try {
if (-not (Test-Path $Path -PathType Leaf -ErrorAction Stop)) {
$InqPath = Join-Path $Path 'inq.exe'
} else {
$InqPath = $Path
}
$InqPath = (Resolve-Path $InqPath -ErrorAction Stop).Path
} catch [System.Management.Automation.ItemNotFoundException] {
throw New-Object System.Management.Automation.ItemNotFoundException ("Please provide the path to inq.exe")
}
$Output = New-Object 'System.Collections.Generic.List[psobject]'
$args = (
('-' + $PSCmdlet.ParameterSetName.ToLower())
)
$Lines = & $InqPath $args 2>$null
$Lines = $Lines |
select -Skip 6 | #skip preamble
where {$_ -notmatch '^-*$'} #skip rows composed only of dashes
$HeaderRow = $Lines[0]
$Rows = $Lines[1..($Lines.Count)]
$ColumnHeaders = $HeaderRow -split ':'
foreach ($Row in $Rows) {
$HT = @{}
if ($PSVersionTable.PSVersion.Major -ge 3) {$HT = [ordered]@{}}
$Values = $Row -split ':'
for ($i=0; $i -lt $ColumnHeaders.Count; $i++) {
$HT += @{
$ColumnHeaders[$i].Trim() = $Values[$i].Trim()
}
}
$Output.Add((New-Object psobject -Property $HT))
}
$Output.ToArray()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment