如何在PowerShell中抑制Start-Job命令的作业对象信息显示?
Sure thing! There are a couple of easy ways to prevent that job object table from appearing when you run Start-Job in PowerShell. Here are the most reliable methods:
Capture the job in a variable: This stores the job object for later use (like checking its state or retrieving results) while keeping the console clean. Example:
$bandwidthJob = Start-Job -ScriptBlock { param($piCurrentBandw) ... } -ArgumentList $yourValueNo output will be printed, and you can still reference
$bandwidthJobif needed.Redirect output to $null: If you don't need to keep track of the job at all, send the output to the null device:
Start-Job -ScriptBlock { param($piByteTotalsec) ... } > $nullFor a more PowerShell-native approach, use
Out-Nullwhich handles all output streams:Start-Job -ScriptBlock { ... } | Out-NullUse a throwaway variable with
-OutVariable: The-OutVariableparameter lets you capture the job object in a variable you don't intend to use. A common convention is to use an underscore for this:Start-Job -ScriptBlock { param($piPacketssec) ... } -OutVariable _This captures the job in
$_(which is overwritten quickly in most contexts) and stops the table from showing up.
All these methods work because Start-Job emits the job object as output by default. By capturing or redirecting that output, you prevent it from being displayed in your console.
内容的提问来源于stack exchange,提问作者John

