Public/Hardware/Get-DiskInfo.ps1
<#
Copyright © 2024 Integris. For internal company use only. All rights reserved. #> FUNCTION Get-DiskInfo { <# .SYNOPSIS Retrieves and displays information about physical disk drives on the system. .DESCRIPTION This function collects detailed information about each physical disk drive, including whether it contains the operating system, its model, media type, bus type, serial number, health status, and size in gigabytes. .PARAMETER Disks The collection of physical disk drives retrieved from the Get-PhysicalDisk cmdlet. .EXAMPLE Get-DiskDrive This command retrieves and displays information about all physical disk drives on the system, highlighting the drive that contains the operating system. .NOTES This function uses CIM instances to gather disk information and may require appropriate permissions to execute. #> [CmdletBinding()] PARAM ( ) $Results = @() $Disks = Get-PhysicalDisk $DriveLetter = $env:windir $DriveLetter = $DriveLetter.Substring(0,1) $Partition = Get-Partition -DriveLetter $DriveLetter $OSDriveDiskNumber = $Partition.DiskNumber FOREACH ($Disk in $Disks) { $IsOSDrive = "$False" IF ($Disk.DeviceID -eq $OSDriveDiskNumber) { $IsOSDrive = "$True" } $BusType = $null IF ($Disk.PhysicalLocation -like "*BaseLayer*") { $BusType = "Sandbox" } ELSE { $BusType = $Disk.BusType } $Results += New-Object PSObject -WarningAction SilentlyContinue -Property @{ PSTypeName = 'IntegrisPowerShell.DiskInfo' DeviceID = $Disk.DeviceID ContainsSystemOS = $IsOSDrive Model = $Disk.Model MediaType = $Disk.MediaType BusType = $BusType SerialNumber = $Disk.SerialNumber HealthStatus = $Disk.HealthStatus SizeGBs = [int]($Disk.Size / 1GB) } } RETURN $Results | Sort-Object -Descending -Property ContainsSystemOS } New-Alias -Name Get-DiskDevice -Value Get-DiskInfo New-Alias -Name Get-DiskDrive -Value Get-DiskInfo |