Win32_ScheduledJob

Win32 Scheduled Job
root/cimv2dynamickey : JobId

Represents a job created with the AT command.

On this page

Main example

List instances

# All instances of Win32_ScheduledJob, with the main properties
Get-CimInstance -ClassName Win32_ScheduledJob |
    Select-Object -Property JobId, Name, Caption, Description, Status, InstallDate

Examples

Filter with WQL

# WQL filter evaluated by the provider: DaysOfMonth = 1 (1)
Get-CimInstance -ClassName Win32_ScheduledJob -Filter 'DaysOfMonth = 1' |
    Select-Object -Property JobId, Name, Caption, Description, Status, InstallDate

The filter is evaluated by the WMI provider: less data is transferred than with Where-Object.

Decode numeric values

# Lookup table for DaysOfMonth (values documented by Microsoft)
$daysOfMonthName = @{
    1 = '1'
    2 = '2'
    4 = '3'
    8 = '4'
    16 = '5'
    32 = '6'
    64 = '7'
    128 = '8'
    256 = '9'
    512 = '10'
    1024 = '11'
    2048 = '12'
    4096 = '13'
    8192 = '14'
    16384 = '15'
    32768 = '16'
    65536 = '17'
    131072 = '18'
    262144 = '19'
    524288 = '20'
    1048576 = '21'
    2097152 = '22'
    4194304 = '23'
    8388608 = '24'
    16777216 = '25'
    33554432 = '26'
    67108864 = '27'
    134217728 = '28'
    268435456 = '29'
    536870912 = '30'
    1073741824 = '31'
}
# Lookup table for DaysOfWeek (values documented by Microsoft)
$daysOfWeekName = @{
    1 = 'Monday'
    2 = 'Tuesday'
    4 = 'Wednesday'
    8 = 'Thursday'
    16 = 'Friday'
    32 = 'Saturday'
    64 = 'Sunday'
}

Get-CimInstance -ClassName Win32_ScheduledJob |
    Select-Object -Property @(
        'JobId'
        'Name'
        'Caption'
        'Description'
        'Status'
        'InstallDate'
        @{ Name = 'DaysOfMonth'; Expression = { $daysOfMonthName[[int]$_.DaysOfMonth] } }
    )

Query a remote computer (CIM session)

review before running
# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
    Get-CimInstance -CimSession $cimSession -ClassName Win32_ScheduledJob |
        Select-Object -Property JobId, Name, Caption, Description, Status, InstallDate
} finally {
    Remove-CimSession -CimSession $cimSession
}

WSMan (WinRM) is used by default. For a host without WinRM, create the session with -SessionOption (New-CimSessionOption -Protocol Dcom). Add -Credential to use another account.

Show the class structure

# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName Win32_ScheduledJob
$cimClass.CimClassProperties |
    Select-Object -Property Name, CimType, Flags

# Methods of the class
$cimClass.CimClassMethods |
    Select-Object -Property Name, ReturnType

Properties

19 of 19 properties
NameTypeAccessDescription
Captionstringread

A short textual description of the object.

Code
# Value of Caption for each instance
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, Caption |
    Select-Object -Property JobId, Caption
Commandstringread

Name of the command, batch program, or binary file (and command-line arguments) that the schedule service uses to invoke the job.

Example: "defrag/q/f"

Code
# Value of Command for each instance
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, Command |
    Select-Object -Property JobId, Command
DaysOfMonthuint32read

Days of the month when the job is scheduled to run. If a job is scheduled to run on multiple days of the month, these values can be joined in a logical OR. For example, if a job is to run on the 1st and 16th of each month, the value of the DaysOfMonth property would be 1 OR 32768.

Values (31)
ValueLabelDescription
111st
222nd
433rd
844th
1655th
3266th
6477th
12888th
25699th
5121010th
10241111th
20481212th
40961313th
81921414th
163841515th
327681616th
655361717th
1310721818th
2621441919th
5242882020th
10485762121st
20971522222nd
41943042323rd
83886082424th
167772162525th
335544322626th
671088642727th
1342177282828th
2684354562929th
5368709123030th
10737418243131st
Code
# Value of DaysOfMonth for each instance
# Lookup table for DaysOfMonth (values documented by Microsoft)
$daysOfMonthName = @{
    1 = '1'
    2 = '2'
    4 = '3'
    8 = '4'
    16 = '5'
    32 = '6'
    64 = '7'
    128 = '8'
    256 = '9'
    512 = '10'
    1024 = '11'
    2048 = '12'
    4096 = '13'
    8192 = '14'
    16384 = '15'
    32768 = '16'
    65536 = '17'
    131072 = '18'
    262144 = '19'
    524288 = '20'
    1048576 = '21'
    2097152 = '22'
    4194304 = '23'
    8388608 = '24'
    16777216 = '25'
    33554432 = '26'
    67108864 = '27'
    134217728 = '28'
    268435456 = '29'
    536870912 = '30'
    1073741824 = '31'
}
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, DaysOfMonth |
    Select-Object -Property @(
        'JobId'
        @{ Name = 'DaysOfMonth'; Expression = { $daysOfMonthName[[int]$_.DaysOfMonth] } }
    )
