If Powershell command separator is ; (semicolon), why does "date; dir" make dir output extra details?
As powershell executes statements one-by-one, I think, it applies output formatting of the first statement to all subsequent statements.
As Get-Date
returns an object of DateTime
type, it gets formatted as list, affecting your 'dir' output.
You can test this assumption by changing return type of Get-Date
to string using 'format' option:
date -Format yyyy-MM-dd ; dir
(this will produce default output for 'dir')
Or by changing default output formatting by pipelining it to Format-Table
:
date | Format-Table ; dir
From Out-Default
docs:
PowerShell automatically adds
Out-Default
to the end of every pipeline…
Definitely, a semicolon itself does not suffice for recognizing such a state:
Get-Alias -Name gal; Get-Location
CommandType Name Version Source ----------- ---- ------- ------ Alias gal -> Get-Alias Drive : D Provider : Microsoft.PowerShell.Core\FileSystem ProviderPath : D:\PShell Path : D:\PShell
Adding Out-Default
to the pipeline explicitly solves the problem:
Get-Alias -Name gal | Out-Default; Get-Location
CommandType Name Version Source ----------- ---- ------- ------ Alias gal -> Get-Alias Path ---- D:\PShell