PowerShell PowerShell Background Jobs Basic job creation

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Start a Script Block as background job:

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

Start a script as background job:

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

Start a job using Invoke-Command on a remote machine:

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

Start job as a different user (Prompts for password):

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

Or

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

Start job as a different user (No prompt):

$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


Got any PowerShell Question?