利用本地变量,从一个可扩展的字符串,使用[scriptblock]::create方法创建脚本块: $v1 = "123" $v2 = "asdf" $sb = [scriptblock]::Create("Write-Host 'Values are: $v1, $v2'") $job = Start-Job -ScriptBlock $sb # 另一种写法 [scriptblock]$sb = { Write-Host "Values are: $v1, $...
模組: ThreadJob 建立類似 Start-Job Cmdlet 的背景工作。 語法 PowerShell 複製 Start-ThreadJob [-ScriptBlock] <ScriptBlock> [-Name <String>] [-InitializationScript <ScriptBlock>] [-InputObject <PSObject>] [-ArgumentList <Object[]>] [-ThrottleLimit <Int32>] [-StreamingHost <PSHost>] [<...
Start-Job-FilePathC:\Scripts\Sample.ps1 Start-Job使用FilePath参数指定存储在本地计算机上的脚本文件。 示例6:使用后台作业获取进程 此示例使用后台作业按名称获取指定进程。 PowerShell Start-Job-NamePShellJob-ScriptBlock{Get-Process-Namepowershell } ...
通过运行 Start-Job 启动本地作业。 提供 –ScriptBlock 参数以指定单个命令行或提供少量命令。 提供 –FilePath 参数以在后台线程上运行整个脚本。 默认情况下,作业接收顺序作业标识 (ID) 编号和默认作业名称。 虽然无法更改分配的作业 ID 号,但可以使用 –Name 参数指定自定义作业名称。 通过自...
InformationAction 的有效值為 SilentlyContinue、Stop、Continue、Inquire、Ignore 或 Suspend,預設值為 SilentlyContinue。 針對來自命令的 Write-Host 資料,您可使用 InformationVariable 將字串指定為要儲存的變數名稱。 InformationPreference (新的喜好設定變數) 能指定您在 Windows PowerShell 工作階段中針對資訊串流資料...
$a = { Get-Service BITS } Invoke-Command -ScriptBlock $a Output Copy Status Name DisplayName --- --- --- Running BITS Background Intelligent Transfer Ser... The call operator is another way to execute script blocks stored in a variable. Like Invoke-Command, the call operator execut...
Within the delay-bind script block, you can reference the piped in object using the pipeline variable$_. PowerShell # Both examples rename config.log to old_config.log# Without delay-bindingdir config.log |ForEach-Object-Process{Rename-Item-Path$_-NewName"old_$($_.Name)"}# With delay-...
$job=Start-Job-ScriptBlock{Get-Process-Namepwsh}Receive-Job$job-Wait If you want to run multiple commands, each in their own background process but all on one line, simply place&between and after each of the commands. PowerShell Get-Process-Namepwsh &Get-Service-NameBITS &Get-CimInstance-...
Invoke-Command 命令使用 AsJob 参数,以便命令作为后台作业运行。 这些命令在远程计算机上运行,但作业存在于本地计算机上。 结果将传输到本地计算机。 PowerShell 复制 $s = New-PSSession -ComputerName Server01, Server02 Invoke-Command -Session $s -ScriptBlock { Get-EventLog System } -AsJob Id Name ...
Improve variable type inference (#19830) (Thanks @MartinGC94!) Fix parameter completion when script requirements fail (#17687) (Thanks @MartinGC94!) Improve the completion for attribute arguments (#25129) (Thanks @MartinGC94!) Fix completion that relies on pseudobinding in script blocks (#251...