In PowerShell, if I do:
dir
I get a listing with color.
However, if I do:
PowerShell -Command "dir"
there is no color.
Is there a way to do PowerShell -Command "dir" and have it show colors in the output?
powershell[.exe] is the name for the default host application of Windows PowerShell, the version of PowerShell that ships with Windows.
To invoke PowerShell 7 (which has the styling features you want), launch pwsh[.exe] instead:
pwsh -Command "dir"
If you ever wonder which version of PowerShell you're currently using, inspect the $PSVersionTable variable:
"You're currently using version $($PSVersionTable.PSVersion)"
To find the executable path of the current process, use Get-Process:
(Get-Process -Id $PID).Path