CmdID

CmdID / PowerShell / Cmdlets / Start

Start-Job

Starts a PowerShell background job. PowerShell reference

From the PowerShell reference 14 parameters Alias sajb

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Starts a PowerShell background job. The Start-Job cmdlet starts a PowerShell background job on the local computer. A PowerShell background job runs a command without interacting with the current session. When you start a background job, a job object returns immediately, even if the job takes an extended time to finish. You can continue to work in the session without interruption while the job runs. The job object contains useful information about the job, but it doesn't contain the job results. When the job finishes, use the Receive-Job cmdlet to get the results of the job. For more information about background jobs, see about_Jobs. To run a background job on a remote computer, use the AsJob parameter that is available on many cmdlets, or use the Invoke-Command cmdlet to run a Start-Job command on the remote computer. For more information, see about_Remote_Jobs. Starting in PowerShell 3.0, Start-Job can start instances of custom job types, such as scheduled jobs. For information about how to use Start-Job to start jobs with custom types, see the help documents for the job type feature. The default working directory for jobs is hardcoded. The Windows default is $HOME\Documents and on Linux or macOS the default is $HOME. The script code running in the background job needs to manage the working directory as needed.

Start-Job [-Name <String>] [-ScriptBlock] <ScriptBlock> [-Credential <PSCredential>] [-Authentication <AuthenticationMechanism>] [[-InitializationScript] <ScriptBlock>] [-RunAs32] [-PSVersion <Version>] [-InputObject <PSObject>] [-ArgumentList <Object[]>] [<CommonParameters>]
Start-Job [-DefinitionName] <String> [[-DefinitionPath] <String>] [[-Type] <String>] [<CommonParameters>]
Start-Job [-Name <String>] [-Credential <PSCredential>] [-FilePath] <String> [-Authentication <AuthenticationMechanism>] [[-InitializationScript] <ScriptBlock>] [-RunAs32] [-PSVersion <Version>] [-InputObject <PSObject>] [-ArgumentList <Object[]>] [<CommonParameters>]
Start-Job [-Name <String>] [-Credential <PSCredential>] -LiteralPath <String> [-Authentication <AuthenticationMechanism>] [[-InitializationScript] <ScriptBlock>] [-RunAs32] [-PSVersion <Version>] [-InputObject <PSObject>] [-ArgumentList <Object[]>] [<CommonParameters>]

Start a background job

Start-Job -ScriptBlock { Get-Process -Name powershell }Identify

Start a job using Invoke-Command

$jobWRM = Invoke-Command -ComputerName (Get-Content -Path C:\Servers.txt) -ScriptBlock { Get-Service -Name WinRM } -JobName WinRM -ThrottleLimit 16 -AsJobIdentify

Get job information

$j = Start-Job -ScriptBlock { Get-WinEvent -Log System } -Credential Domain01\User01 $j | Select-Object -Property *Identify

Trips 1 Sigma rule: mediumEventLog Query Requests By Builtin Utilities by Ali Alwashali, Nasreddine Bencherchali (Nextron Systems)

Run a script as a background job

Start-Job -FilePath C:\Scripts\Sample.ps1Identify

Get a process using a background job

Start-Job -Name PShellJob -ScriptBlock { Get-Process -Name powershell }Identify

Collect and save data by using a background job

Start-Job -Name GetMappingFiles -InitializationScript {Import-Module -Name MapFunctions} -ScriptBlock { Get-Map -Name * | Set-Content -Path D:\Maps.tif } -RunAs32Identify

Trips 1 Sigma rule: lowImport New Module Via PowerShell CommandLine by Nasreddine Bencherchali (Nextron Systems)

Pass input to a background job

Start-Job -ScriptBlock { Get-Content -Path $input } -InputObject "C:\Servers.txt" Receive-Job -Name Job45 -KeepIdentify

Use the ArgumentList parameter to specify an array

Start-Job -ScriptBlock { Get-Process -Name $args } -ArgumentList powershell, pwsh, notepadIdentify

Its page in the reference: Start-Job.

Parameters

