基本职位创造

启动脚本块作为后台作业:

$job = Start-Job -ScriptBlock {Get-Process}

启动脚本作为后台作业:

$job = Start-Job -FilePath "C:\YourFolder\Script.ps1"

在远程计算机上使用 Invoke-Command 启动作业:

$job = Invoke-Command -ComputerName "ComputerName" -ScriptBlock {Get-Service winrm} -JobName "WinRM" -ThrottleLimit 16 -AsJob

以其他用户身份开始工作(提示输入密码):

Start-Job -ScriptBlock {Get-Process} -Credential "Domain\Username"

要么

Start-Job -ScriptBlock {Get-Process} -Credential (Get-Credential)

以其他用户身份启动作业(无提示):

$username = "Domain\Username" 
$password = "password"
$secPassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username, $secPassword)
Start-Job -ScriptBlock {Get-Process} -Credential $credentials