PowerShell 技能连载 - 输出的同时赋值

如果您想将某个命令的结果赋给一个变量,并且同时输出结果,以下是两种实现方法:

您可以使用小括号:

PS> ($result = Get-Service)

Status   Name               DisplayName
------   ----               -----------
Running  AdobeARMservice    Adobe Acrobat Update Service
(...)

或者使用 OutVariable 通用参数:

PS> Get-Service -OutVariable result

Status   Name               DisplayName
------   ----               -----------
Running  AdobeARMservice    Adobe Acrobat Update Service
(...)
作者

Victor Woo

发布于

2015-09-07

更新于

2015-09-07

许可协议

PowerShell 技术 QQ 群