DaysOfWeekuint32read

Days of the week when a job is scheduled to run. If a job is scheduled to run on multiple days of the week, the values can be joined in a logical OR. For example, if a job is scheduled to run on Mondays, Wednesdays, and Fridays the value of the DaysOfWeek property would be 1 OR 4 OR 16.

Values (7)
ValueLabelDescription
1Monday
2Tuesday
4Wednesday
8Thursday
16Friday
32Saturday
64Sunday
Code
# Value of DaysOfWeek for each instance
# Lookup table for DaysOfWeek (values documented by Microsoft)
$daysOfWeekName = @{
    1 = 'Monday'
    2 = 'Tuesday'
    4 = 'Wednesday'
    8 = 'Thursday'
    16 = 'Friday'
    32 = 'Saturday'
    64 = 'Sunday'
}
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, DaysOfWeek |
    Select-Object -Property @(
        'JobId'
        @{ Name = 'DaysOfWeek'; Expression = { $daysOfWeekName[[int]$_.DaysOfWeek] } }
    )
Descriptionstringread

A textual description of the object.

Code
# Value of Description for each instance
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, Description |
    Select-Object -Property JobId, Description
ElapsedTimedatetimeread

Length of time the job has been executing.

Code
# Value of ElapsedTime for each instance
# CIM cmdlets already return a DateTime object: no conversion is needed
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, ElapsedTime |
    Select-Object -Property JobId, ElapsedTime
InstallDatedatetimeread

Indicates when the object was installed. Lack of a value does not indicate that the object is not installed.

Code
# Value of InstallDate for each instance
# CIM cmdlets already return a DateTime object: no conversion is needed
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, InstallDate |
    Select-Object -Property JobId, InstallDate
InteractWithDesktopbooleanread

Specified job is interactive, which means that a user can give input to a scheduled job while it is executing.

Code
# Value of InteractWithDesktop for each instance
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, InteractWithDesktop |
    Select-Object -Property JobId, InteractWithDesktop
JobId keyuint32read

Identifying number of the job. It is used by methods as a handle to one job being scheduled on this computer.

Code
# Value of JobId for each instance
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId |
    Select-Object -Property JobId
JobStatusstringread

Status of execution the last time this job was scheduled to run.

Values (2)
ValueLabelDescription
SuccessSuccess
FailureFailure
Code
# Value of JobStatus for each instance
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, JobStatus |
    Select-Object -Property JobId, JobStatus
Namestringread

Label by which the object is known. When subclassed, this property can be overridden to be a key property.

Code
# Value of Name for each instance
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, Name |
    Select-Object -Property JobId, Name
Notifystringread

User is notified upon job completion or failure.

Code
# Value of Notify for each instance
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, Notify |
    Select-Object -Property JobId, Notify
Ownerstringread

User who submitted the job.

Code
# Value of Owner for each instance
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, Owner |
    Select-Object -Property JobId, Owner
Priorityuint32read

Importance of a job's execution.

Code
# Value of Priority for each instance
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, Priority |
    Select-Object -Property JobId, Priority
RunRepeatedlybooleanread

Scheduled job runs repeatedly on the days that the job is scheduled. If False, then the job is run one time.

Code
# Value of RunRepeatedly for each instance
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, RunRepeatedly |
    Select-Object -Property JobId, RunRepeatedly
StartTimedatetimeread

UTC time to run the job, in the form of "YYYYMMDDHHMMSS.MMMMMM(+-)OOO", where "YYYYMMDD" must be replaced by "". The replacement is necessary because the scheduling service only allows jobs to be configured to run one time, or run on a day of the month or week. A job cannot be run on a specific date.