14 in the PowerShell reference
-ArgumentListSpecifies an array of arguments, or parameter values, for the script that is specified by the FilePath parameter or a command specified with the ScriptBlock parameter. Arguments must be passed to ArgumentList as single-dimension array argument. For example, a comma-separated list. For more information about the behavior of ArgumentList, see about_Splatting.
-AuthenticationSpecifies the mechanism that is used to authenticate user credentials. The acceptable values for this parameter are as follows: - Default - Basic - Credssp - Digest - Kerberos - Negotiate - NegotiateWithImplicitCredential The default value is Default. CredSSP authentication is available only in Windows Vista, Windows Server 2008, and later versions of the Windows operating system. For more information about the values of this parameter, see AuthenticationMechanism. CAUTION: Credential Security Support Provider (CredSSP) authentication, in which the user's credentials are passed to a remote computer to be authenticated, is designed for commands that require authentication on more than one resource, such as accessing a remote network share. This mechanism increases the security risk of the remote operation. If the remote computer is compromised, the credentials that are passed to it can be used to control the network session.
-CredentialSpecifies a user account that has permission to perform this action. If the Credential parameter isn't specified, the command uses the current user's credentials. Credentials are stored in a PSCredential object and the password is stored as a SecureString. NOTE: For more information about SecureString data protection, see How secure is SecureString?.
-DefinitionNameSpecifies the definition name of the job that this cmdlet starts. Use this parameter to start custom job types that have a definition name, such as scheduled jobs. When you use Start-Job to start an instance of a scheduled job, the job starts immediately, regardless of job triggers or job options. The resulting job instance is a scheduled job, but it isn't saved to disk like triggered scheduled jobs. You can't use the ArgumentList parameter of Start-Job to provide values for parameters of scripts that run in a scheduled job. For more information, see about_Scheduled_Jobs. This parameter was introduced in PowerShell 3.0.
-DefinitionPathSpecifies path of the definition for the job that this cmdlet starts. Enter the definition path. The concatenation of the values of the DefinitionPath and DefinitionName parameters is the fully qualified path of the job definition. Use this parameter to start custom job types that have a definition path, such as scheduled jobs. For scheduled jobs, the value of the DefinitionPath parameter is $HOME\AppData\Local\Windows\PowerShell\ScheduledJob. This parameter was introduced in PowerShell 3.0.
-FilePathSpecifies a local script that Start-Job runs as a background job. Enter the path and file name of the script or use the pipeline to send a script path to Start-Job. The script must be on the local computer or in a folder that the local computer can access. When you use this parameter, PowerShell converts the contents of the specified script file to a scriptblock and runs the scriptblock as a background job.
-InitializationScriptSpecifies commands that run before the job starts. To create a scriptblock, enclose the commands in curly braces ({}). Use this parameter to prepare the session in which the job runs. For example, you can use it to add functions, snap-ins, and modules to the session.
-InputObjectSpecifies input to the command. Enter a variable that contains the objects, or type a command or expression that generates the objects. In the value of the ScriptBlock parameter, use the $input automatic variable to represent the input objects.
-LiteralPathSpecifies a local script that this cmdlet runs as a background job. Enter the path of a script on the local computer. Start-Job uses the value of the LiteralPath parameter exactly as it's typed. No characters are interpreted as wildcard characters. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape sequences.
-NameSpecifies a friendly name for the new job. You can use the name to identify the job to other job cmdlets, such as the Stop-Job cmdlet. The default friendly name is Job#, where # is an ordinal number that is incremented for each job.
-PSVersionSpecifies a version. Start-Job runs the job with the version of PowerShell. The acceptable values for this parameter are: 2.0 and 3.0. This parameter was introduced in PowerShell 3.0.
-RunAs32Indicates that Start-Job runs the job in a 32-bit process. RunAs32 forces the job to run in a 32-bit process, even on a 64-bit operating system. On 64-bit versions of Windows 7 and Windows Server 2008 R2, when the Start-Job command includes the RunAs32 parameter, you can't use the Credential parameter to specify the credentials of another user.
-ScriptBlockSpecifies the commands to run in the background job. To create a scriptblock, enclose the commands in curly braces ({}). Use the $input automatic variable to access the value of the InputObject parameter. This parameter is required.
-TypeSpecifies the custom type for jobs started by Start-Job. Enter a custom job type name, such as PSScheduledJob for scheduled jobs or PSWorkflowJob for workflows jobs. This parameter isn't valid for standard background jobs. This parameter was introduced in PowerShell 3.0.