| CMD Variable | PowerShell Analog | Description |
|---|---|---|
|
|
The full path to the script being executed. |
|
|
Positional arguments passed to the script. |
|
|
All arguments passed to the script as an array. |
|
|
Full path of the argument. |
|
|
Drive letter of the argument. |
|
|
Path of the argument without the file name. |
|
|
File name without extension. |
|
|
File extension. |
|
No direct analog |
Short 8.3 name format (rarely needed in PS). |
|
|
File attributes. |
|
|
File’s last modification time. |
|
|
File size in bytes. |
|
|
Resolves a file in the PATH environment variable. |
Key Differences:
-
$args in PowerShell is an array, making it more flexible for handling arguments.
-
PowerShell uses cmdlets (e.g., Split-Path, Resolve-Path) for advanced file and path manipulations.
-
$MyInvocation provides detailed context about the script, command, or function being executed.