The "(+-)OOO" section of the StartTime property value is the current bias for local time translation. The bias is the difference between the UTC time and local time. To calculate the bias for your time zone, multiply the number of hours that your time zone is ahead or behind Greenwich Mean Time (GMT) by 60 (use a positive number for the number of hours if your time zone is ahead of GMT and a negative number if your time zone is behind GMT). Add an additional 60 to your calculation if your time zone is using daylight savings time. For example, the Pacific Standard Time zone is eight hours behind GMT, therefore the bias is equals to -420 (-8 * 60 + 60) when daylight savings time is in use and -480 (-8 * 60) when daylight savings time is not in use. You can also determine the value of the bias by querying the bias property of the Win32_TimeZone class.

For example: "123000.000000-420" specifies 14.30 (2:30 P.M.) PST with daylight savings time in effect.

Code
# Value of StartTime for each instance
# CIM cmdlets already return a DateTime object: no conversion is needed
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, StartTime |
    Select-Object -Property JobId, StartTime
Statusstringread

String that indicates the current status of the object. Operational and non-operational status can be defined. Operational status can include "OK", "Degraded", and "Pred Fail". "Pred Fail" indicates that an element is functioning properly, but is predicting a failure (for example, a SMART-enabled hard disk drive).

Non-operational status can include "Error", "Starting", "Stopping", and "Service". "Service" can apply during disk mirror-resilvering, reloading a user permissions list, or other administrative work. Not all such work is online, but the managed element is neither "OK" nor in one of the other states.

Values include the following:

Values (12)
ValueLabelDescription
OKOK
ErrorError
DegradedDegraded
UnknownUnknown
Pred FailPred Fail
StartingStarting
StoppingStopping
ServiceService
StressedStressed
NonRecoverNonRecover
No ContactNo Contact
Lost CommLost Comm
Code
# Value of Status for each instance
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, Status |
    Select-Object -Property JobId, Status
TimeSubmitteddatetimeread

Time that the job was submitted.

Code
# Value of TimeSubmitted for each instance
# CIM cmdlets already return a DateTime object: no conversion is needed
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, TimeSubmitted |
    Select-Object -Property JobId, TimeSubmitted
UntilTimedatetimeread

Time at which the job is invalid or should be stopped.

Code
# Value of UntilTime for each instance
# CIM cmdlets already return a DateTime object: no conversion is needed
Get-CimInstance -ClassName Win32_ScheduledJob -Property JobId, UntilTime |
    Select-Object -Property JobId, UntilTime

Methods

Create static#

Class method that submits a job to the operating system for execution at a specified future time and date.

uint32 Create(
    [in] string Command,
    [in] datetime StartTime,
    [in] boolean RunRepeatedly,
    [in] uint32 DaysOfWeek,
    [in] uint32 DaysOfMonth,
    [in] boolean InteractWithDesktop,
    [out] uint32 JobId
);

Parameters

ParameterTypeDirectionDescription
Commandstringin

Name of the command, batch program, or binary file and command-line parameters that the schedule service uses to invoke the job.

Example: "defrag /q /f".

StartTimedatetimein

Coordinated Universal Time (UTC) time to run a job. The form must be: "YYYYMMDDHHMMSS.MMMMMM(+-)OOO", where "YYYYMMDD" must be replaced by "". For example: "143000.000000-420" specifies 14.30 (2:30 P.M.) PST with daylight savings time in effect.

The "(+-)OOO" section of the StartTime property value is the current bias for local time translation. The bias is the difference between the UTC time and the local time. To calculate the bias for your time zone, multiply the number of hours that your time zone is ahead or behind Greenwich Mean Time (GMT) by 60 (use a positive number for the number of hours if your time zone is ahead of GMT and a negative number if your time zone is behind GMT). Add an additional 60 to your calculation if your time zone is using daylight savings time. For example, the Pacific Standard Time zone is eight hours behind GMT, therefore the bias is equals to -420 (-8 * 60 + 60) when daylight savings time is in use and -480 (-8 * 60) when daylight savings time is not in use. You can also determine the value of the bias by querying the bias property of the Win32_TimeZone class.

RunRepeatedlybooleanin

If True, a scheduled job runs repeatedly on specific days. The default is False.

DaysOfWeekuint32in

Days of the week when a job is scheduled to run; used only when the *RunRepeatedly* parameter is True. To schedule a job for more than one day of the week, join the appropriate values in a logical OR. For example, to schedule a job for Tuesdays and Fridays, the value of *DaysOfWeek* are 2 OR 16.

DaysOfMonthuint32in

Days of the month when a job is scheduled to run; used only when the *RunRepeatedly* parameter is True.

InteractWithDesktopbooleanin

If True, the specified job should be interactive, which means that a user can give input to a scheduled job while the job is executing. The default is False.

JobIduint32out

Identifier number of a job. This parameter is a handle to a job being scheduled on a computer.

