Show-PSDrive.ps1
19 Sep 2025Description
Purpose
Displays the details of all PowerShell drives.
Detailed Description
The Show-PSDrive function retrieves all the PowerShell drives, sorts them by a specified property, and then displays them in a table format.
Usage
Example 1
Show-PSDrive -SortBy "Name"
Notes
No additional notes.
Script
function Show-PSDrive {
<#
.SYNOPSIS
Displays the details of all PowerShell drives.
.DESCRIPTION
The Show-PSDrive function retrieves all the PowerShell drives, sorts them by a specified property, and then displays them in a table format.
.PARAMETER SortBy
Specifies the property by which the PowerShell drives should be sorted.
.EXAMPLE
Show-PSDrive -SortBy "Name"
#>
param (
[ValidateSet("Name", "Root", "Description", "MaximumSize", "Credential", "DisplayRoot", "Used", "Free", "CurrentLocation", "IsReady")]
[string]$SortBy
)
try {
$drives = Get-PSDrive
if ($SortBy) {
$drives = $drives | Sort-Object $SortBy
}
$drives = $drives | Select-Object Name, Root, Description, @{Name = 'Used'; Expression = { (Get-FriendlySize -Bytes $_.Used).FriendlySize } }, @{Name = 'Free'; Expression = { (Get-FriendlySize -Bytes $_.Free).FriendlySize } }, DisplayRoot
$drives | Format-Table -AutoSize
}
catch {
Write-Error "An error occurred: $_"
}
}
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.