Last active
October 9, 2023 16:43
-
-
Save psitem/1440de1b50748f61d6d280de60b72111 to your computer and use it in GitHub Desktop.
Modifies the output of Get-PhysicalDisk to have enclosure information. Works On My Machine™ certified with an LSI SAS 9201-16e and Promise SAS enclosures.
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
<# | |
Wrote this to scratch an itch for tracking where my disks are physically located within and across | |
storage enclosures. Before writing this I was using a spreadsheet, which was tedious to maintain. | |
For this script to be useful, you'll need a storage enclosure that Windows recognizes and exposes | |
through WMI, ie: one that provides SCSI Enclosure Services (SES). | |
Check the output of Get-StorageEnclosure. | |
On my systems with multiple Promise J610S/J630S enclosures, Get-PhysicalDisk provides "Slot #" in | |
the PhysicalLocation property but the EnclosureNumber isn't populated. This script adds two | |
Properties to the objects returned by Get-PhysicalDisk: | |
EnclosureSN = Enclosure SerialNumber as provided by Get-StorageEnclosure | |
SizeString = Disk size coverted from Bytes to KB/MB/GB/TB/PB units. | |
I do not know how broadly applicable this is to other brands of enclosure, the only other model I | |
own does not provide SES. | |
#> | |
# Format-Bytes borrowed and modified from https://theposhwolf.com/howtos/Format-Bytes/ | |
Function Format-Bytes { | |
Param | |
( | |
[Parameter( | |
ValueFromPipeline = $true | |
)] | |
[ValidateNotNullOrEmpty()] | |
$number | |
) | |
Begin{ | |
$sizes = 'KB','MB','GB','TB','PB' | |
} | |
Process { | |
# New for loop | |
for($x = 0;$x -lt $sizes.count; $x++){ | |
if ($number -lt "1$($sizes[$x])"){ | |
if ($x -eq 0){ | |
return "$number B" | |
} else { | |
$num = $number / "1$($sizes[$x-1])" | |
$num = "{0:N2}" -f $num | |
return "$num $($sizes[$x-1])" | |
} | |
} | |
} | |
} | |
End{} | |
} | |
$disks = Get-PhysicalDisk | ForEach-Object { | |
$_ | ` | |
Add-Member ` | |
-MemberType NoteProperty ` | |
-Name EnclosureSN ` | |
-Value ( ( $_ | Get-StorageEnclosure ).SerialNumber ) ` | |
-PassThru | ` | |
Add-Member ` | |
-MemberType NoteProperty ` | |
-Name SizeString ` | |
-Value ( Format-Bytes $_.Size ) ` | |
-PassThru ` | |
} | Sort-Object EnclosureSN, SlotNumber, { [int] $_.DeviceId } | |
return $disks | |
# $disks | Format-Table DeviceId,FriendlyName,SerialNumber,MediaType,EnclosureSN,SlotNumber,SizeString -AutoSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output from my Plex server: