如果 Powershell 命令分隔符是 ; (分号),为什么“date; dir”使dir输出额外的细节?

Mic*_*ter 12 powershell command-line

我知道分号是 Powershell 中的命令分隔符。 echo "hello"; dir给出这个输出。

PS C:\> echo "hello"; dir
hello

Directory: C:\

Mode         LastWriteTime     Length Name
----         -------------     ------ ----
d-----       2018-04-29 13:02         BCD_Backup
d-----       2018-12-02 14:08         Dell
<snip>
Run Code Online (Sandbox Code Playgroud)

但是为什么会date; dir给出这个输出呢?

PS C:\> date; dir

Friday, December 14, 2018 11:14:23

PSPath            : Microsoft.PowerShell.Core\FileSystem::C:\BCD_Backup
PSParentPath      : Microsoft.PowerShell.Core\FileSystem::C:\
PSChildName       : BCD_Backup
PSDrive           : C
PSProvider        : Microsoft.PowerShell.Core\FileSystem
PSIsContainer     : True
Name              : BCD_Backup
FullName          : C:\BCD_Backup
Parent            :
Exists            : True
Root              : C:\
Extension         :
CreationTime      : 2018-04-29 13:02:31
CreationTimeUtc   : 2018-04-29 11:02:31
LastAccessTime    : 2018-04-29 13:02:31
LastAccessTimeUtc : 2018-04-29 11:02:31
LastWriteTime     : 2018-04-29 13:02:31
LastWriteTimeUtc  : 2018-04-29 11:02:31
Attributes        : Directory
Mode              : d-----
BaseName          : BCD_Backup
Target            : {}
LinkType          :


PSPath            : Microsoft.PowerShell.Core\FileSystem::C:\Dell
PSParentPath      : Microsoft.PowerShell.Core\FileSystem::C:\
<snip>
Run Code Online (Sandbox Code Playgroud)

Jos*_*efZ 6

来自Out-Default文档

\n
\n

PowerShell 自动添加Out-Default 到每个管道的末尾\xe2\x80\xa6

\n
\n

当然,分号本身不足以识别这样的状态:

\n
Get-Alias -Name gal; Get-Location\n
Run Code Online (Sandbox Code Playgroud)\n
\n
CommandType     Name                                          Version    Source\n-----------     ----                                          -------    ------\nAlias           gal -> Get-Alias\n\nDrive        : D\nProvider     : Microsoft.PowerShell.Core\\FileSystem\nProviderPath : D:\\PShell\nPath         : D:\\PShell\n
Run Code Online (Sandbox Code Playgroud)\n
\n

添加Out-Default到管道显式解决了问题:

\n
Get-Alias -Name gal | Out-Default; Get-Location\n
Run Code Online (Sandbox Code Playgroud)\n
\n
CommandType     Name                                          Version    Source\n-----------     ----                                          -------    ------\nAlias           gal -> Get-Alias\n\n\nPath\n----\nD:\\PShell\n
Run Code Online (Sandbox Code Playgroud)\n
\n