CmdID

CmdID / PowerShell / Cmdlets / Get

Get-Job

Gets PowerShell background jobs that are running in the current session. PowerShell reference

From the PowerShell reference 12 parameters Alias gjb

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

Gets PowerShell background jobs that are running in the current session. The Get-Job cmdlet gets objects that represent the background jobs that were started in the current session. You can use Get-Job to get jobs that were started by using the Start-Job cmdlet, or by using the AsJob parameter of any cmdlet. Without parameters, a Get-Job command gets all jobs in the current session. You can use the parameters of Get-Job to get particular jobs. The job object that Get-Job returns contains useful information about the job, but it does not contain the job results. To get the results, use the Receive-Job cmdlet. A Windows PowerShell background job is a command that runs in the background without interacting with the current session. Typically, you use a background job to run a complex command that takes a long time to finish. For more information about background jobs in Windows PowerShell, see about_Jobs. Beginning in Windows PowerShell 3.0, the Get-Job cmdlet also gets custom job types, such as workflow jobs and instances of scheduled jobs. To find the job type of a job, use the PSJobTypeName property of the job. To enable Get-Job to get a custom job type, import the module that supports the custom job type into the session before you run a Get-Job command, either by using the Import-Module cmdlet or by using or getting a cmdlet in the module. For information about a particular custom job type, see the documentation of the custom job type feature.

Get-Job [-IncludeChildJob] [-ChildJobState <JobState>] [-HasMoreData <Boolean>] [-Before <DateTime>] [-After <DateTime>] [-Newest <Int32>] [[-Id] <Int32[]>] [<CommonParameters>]
Get-Job [-IncludeChildJob] [-ChildJobState <JobState>] [-HasMoreData <Boolean>] [-Before <DateTime>] [-After <DateTime>] [-Newest <Int32>] [-Command <String[]>] [<CommonParameters>]
Get-Job [-IncludeChildJob] [-ChildJobState <JobState>] [-HasMoreData <Boolean>] [-Before <DateTime>] [-After <DateTime>] [-Newest <Int32>] [-InstanceId] <Guid[]> [<CommonParameters>]
Get-Job [-IncludeChildJob] [-ChildJobState <JobState>] [-HasMoreData <Boolean>] [-Before <DateTime>] [-After <DateTime>] [-Newest <Int32>] [-Name] <String[]> [<CommonParameters>]
Get-Job [-IncludeChildJob] [-ChildJobState <JobState>] [-HasMoreData <Boolean>] [-Before <DateTime>] [-After <DateTime>] [-Newest <Int32>] [-State] <JobState> [<CommonParameters>]
Get-Job [-Filter] <Hashtable> [<CommonParameters>]

Get all background jobs started in the current session

Get-JobIdentify

Stop a job by using an instance ID

$j = Get-Job -Name Job1 $ID = $j.InstanceId $IDIdentify

Get jobs that include a specific command

Get-Job -Command "Get-Process"Identify

Get jobs that include a specific command by using the pipeline

[pscustomobject]@{Command='Get-Process'} | Get-JobIdentify

Get jobs that have not been started

Get-Job -State NotStartedIdentify

Get jobs that have not been assigned a name

Get-Job -Name Job*Identify

Use a job object to represent the job in a command

Start-Job -ScriptBlock {Get-Process} -Name MyJob $j = Get-Job -Name MyJob $jIdentify

Get all jobs including jobs started by a different method

Start-Job -ScriptBlock {Get-EventLog -LogName System} Invoke-Command -ComputerName S1 -ScriptBlock {Get-EventLog -LogName System} -AsJob Invoke-Command -ComputerName S2 -ScriptBlock {Start-Job -ScriptBlock {Get-EventLog -LogName System}} Get-JobIdentify

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

Investigate a failed job

PS> Start-Job -ScriptBlock {Get-Process} Id Name PSJobTypeName State HasMoreData Location Command -- ---- ------------- ----- ----------- -------- ------- 1 Job1 BackgroundJob Failed False localhost Get-Process PS> (Get-Job).JobStateInfo | Format-List -Property * State : Failed Reason : PS> Get-Job | Format-List -Property * HasMoreData : False StatusMessage : Location : localhost Command : Get-Process JobStateInfo : Failed Finished : System.Threading.ManualReset EventInstanceId : fb792295-1318-4f5d-8ac8-8a89c5261507 Id : 1 Name : Job1 ChildJobs : {Job2} Output : {} Error : {} Progress : {} Verbose : {} Debug : {} Warning : {} StateChanged : PS> (Get-Job -Name Job2).JobStateInfo.Reason Connecting to remote server using WSManCreateShellEx api failed. The async callback gave the following error message: Access is denied.Identify

