ps/Modules/Cole.PowerShell.Developer/Public/Get-LocalHardDrives.ps1
2023-05-30 22:51:22 -07:00

45 lines
952 B
PowerShell

function Get-LocalHardDrives {
<#
.SYNOPSIS
Get the local hard drive information for this computer
.PARAMETER IncludeRemovableDisks
Get the information of removable disks as well
.OUTPUTS
Returns a [object[]] of drive info. See also ConvertTo-DriveInfo
#>
[CmdletBinding()]
[OutputType([string[]])]
param (
$IncludeRemovableDisks
)
<#
Drive types for the CIM Instance response are:
0 = Unknown
1 = No Root directory
2 = Removable Disk
3 = Local Disk
4 = Network Drive
5 = Compact Disc
6 = Ram Disk
#>
$driveTypeFilter = @(3)
$return = @()
if ($IncludeRemovableDisks) {
$driveTypeFilter += 2
}
$drives = (Get-CIMInstance -Class Win32_LogicalDisk)
foreach ($drive in $drives) {
if ($driveTypeFilter -contains $drive.DriveType) {
$return += (ConvertTo-DriveInfo -CimInstance $drive)
}
}
return $return
}