PowerShell 中 Stop-Process 中 Passthru 引數的用途是什麼?


使用 Passthru 引數,PowerShell 會返回控制檯中的輸出。例如,ID 為 12344 的 notepad.exe 程序停止後,就會使用 Passthru 引數在控制檯中顯示。以前僅使用 Stop-Process 時不會出現這種情況。

PS C:\WINDOWS\system32> Stop-Process -Id 12344 -PassThru

    Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
    -------  ------    -----      -----     ------     --  -- -----------
        227      13     2800      13440       0.19  12344   1 notepad

還可結合使用 –Confirm 和 –PassThru 引數。

PS C:\WINDOWS\system32> Stop-Process -Id 26492 -Confirm -PassThru

Confirm
Are you sure you want to perform this action?
Performing the operation "Stop-Process" on target "notepad (26492)".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    228      14     3152      13736       0.20  26492   1 notepad

更新時間:2020 年 1 月 22 日

3K+ 瀏覽次數

開啟您的職業生涯

完成本課程後獲得認證

開始學習
廣告
© . All rights reserved.