A command is an executable instruction that a shell invokes to perform an operation. In PowerShell, you type a command, add parameters, press Enter, and immediately inspect the result. This interactive pattern lets administrators accomplish useful work without first writing a script. section 4.0 section 4.2
A PowerShell command commonly contains these parts:
- A command or cmdlet name, commonly written in verb-noun form, such as Get-Command. section 4.3
- Parameter names beginning with a dash, such as -Verb or -Module. section 4.3
- Parameter values, which may be comma-separated; switch parameters need no value. section 4.3
- Required spaces between the command, parameters, and values; capitalization does not matter, but accurate punctuation and spacing prevent avoidable errors. section 4.3
Finding the right command is part of performing the task. Start with PowerShell’s help system when you do not know what to use, when a command reports an error, or when you need to connect commands into a larger operation. Use Get-Help and Get-Command with wildcards to narrow possibilities, then read the examples and full help. section 3.1 section 7.6
Inspecting local disk space
Get-CimInstance -class Win32_LogicalDisk -computername localhost -filter "drivetype=3" | Sort-Object -property DeviceID | Format-Table -property DeviceID, @{label='FreeSpace(MB)';expression={$_.FreeSpace / 1MB -as [int]}}, @{label='Size(GB)';expression={$_.Size / 1GB -as [int]}}, @{label='%Free';expression={$_.FreeSpace / $_.Size * 100 -as [int]}} This command retrieves local logical disks, filters for fixed drives, sorts them, and formats free space, size, and percentage-free values. Long commands can be formatted across lines in VS Code while remaining one command. section 19.2
Get-CimInstance -class Win32_LogicalDisk -computername localhost `
-filter "drivetype=3" | Sort-Object -property DeviceID |
Format-Table -property DeviceID,
@{label='FreeSpace(MB)';expression={$_.FreeSpace / 1MB -as [int]}},
@{label='Size(GB)';expression={$_.Size / 1GB -as [int]}},
@{label='%Free';expression={$_.FreeSpace / $_.Size * 100 -as [int]}}
Use the complete disk-space command as a copyable example of combining a command, parameters, filtering, sorting, formatting, and calculated expressions. section 19.2
Commands can become repeatable automation. After repeatedly refining an interactive command, place it in a .ps1 file and run the script instead of retyping it. In VS Code, full command and parameter names make the resulting automation easier to read, test, and maintain. section 4.2 section 19.2