Get filtered results

PS> workflow WFProcess {Get-Process} PS> WFProcess -AsJob -JobName WFProcessJob -PSPrivateMetadata @{MyCustomId = 92107} PS> Get-Job -Filter @{MyCustomId = 92107} Id Name State HasMoreData Location Command -- ---- ----- ----------- -------- ------- 1 WFProcessJob Completed True localhost WFProcessIdentify

Its page in the reference: Get-Job.

Parameters

12 in the PowerShell reference
-AfterGets completed jobs that ended after the specified date and time. Enter a DateTime object, such as one returned by the Get-Date cmdlet or a string that can be converted to a DateTime object, such as Dec 1, 2012 2:00 AM or 11/06. This parameter works only on custom job types, such as workflow jobs and scheduled jobs, that have an EndTime property. It does not work on standard background jobs, such as those created by using the Start-Job cmdlet. For information about support for this parameter, see the help topic for the job type. This parameter was introduced in Windows PowerShell 3.0.
-BeforeGets completed jobs that ended before the specified date and time. Enter a DateTime object. This parameter works only on custom job types, such as workflow jobs and scheduled jobs, that have an EndTime property. It does not work on standard background jobs, such as those created by using the Start-Job cmdlet. For information about support for this parameter, see the help topic for the job type. This parameter was introduced in Windows PowerShell 3.0.
-ChildJobStateGets only the child jobs that have the specified state. The acceptable values for this parameter are: - NotStarted - Running - Completed - Failed - Stopped - Blocked - Suspended - Disconnected - Suspending - Stopping By default, Get-Job does not get child jobs. By using the IncludeChildJob parameter, Get-Job gets all child jobs. If you use the ChildJobState parameter, the IncludeChildJob parameter has no effect. This parameter was introduced in Windows PowerShell 3.0.
-CommandSpecifies an array of commands as strings. This cmdlet gets the jobs that include the specified commands. The default is all jobs. You can use wildcard characters to specify a command pattern.
-FilterSpecifies a hash table of conditions. This cmdlet gets jobs that satisfy all of the conditions. Enter a hash table where the keys are job properties and the values are job property values. This parameter works only on custom job types, such as workflow jobs and scheduled jobs. It does not work on standard background jobs, such as those created by using the Start-Job cmdlet. For information about support for this parameter, see the help topic for the job type. This parameter was introduced in Windows PowerShell 3.0.
-HasMoreDataIndicates whether this cmdlet gets only jobs that have the specified HasMoreData property value. The HasMoreData property indicates whether all job results have been received in the current session. To get jobs that have more results, specify a value of $true. To get jobs that do not have more results, specify a value of $false. To get the results of a job, use the Receive-Job cmdlet. When you use the Receive-Job cmdlet, it deletes from its in-memory, session-specific storage the results that it returned. When it has returned all results of the job in the current session, it sets the value of the HasMoreData property of the job to $false) to indicate that it has no more results for the job in the current session. Use the Keep parameter of Receive-Job to prevent Receive-Job from deleting results and changing the value of the HasMoreData property. For more information, type Get-Help Receive-Job. The HasMoreData property is specific to the current session. …
-IdSpecifies an array of IDs of jobs that this cmdlet gets. The ID is an integer that uniquely identifies the job in the current session. It is easier to remember and to type than the instance ID, but it is unique only in the current session. You can type one or more IDs separated by commas. To find the ID of a job, type Get-Job without parameters.
-IncludeChildJobIndicates that this cmdlet returns child jobs, in addition to parent jobs. This parameter is especially useful for investigating workflow jobs, for which Get-Job returns a container parent job, and job failures, because the reason for the failure is saved in a property of the child job. This parameter was introduced in Windows PowerShell 3.0.
-InstanceIdSpecifies an array of instance IDs of jobs that this cmdlet gets. The default is all jobs. An instance ID is a GUID that uniquely identifies the job on the computer. To find the instance ID of a job, use Get-Job.
-NameSpecifies an array of instance friendly names of jobs that this cmdlet gets. Enter a job name, or use wildcard characters to enter a job name pattern. By default, Get-Job gets all jobs in the current session.
-NewestSpecifies a number of jobs to get. This cmdlet gets the jobs that ended most recently. The Newest parameter does not sort or return the newest jobs in end-time order. To sort the output, use the Sort-Object cmdlet. This parameter was introduced in Windows PowerShell 3.0.
-StateSpecifies a job state. This cmdlet gets only jobs in the specified state. The acceptable values for this parameter are: - NotStarted - Running - Completed - Failed - Stopped - Blocked - Suspended - Disconnected - Suspending - Stopping By default, Get-Job gets all the jobs in the current session. For more information about job states, see JobState Enumeration.