Listing Drives with Powershell

PowerShell script to list all local drives as a table.

Jan 1, 2023 - 13:38
Jan 4, 2023 - 12:25
Listing Drives with Powershell
powershell script

Quick and effective script to list the local drives. This script just bring the result for the system which it run. To get all drives from the environment a loop and the targets are required with privileged account.

------

<#
.SYNOPSIS
    Lists all drives
.DESCRIPTION
    This PowerShell script lists all local drives as a table.
.EXAMPLE
    PS> ./list-drives

    Name Root Used (GB) Free (GB)
    ---- ---- --------- ---------
    C    C:\     6648,1     744,2
.LINK
    https://github.com/fleschutz/PowerShell
.NOTES
    Author: Markus Fleschutz | License: CC0
#>

try {
    Get-PSDrive -PSProvider FileSystem | format-table -property Name,Root,@{n="Used (GB)";e={[math]::Round($_.Used/1GB,1)}},@{n="Free (GB)";e={[math]::Round($_.Free/1GB,1)}}
    exit 0 # success
} catch {
    "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
    exit 1
}

--------

Source:

https://github.com/fleschutz/PowerShell/blob/master/Scripts/list-drives.ps1

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow