为什么"exit"不显示为 PowerShell 命令?



今天注意到一些奇怪的事情。我们都(可能)知道exit将结束您当前的PowerShell会话(或退出远程PSSession)。然而,Get-CommandGet-Alias都没有返回任何内容(错误截短如下):

Get-Command exit # ==> The term 'exit' is not recognized as the name of a cmdlet....
Get-Alias exit # ====> This command cannot find a matching alias....

所以…这是什么?

exit是关键字,而不是命令/cmdlet。查看about_Language_Keywords获取更多信息。

其他关键字(如:if)在与Get-Command/Get-Alias一起使用时也表现出相同的行为。

最新更新