Return values

ValueLabelDescription
0Successful completionThe request is accepted.
1Not supportedThe request is not supported.
2Access deniedThe user does not have the necessary access.
8Unknown failureInteractive process.
9Path not foundThe directory path to the service executable file cannot be found.
21Invalid parameterInvalid parameters have been passed to the service.
22Service not startedThe account that this service runs under is invalid or lacks the permissions to run the service.
23..4294967295Other

Call the Create method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
$methodParameters = @{
    ClassName  = 'Win32_ScheduledJob'
    MethodName = 'Create'
    Arguments  = @{
        Command             = 'Example'
        StartTime           = (Get-Date)
        RunRepeatedly       = $false
        DaysOfWeek          = 1
        DaysOfMonth         = 1
        InteractWithDesktop = $false
    }
    WhatIf     = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'Successful completion'
        1 = 'Not supported'
        2 = 'Access denied'
        8 = 'Unknown failure'
        9 = 'Path not found'
        21 = 'Invalid parameter'
        22 = 'Service not started'
    }
    $returnValueName[[int]$result.ReturnValue]
    $result.JobId
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

Delete #

Class method that deletes a scheduled job.

uint32 Delete();

Return values

ValueLabelDescription
0Successful completionThe request was accepted.
1Not supportedThe request is not supported.
2Access deniedThe user did not have the necessary access.
8Unknown failureInteractive process.
9Path not foundThe directory path to the service executable file was not found.
21Invalid parameterInvalid parameters have been passed to the service.
22Service not startedThe account which this service is to run under is either invalid or lacks the permissions to run the service.
23..4294967295Other

Call the Delete method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_ScheduledJob -Filter 'JobId = 0'
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'Delete'
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'Successful completion'
        1 = 'Not supported'
        2 = 'Access denied'
        8 = 'Unknown failure'
        9 = 'Path not found'
        21 = 'Invalid parameter'
        22 = 'Service not started'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

Remarks

Each job scheduled against the schedule service is stored persistently (the scheduler can start a job after a reboot), and is executed at the specified time and day of the week or month. If the computer is not active, or if the scheduled service is not running at the specified job time, the schedule service runs the specified job on the next day at the specified time.

Jobs are scheduled according to Coordinated Universal Time (UTC) with bias offset from Greenwich Mean Time (GMT), which means that a job can be specified using any time zone. The Win32_ScheduledJob class returns the local time with UTC offset when enumerating an object, and converts to local time when creating new jobs. For example, a job specified to run on a computer in Boston at 10:30 P.M. Monday PST time will be scheduled to run locally at 1:30 A.M. Tuesday EST.

Note: A client must take into account whether or not daylight savings time is in operation on the local computer, and if it is, then subtract a bias of 60 minutes from the UTC offset.

The Win32_ScheduledJob class is derived from CIM_Job. You must be a member of the administrators group to create a scheduled job using this class.

The Win32_ScheduledJob class is internally using the AT protocol, which is bound to deprecation starting with Windows 8 and Windows Server 2012. As a first step the AT protocol is disabled by default. If the protocol is disabled, for example calling the Create method on a Win32_ScheduledJob object will fail with error 0x8. You can turn the AT protocol back on by adding the following registry entry:

``` syntax

Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\Configuration

Name: EnableAt

Type: REG_DWORD

Value: 1

```

You may need to restart the machine to make the setting effective.

Because Win32_ScheduledJob is based on the NetScheduleJobGetInfo Win32 API, you cannot use this class in conjunction with the Task Scheduler. If you wish to use Task Scheduler, use the Task Scheduler API. For more information, see the Task Scheduler Reference.

Inheritance

Superclass chain

  1. CIM_ManagedSystemElement
  2. CIM_LogicalElement
  3. CIM_Job
  4. Win32_ScheduledJob

Known subclasses

No known subclass.

Requirements

Namespace
root/cimv2
Minimum client
Windows Vista
Minimum server
Windows Server 2008
Provider
CIMWin32
MOF file
CIMWin32.mof
DLL
CIMWin32.dll
Class qualifiers

Dynamic Provider("CIMWin32") UUID("{8502C4E0-5FBB-11D2-AAC1-006008C78BC7}") SupportsCreate CreateBy("Create") SupportsDelete DeleteBy("Delete") AMENDMENT

Microsoft source

Source: Microsoft Learn

Descriptions, properties and methods come from the Microsoft documentation (MicrosoftDocs/win32 repository), published under the CC BY 4.0 licence. Formatting and translations are specific to this site; the PowerShell examples are written for it.