From ab3d1f0a5e7b77d2099368a53952fddf380c8c06 Mon Sep 17 00:00:00 2001 From: Bobby Reed Date: Wed, 23 May 2018 12:58:39 -0400 Subject: [PATCH 1/8] Batch automation: Formatting fixes --- .../About/about_Scheduled_Jobs.md | 4 +- .../About/about_Scheduled_Jobs_Advanced.md | 4 +- .../About/about_Scheduled_Jobs_Basics.md | 4 +- .../about_Scheduled_Jobs_Troubleshooting.md | 5 +- .../3.0/PSScheduledJob/Add-JobTrigger.md | 42 ++++-- .../3.0/PSScheduledJob/Disable-JobTrigger.md | 48 +++++-- .../PSScheduledJob/Disable-ScheduledJob.md | 68 ++++++++-- .../3.0/PSScheduledJob/Enable-JobTrigger.md | 46 +++++-- .../3.0/PSScheduledJob/Enable-ScheduledJob.md | 53 ++++++-- .../3.0/PSScheduledJob/Get-JobTrigger.md | 97 +++++++++++--- .../3.0/PSScheduledJob/Get-ScheduledJob.md | 48 +++++-- .../PSScheduledJob/Get-ScheduledJobOption.md | 70 +++++++--- .../3.0/PSScheduledJob/New-JobTrigger.md | 105 +++++++++++---- .../PSScheduledJob/New-ScheduledJobOption.md | 71 ++++++++-- .../3.0/PSScheduledJob/PSScheduledJob.md | 22 ++- .../PSScheduledJob/Register-ScheduledJob.md | 78 ++++++++--- .../3.0/PSScheduledJob/Remove-JobTrigger.md | 46 +++++-- .../3.0/PSScheduledJob/Set-JobTrigger.md | 106 ++++++++++++--- .../3.0/PSScheduledJob/Set-ScheduledJob.md | 61 +++++++-- .../PSScheduledJob/Set-ScheduledJobOption.md | 53 +++++++- .../PSScheduledJob/Unregister-ScheduledJob.md | 43 ++++-- .../About/about_ActivityCommonParameters.md | 4 +- .../New-PSWorkflowExecutionOption.md | 126 +++++++++--------- .../3.0/PSWorkflow/New-PSWorkflowSession.md | 39 +++++- reference/3.0/PSWorkflow/PSWorkflow.md | 8 +- 25 files changed, 964 insertions(+), 287 deletions(-) diff --git a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs.md b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs.md index 80ab7da28fbf..20d0fa0198e6 100644 --- a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs.md +++ b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs.md @@ -1,12 +1,12 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us keywords: powershell,cmdlet title: about_Scheduled_Jobs --- - # About Scheduled Jobs + ## about_Scheduled_Jobs diff --git a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Advanced.md b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Advanced.md index aa88bcff9891..6fc3957660b2 100644 --- a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Advanced.md +++ b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Advanced.md @@ -1,12 +1,12 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us keywords: powershell,cmdlet title: about_Scheduled_Jobs_Advanced --- - # About Scheduled Jobs Advanced + ## about_Scheduled_Jobs_Advanced diff --git a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Basics.md b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Basics.md index dd9c69d844bf..88b8bb633ed1 100644 --- a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Basics.md +++ b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Basics.md @@ -1,12 +1,12 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us keywords: powershell,cmdlet title: about_Scheduled_Jobs_Basics --- - # About Scheduled Jobs Basics + ## about_Scheduled_Jobs_Basics diff --git a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Troubleshooting.md b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Troubleshooting.md index ea1da952120e..d5b0b8af63e8 100644 --- a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Troubleshooting.md +++ b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Troubleshooting.md @@ -1,12 +1,12 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us keywords: powershell,cmdlet title: about_Scheduled_Jobs_Troubleshooting --- - # About Scheduled Jobs Troubleshooting + ## about_Scheduled_Jobs_Troubleshooting @@ -184,6 +184,7 @@ Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName 1213 33 12348 21676 88 25.71 1608 CcmExec 29 4 1168 2920 43 0.02 748 conhost 46 6 2208 4612 45 0.03 1640 conhost + # ... diff --git a/reference/3.0/PSScheduledJob/Add-JobTrigger.md b/reference/3.0/PSScheduledJob/Add-JobTrigger.md index 759664f2b6f4..21fb422745a2 100644 --- a/reference/3.0/PSScheduledJob/Add-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/Add-JobTrigger.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,29 +7,35 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223913 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Add-JobTrigger --- - # Add-JobTrigger + ## SYNOPSIS + Adds job triggers to scheduled jobs + ## SYNTAX ### JobDefinition (Default) + ``` Add-JobTrigger [-Trigger] [-InputObject] [] ``` ### JobDefinitionId + ``` Add-JobTrigger [-Trigger] [-Id] [] ``` ### JobDefinitionName + ``` Add-JobTrigger [-Trigger] [-Name] [] ``` ## DESCRIPTION + The **Add-JobTrigger** cmdlet adds job triggers to scheduled jobs. You can use it to add multiple triggers to multiple scheduled jobs. @@ -46,11 +52,14 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Add a job trigger to a scheduled job -``` -PS C:\> $Daily = New-JobTrigger -Daily -At 3AMPS C:\> Add-JobTrigger -Trigger $Daily -Name TestJob + +```powershell +$Daily = New-JobTrigger -Daily -At 3AM +Add-JobTrigger -Trigger $Daily -Name TestJob ``` These commands add the Daily job trigger to the TestJob scheduled job. @@ -59,20 +68,24 @@ The first command uses the New-JobTrigger cmdlet to create a job trigger that st The command saves the job trigger in the $Daily variable. The second command uses the **Add-JobTrigger** cmdlet to add the job trigger in the $Startup variable to the TestJob scheduled job. + ### Example 2: Add a job trigger to many scheduled jobs -``` -PS C:\> Get-ScheduledJob | Add-JobTrigger -Trigger (New-JobTrigger -AtStartup) + +```powershell +Get-ScheduledJob | Add-JobTrigger -Trigger (New-JobTrigger -AtStartup) ``` This command adds an AtStartup job trigger to all scheduled jobs on the local computer. It uses the Get-ScheduledJob to get all of the scheduled jobs on the computer. It uses a pipeline operator (|) to send the jobs to the **Add-JobTrigger** cmdlet, which adds the job trigger to each of the scheduled jobs. The value of the **Trigger** parameter is a New-JobTrigger command that creates the AtStartup job trigger. + ### Example 3: Copy a job trigger -``` -PS C:\> $t = Get-JobTrigger -Name BackupArchives -PS C:\> Add-JobTrigger -Name TestBackup, BackupLogs -Trigger $t +```powershell +$t = Get-JobTrigger -Name BackupArchives + +Add-JobTrigger -Name TestBackup, BackupLogs -Trigger $t ``` These commands copy the job trigger from the BackupArchives scheduled job and add it to the TestBackup and BackupLogs scheduled jobs. @@ -81,9 +94,11 @@ The first command uses the Get-JobTrigger cmdlet to get the job trigger of the B The command saves the trigger in the $t variable. The second command uses the **Add-JobTrigger** cmdlet to add the job trigger in $t to the TestBackup and BackupLogs scheduled jobs. + ## PARAMETERS ### -Id + Specifies the identification numbers of the scheduled jobs. **Add-JobTrigger** adds the job trigger to the specified scheduled jobs. @@ -102,6 +117,7 @@ Accept wildcard characters: False ``` ### -InputObject + Specifies the scheduled jobs. Enter a variable that contains **ScheduledJob** objects or type a command or expression that gets **ScheduledJob** objects, such as a Get-ScheduledJob command. You can also pipe **ScheduledJob** objects to **Add-JobTrigger**. @@ -119,6 +135,7 @@ Accept wildcard characters: False ``` ### -Name + Specifies the names of the scheduled jobs. **Add-JobTrigger** adds the job triggers to the specified scheduled jobs. Wildcards are supported. @@ -138,6 +155,7 @@ Accept wildcard characters: True ``` ### -Trigger + Specifies the job triggers to add. Enter a hash table that specifies job triggers or a variable that contains **ScheduledJobTrigger** objects, or type a command or expression that gets **ScheduledJobTrigger** objects, such as a Get-JobTrigger command. You can also pipe **ScheduledJobTrigger** objects to **Add-JobTrigger**. @@ -155,15 +173,21 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobTrigger, Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition + You can pipe job triggers or scheduled jobs to **Add-JobTrigger**. + ## OUTPUTS ### None + This cmdlet does not return any output. + ## NOTES ## RELATED LINKS diff --git a/reference/3.0/PSScheduledJob/Disable-JobTrigger.md b/reference/3.0/PSScheduledJob/Disable-JobTrigger.md index 2b353dc5939b..a96484f8b6a3 100644 --- a/reference/3.0/PSScheduledJob/Disable-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/Disable-JobTrigger.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,10 +7,12 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223918 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Disable-JobTrigger --- - # Disable-JobTrigger + ## SYNOPSIS + Disables the job triggers of scheduled jobs + ## SYNTAX ``` @@ -18,6 +20,7 @@ Disable-JobTrigger [-InputObject] [-WhatIf] [-Confirm] [ ``` ## DESCRIPTION + The **Disable-JobTrigger** cmdlet temporarily disables the job triggers of scheduled jobs. Disabling preserves all job trigger properties, but it prevents the job trigger from starting the scheduled job. @@ -36,24 +39,35 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Disable a job trigger -``` -PS C:\> Get-JobTrigger -Name Backup-Archives -TriggerID 1 | Disable-JobTrigger + +```powershell +Get-JobTrigger -Name Backup-Archives -TriggerId 1 | Disable-JobTrigger ``` This command disables the first trigger (ID=1) of the Backup-Archives scheduled job on the local computer. The command uses the Get-JobTrigger cmdlet to get the job trigger. A pipeline operator sends the job trigger to the **Disable-JobTrigger** cmdlet, which disables it. + ### Example 2: Disable all job triggers -``` + The first command uses the Get-ScheduledJob cmdlet to get the Backup-Archives and Inventory scheduled jobs. A pipeline operator (|) sends the scheduled jobs to the Get-JobTrigger cmdlet, which gets all job triggers of the scheduled jobs. Another pipeline operator sends the job triggers to the **Disable-JobTrigger** cmdlet, which disables them.The first command uses the **Get-ScheduledJob** cmdlet to get the jobs, because its **Name** parameter takes multiple names. -PS C:\> Get-ScheduledJob -Name Backup-Archives, Inventory | Get-JobTrigger | Disable-JobTrigger + +```powershell +Get-ScheduledJob -Name Backup-Archives, Inventory | Get-JobTrigger | Disable-JobTrigger +``` The second command displays the results. The command repeats the **Get-ScheduledJob** and **Get-JobTrigger** command. A pipeline operator sends the job triggers to the Format-Table cmdlet, which displays the job triggers in a table. The **Format-Table** command adds a **JobName** property that displays the value of the **Name** property of the scheduled job in the **JobDefinition** property of the job trigger object. -PS C:\> Get-ScheduledJob -Name Backup-Archives, Inventory | Get-JobTrigger | Format-Table -Property ID, Frequency, At, DaysOfWeek, Enabled, @{Label="JobName";Expression={$_.JobDefinition.Name}} -AutoSize + +```powershell +Get-ScheduledJob -Name Backup-Archives, Inventory | Get-JobTrigger | Format-Table -Property ID, Frequency, At, DaysOfWeek, Enabled, @{Label="JobName";Expression={$_.JobDefinition.Name}} -AutoSize +``` + +```output Id Frequency At DaysOfWeek Enabled JobName -- --------- -- ---------- ------- ------- 1 Weekly 9/28/2011 3:00:00 AM {Monday} False Backup-Archive @@ -63,9 +77,11 @@ Id Frequency At DaysOfWeek Enabled JobName ``` These commands disable all job triggers on two scheduled jobs and display the results. + ### Example 3: Disable job trigger of a scheduled job on a remote computer. -``` -PS C:\> Invoke-Command -ComputerName Server01 {Get-JobTrigger -Name DeployPackage | Where-Object {$_.Frequency -eq "Daily"} | Disable-JobTrigger} + +```powershell +Invoke-Command -ComputerName Server01 {Get-JobTrigger -Name DeployPackage | Where-Object {$_.Frequency -eq "Daily"} | Disable-JobTrigger} ``` This command disables the daily job triggers on the DeployPackage scheduled job on the Server01 remote computer. @@ -74,9 +90,11 @@ The command uses the Invoke-Command cmdlet to run the commands on the Server01 c The remote command uses the Get-JobTrigger cmdlet to get the job triggers of the DeployPackage scheduled job. A pipeline operator sends the job triggers to the Where-Object cmdlet which returns only daily job triggers. A pipeline operator sends the daily job triggers to the **Disable-JobTrigger** cmdlets which disables them. + ## PARAMETERS ### -InputObject + Specifies the job trigger to be disabled. Enter a variable that contains **ScheduledJobTrigger** objects or type a command or expression that gets **ScheduledJobTriger** objects, such as a Get-JobTrigger command. You can also pipe a **ScheduledJobTrigger** object to **Disable-JobTrigger**. @@ -94,6 +112,7 @@ Accept wildcard characters: False ``` ### -Confirm + Prompts you for confirmation before running the cmdlet. ```yaml @@ -109,6 +128,7 @@ Accept wildcard characters: False ``` ### -WhatIf + Shows what would happen if the cmdlet runs. The cmdlet is not run. @@ -125,17 +145,25 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobTrigger + You can pipe job triggers to **Disable-JobTrigger**. + ## OUTPUTS ### None + This cmdlet does not generate any output. + ## NOTES -* **Disable-JobTrigger** does not generate errors or warnings if you disable a job trigger that is already disabled. + +- **Disable-JobTrigger** does not generate errors or warnings if you disable a job trigger that is already disabled. + ## RELATED LINKS [about_Scheduled_Jobs](About/about_Scheduled_Jobs.md) diff --git a/reference/3.0/PSScheduledJob/Disable-ScheduledJob.md b/reference/3.0/PSScheduledJob/Disable-ScheduledJob.md index 1a6014c06d44..82d999d325e4 100644 --- a/reference/3.0/PSScheduledJob/Disable-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Disable-ScheduledJob.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,29 +7,35 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223927 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Disable-ScheduledJob --- - # Disable-ScheduledJob + ## SYNOPSIS + Disables a scheduled job + ## SYNTAX ### Definition (Default) + ``` Disable-ScheduledJob [-InputObject] [-PassThru] [-WhatIf] [-Confirm] [] ``` ### DefinitionId + ``` Disable-ScheduledJob [-Id] [-PassThru] [-WhatIf] [-Confirm] [] ``` ### DefinitionName + ``` Disable-ScheduledJob [-Name] [-PassThru] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION + The **Disable-ScheduledJob** cmdlet temporarily disables scheduled jobs. Disabling preserves all job properties and does not disable the job triggers, but it prevents the scheduled jobs from starting automatically when triggered. You can start a disabled scheduled job by using the Start-Job cmdlet or use a disabled scheduled job as a template. @@ -43,11 +49,16 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Disable a scheduled job + +```powershell +Disable-ScheduledJob -Id 2 -Passthru ``` -PS C:\> Disable-ScheduledJob -ID 2 -Passthru + +```output Id Name Triggers Command Enabled -- ---- -------- ------- ------- 2 Inventory {1, 2} \\Srv01\Scripts\Get-FullInventory.ps1 False @@ -55,9 +66,14 @@ Id Name Triggers Command This command disables the scheduled job with ID 2 on the local computer. The output shows the effect of the command. + ### Example 2: Disable all scheduled jobs + +```powershell +Get-ScheduledJob | Disable-ScheduledJob -Passthru ``` -PS C:\> Get-ScheduledJob | Disable-ScheduledJob -Passthru + +```output Id Name Triggers Command Enabled -- ---- -------- ------- ------- 1 ArchiveProje... {} C:\Scripts\Archive-DxProjects.ps1 False @@ -72,9 +88,11 @@ It uses the Get-ScheduledJob cmdlet to get all scheduled job and the **Disable-S You can re-enable scheduled job by using the Enable-ScheduledJob cmdlet and run a disabled scheduled job by using the Start-Job cmdlet. **Disable-ScheduledJob** does not generate warnings or errors if you disable a scheduled job that is already disabled, so you can disable all scheduled jobs without conditions. + ### Example 3: Disable selected scheduled jobs -``` -PS C:\> Get-ScheduledJob | Where-Object {!$_.Credential} | Disable-ScheduledJob + +```powershell +Get-ScheduledJob | Where-Object {!$_.Credential} | Disable-ScheduledJob ``` This command disables scheduled job do not include a credential. @@ -84,19 +102,27 @@ The command uses the Get-ScheduledJob cmdlet to get all scheduled jobs on the co A pipeline operator sends the scheduled jobs to the Where-Object cmdlet, which selects scheduled jobs that do not have credentials. The command uses the not (!) operator and references the **Credential** property of the scheduled job. Another pipeline operator sends the selected scheduled jobs to the **Disable-ScheduledJob** cmdlet, which disables them. + ### Example 4: Disable scheduled jobs on a remote computer -``` -PS C:\> Invoke-Command -ComputerName Srv01, Srv10 -ScriptBlock {Disable-ScheduledJob -Name TestJob} + +```powershell +Invoke-Command -ComputerName Srv01, Srv10 -ScriptBlock {Disable-ScheduledJob -Name TestJob} ``` This command disables the TestJob scheduled job on two remote computers, Srv01 and Srv10. The command uses the Invoke-Command cmdlet to run a **Disable-ScheduledJob** command on the Srv01 and Srv10 computers. The command uses the **Name** parameter of **Disable-ScheduledJob** to select the TestJob scheduled job on each computer. + ### Example 5: Disable a scheduled job by its global ID -``` + The first command demonstrates one way of finding the GlobalID of a scheduled job. The command uses the Get-ScheduledJob cmdlet to get the scheduled jobs on the computer. A pipeline operator (|) sends the scheduled jobs to the Format-Table cmdlet which displays the **Name**, **GlobalID**, and **Command** properties of each job in a table. -PS C:\> Get-ScheduledJob | Format-Table -Property Name, GlobalID, Command -Autosize + +```powershell +Get-ScheduledJob | Format-Table -Property Name, GlobalID, Command -Autosize +``` + +```output Name GlobalId Command ---- -------- ------- ArchiveProjects1 a26a0b3d-b4e6-44d3-8b95-8706ef621f7c C:\Scripts\Archive-DxProjects.ps1 @@ -104,17 +130,22 @@ Inventory 3ac37e5d-84c0-4a8f-9661-7e88ebb8f914 \\Srv01\Scripts\Get-FullIn Backup-Scripts 4d0cc6be-c082-48d1-baec-1bd8278f3c81 Copy-Item C:\CurrentScripts\*.ps1 -Destination C:\BackupScripts Test-HelpFiles d77020ca-f20d-42be-86c8-fc64df97db90 .\Test-HelpFiles.ps1 Test-HelpFiles 2f1606d2-c6cf-4bef-8b1c-ae36a9cc9934 .\Test-DomainHelpFiles.ps1 +``` The second command uses the Get-ScheduledJob cmdlet to get the scheduled jobs on the computer. A pipeline operator (|) sends the scheduled jobs to the Where-Object cmdlet, which selects the scheduled job with the specified global ID. Another pipeline operator sends the job to the Disable-ScheduledJob cmdlet, which disables it. -PS C:\> Get-ScheduledJob | Where-Object {$_.GlobalID = d77020ca-f20d-42be-86c8-fc64df97db90} | Disable-ScheduledJob + +```powershell +Get-ScheduledJob | Where-Object {$_.GlobalID = d77020ca-f20d-42be-86c8-fc64df97db90} | Disable-ScheduledJob ``` This examples shows how to disable a scheduled job by using its global identifier. The value of the GlobalID property of a scheduled job is a unique identifier (GUID). Use the GlobalID value when precision is required, such as when you are disabling scheduled jobs on multiple computers. + ## PARAMETERS ### -Id + Disables the scheduled job with the specified identification number (ID). Enter the ID of a scheduled job. @@ -131,6 +162,7 @@ Accept wildcard characters: False ``` ### -InputObject + Specifies the scheduled job to be disabled. Enter a variable that contains **ScheduledJobDefinition** objects or type a command or expression that gets **ScheduledJobDefinition** objects, such as a Get-ScheduledJob command. You can also pipe a **ScheduledJobDefinition** object to **Disable-ScheduledJob**. @@ -148,6 +180,7 @@ Accept wildcard characters: False ``` ### -Name + Disables the scheduled jobs with the specified names. Enter the name of a scheduled job. Wildcards are supported. @@ -165,6 +198,7 @@ Accept wildcard characters: False ``` ### -PassThru + Returns the scheduled jobs that were disabled. By default, this cmdlet does not generate any output. @@ -181,6 +215,7 @@ Accept wildcard characters: False ``` ### -Confirm + Prompts you for confirmation before running the cmdlet. ```yaml @@ -196,6 +231,7 @@ Accept wildcard characters: False ``` ### -WhatIf + Shows what would happen if the cmdlet runs. The cmdlet is not run. @@ -212,18 +248,26 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition + You can pipe a scheduled job to **Disable-ScheduledJob**. + ## OUTPUTS ### None or Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition + If you use the **Passthru** parameter, **Disable-ScheduledJob** returns the scheduled job that was disabled. Otherwise, this cmdlet does not generate any output. + ## NOTES -* **Disable-ScheduledJob** does not generate warnings or errors if you use it to disable a scheduled job that is already disabled. + +- **Disable-ScheduledJob** does not generate warnings or errors if you use it to disable a scheduled job that is already disabled. + ## RELATED LINKS [about_Scheduled_Jobs](About/about_Scheduled_Jobs.md) diff --git a/reference/3.0/PSScheduledJob/Enable-JobTrigger.md b/reference/3.0/PSScheduledJob/Enable-JobTrigger.md index e8452256a737..bc8e7f627b97 100644 --- a/reference/3.0/PSScheduledJob/Enable-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/Enable-JobTrigger.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,10 +7,12 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223917 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Enable-JobTrigger --- - # Enable-JobTrigger + ## SYNOPSIS + Enables the job triggers of scheduled jobs + ## SYNTAX ``` @@ -18,6 +20,7 @@ Enable-JobTrigger [-InputObject] [-WhatIf] [-Confirm] [< ``` ## DESCRIPTION + The **Enable-JobTrigger** cmdlet re-enables job triggers of scheduled jobs, such as those that were disabled by using the Disable-JobTrigger cmdlet. Enabled and re-enabled job triggers can start scheduled jobs immediately; there is no need to restart Windows or Windows PowerShell. @@ -32,28 +35,34 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Enable a job trigger -``` -PS C:\> Get-JobTrigger -Name Backup-Archives -TriggerID 1 | Enable-JobTrigger + +```powershell +Get-JobTrigger -Name Backup-Archives -TriggerId 1 | Enable-JobTrigger ``` This command enables the first trigger (ID=1) of the Backup-Archives scheduled job on the local computer. The command uses the Get-JobTrigger cmdlet to get the job trigger. A pipeline operator sends the job trigger to the **Enable-JobTrigger** cmdlet, which enables it. + ### Example 2: Enable all job triggers -``` -PS C:\> Get-ScheduledJob | Get-JobTrigger | Enable-JobTrigger + +```powershell +Get-ScheduledJob | Get-JobTrigger | Enable-JobTrigger ``` The command uses the Get-ScheduledJob cmdlet to get the scheduled jobs on the local computer. A pipeline operator (|) sends the scheduled jobs to the Get-JobTrigger cmdlet, which gets all job triggers of the scheduled jobs. Another pipeline operator sends the job triggers to the **Enable-JobTrigger** cmdlet, which enables them. + ### Example 3: Enable the job trigger of a scheduled job on a remote computer. -``` -PS C:\> Invoke-Command -ComputerName Server01 {Get-JobTrigger -Name DeployPackage | Where-Object {$_.Frequency -eq "AtLogon"} | Enable-JobTrigger} + +```powershell +Invoke-Command -ComputerName Server01 {Get-JobTrigger -Name DeployPackage | Where-Object {$_.Frequency -eq "AtLogon"} | Enable-JobTrigger} ``` This command re-enables the AtLogon job triggers on the DeployPackage scheduled job on the Server01 remote computer. @@ -62,9 +71,14 @@ The command uses the Invoke-Command cmdlet to run the commands on the Server01 c The remote command uses the Get-JobTrigger cmdlet to get the job triggers of the DeployPackage scheduled job. A pipeline operator sends the job triggers to the Where-Object cmdlet which returns only AtLogon job triggers. A pipeline operator sends the AtLogon job triggers to the **Enable-JobTrigger** cmdlets which Enables them. + ### Example 4: Display disabled job triggers + +```powershell +Get-ScheduledJob | Get-JobTrigger | Where-Object {!$_.Enabled} | Format-Table Id, Frequency, At, DaysOfWeek, Enabled, @{Label="JobName";Expression={$_.JobDefinition.Name}} ``` -PS C:\> Get-ScheduledJob | Get-JobTrigger | where {!$_.Enabled} | Format-Table Id, Frequency, At, DaysOfWeek, Enabled, @{Label="JobName";Expression={$_.JobDefinition.Name}} + +```output Id Frequency At DaysOfWeek Enabled JobName -- --------- -- ---------- ------- ------- 1 Weekly 9/28/2011 3:00:00 AM {Monday} False Backup-Archive @@ -82,9 +96,11 @@ Another pipeline operator sends the job triggers to the Where-Object cmdlet, whi Another pipeline operator sends the disabled job triggers to the Format-Table cmdlet, which displays the selected properties of the job triggers in a table. The properties include a new **JobName** property that displays the name of the scheduled job in the **JobDefinition** property of the job trigger. + ## PARAMETERS ### -InputObject + Specifies the job trigger to be enabled. Enter a variable that contains **ScheduledJobTrigger** objects or type a command or expression that gets **ScheduledJobTriger** objects, such as a Get-JobTrigger command. You can also pipe a **ScheduledJobTrigger** object to **Enable-JobTrigger**. @@ -102,6 +118,7 @@ Accept wildcard characters: False ``` ### -Confirm + Prompts you for confirmation before running the cmdlet. ```yaml @@ -117,6 +134,7 @@ Accept wildcard characters: False ``` ### -WhatIf + Shows what would happen if the cmdlet runs. The cmdlet is not run. @@ -133,17 +151,25 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobTrigger + You can pipe job triggers to **Enable-JobTrigger**. + ## OUTPUTS ### None + This cmdlet does not generate any output. + ## NOTES -* **Enable-JobTrigger** does not generate errors or warnings if you enable a job trigger that is already enabled. + +- **Enable-JobTrigger** does not generate errors or warnings if you enable a job trigger that is already enabled. + ## RELATED LINKS [about_Scheduled_Jobs](About/about_Scheduled_Jobs.md) diff --git a/reference/3.0/PSScheduledJob/Enable-ScheduledJob.md b/reference/3.0/PSScheduledJob/Enable-ScheduledJob.md index d55689018bda..0baf0b381578 100644 --- a/reference/3.0/PSScheduledJob/Enable-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Enable-ScheduledJob.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,29 +7,35 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223926 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Enable-ScheduledJob --- - # Enable-ScheduledJob + ## SYNOPSIS + Enables a scheduled job + ## SYNTAX ### Definition (Default) + ``` Enable-ScheduledJob [-InputObject] [-PassThru] [-WhatIf] [-Confirm] [] ``` ### DefinitionId + ``` Enable-ScheduledJob [-Id] [-PassThru] [-WhatIf] [-Confirm] [] ``` ### DefinitionName + ``` Enable-ScheduledJob [-Name] [-PassThru] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION + The **Enable-ScheduledJob** cmdlet re-enables scheduled jobs that are disabled, such as those that are disabled by using the Disable-ScheduledJob cmdlet. Enabled jobs run automatically when triggered. @@ -41,11 +47,16 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Enable a scheduled job + +```powershell +Enable-ScheduledJob -Id 2 -Passthru ``` -PS C:\> Enable-ScheduledJob -ID 2 -Passthru + +```output Id Name Triggers Command Enabled -- ---- -------- ------- ------- 2 Inventory {1, 2} \\Srv01\Scripts\Get-FullInventory.ps1 True @@ -53,9 +64,14 @@ Id Name Triggers Command This command enables the scheduled job with ID 2 on the local computer. The output shows the effect of the command. + ### Example 2: Enable all scheduled jobs + +```powershell +Get-ScheduledJob | Enable-ScheduledJob -Passthru ``` -PS C:\> Get-ScheduledJob | Enable-ScheduledJob -Passthru + +```output Id Name Triggers Command Enabled -- ---- -------- ------- ------- 1 ArchiveProje... {} C:\Scripts\Archive-DxProjects.ps1 True @@ -68,9 +84,11 @@ This command enables all scheduled jobs on the local computer. It uses the Get-ScheduledJob cmdlet to get all scheduled job and the **Enable-ScheduledJob** cmdlet to enable them. **Enable-ScheduledJob** does not generate warnings or errors if you enable a scheduled job that is already enabled, so you can enable all scheduled jobs without conditions. + ### Example 3: Enable selected scheduled jobs -``` -PS C:\> Get-ScheduledJob | Get-ScheduledJobOption | Where-Object {$_.RunWithoutNetwork} | ForEach-Object {Enable-ScheduledJob -InputObject $_.JobDefinition} + +```powershell +Get-ScheduledJob | Get-ScheduledJobOption | Where-Object {$_.RunWithoutNetwork} | ForEach-Object {Enable-ScheduledJob -InputObject $_.JobDefinition} ``` This command enables scheduled jobs that do not require a network connection. @@ -82,18 +100,22 @@ The **JobDefinition** property is used to complete the command. The command uses a pipeline operator (|) to send the job options to the Where-Object cmdlet, which selects scheduled job option objects in which the **RunWithoutNetwork** property has a value of True ($true). Another pipeline operator sends the selected scheduled job options objects to the ForEach-Object cmdlet which runs an **Enable-ScheduledJob** command on the scheduled job in the value of the **JobDefinition** property of each job options object. + ### Example 4: Enable scheduled jobs on a remote computer -``` -PS C:\> Invoke-Command -ComputerName Srv01, Srv10 -ScriptBlock {Enable-ScheduledJob -Name Inventory} + +```powershell +Invoke-Command -ComputerName Srv01, Srv10 -ScriptBlock {Enable-ScheduledJob -Name Inventory} ``` This command enables scheduled jobs that have "test" in their names on two remote computers, Srv01 and Srv10. The command uses the Invoke-Command cmdlet to run an **Enable-ScheduledJob** command on the Srv01 and Srv10 computers. The command uses the **Name** parameter of **Enable-ScheduledJob** to enable the Inventory scheduled job on each computer. + ## PARAMETERS ### -Id + Enables the scheduled job with the specified identification number (ID). Enter the ID of a scheduled job. @@ -110,6 +132,7 @@ Accept wildcard characters: False ``` ### -InputObject + Specifies the scheduled job to be enabled. Enter a variable that contains **ScheduledJobDefinition** objects or type a command or expression that gets **ScheduledJobDefinition** objects, such as a Get-ScheduledJob command. You can also pipe a **ScheduledJobDefinition** object to **Enable-ScheduledJob**. @@ -127,6 +150,7 @@ Accept wildcard characters: False ``` ### -Name + Enables the scheduled jobs with the specified names. Enter the name of a scheduled job. Wildcards are supported. @@ -144,6 +168,7 @@ Accept wildcard characters: False ``` ### -PassThru + Returns the scheduled jobs that were enabled. By default, this cmdlet does not generate any output. @@ -160,6 +185,7 @@ Accept wildcard characters: False ``` ### -Confirm + Prompts you for confirmation before running the cmdlet. ```yaml @@ -175,6 +201,7 @@ Accept wildcard characters: False ``` ### -WhatIf + Shows what would happen if the cmdlet runs. The cmdlet is not run. @@ -191,18 +218,26 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition + You can pipe a scheduled job to **Enable-ScheduledJob**. + ## OUTPUTS ### None or Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition + If you use the **Passthru** parameter, **Enable-ScheduledJob** returns the scheduled job that was enabled. Otherwise, this cmdlet does not generate any output. + ## NOTES -* **Enable-ScheduledJob** does not generate warnings or errors if you use it to enable a scheduled job that is already enabled. + +- **Enable-ScheduledJob** does not generate warnings or errors if you use it to enable a scheduled job that is already enabled. + ## RELATED LINKS [about_Scheduled_Jobs](About/about_Scheduled_Jobs.md) diff --git a/reference/3.0/PSScheduledJob/Get-JobTrigger.md b/reference/3.0/PSScheduledJob/Get-JobTrigger.md index 96a2ad874901..b151bb8190d0 100644 --- a/reference/3.0/PSScheduledJob/Get-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/Get-JobTrigger.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,28 +7,34 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223915 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Get-JobTrigger --- - # Get-JobTrigger + ## SYNOPSIS + Gets the job triggers of scheduled jobs. + ## SYNTAX ### JobDefinition (Default) + ``` Get-JobTrigger [[-TriggerId] ] [-InputObject] [] ``` ### JobDefinitionId + ``` Get-JobTrigger [[-TriggerId] ] [-Id] [] ``` ### JobDefinitionName + ``` Get-JobTrigger [[-TriggerId] ] [-Name] [] ``` ## DESCRIPTION + The **Get-JobTrigger** cmdlet gets the job triggers of scheduled jobs. You can use this command to examine the job triggers or to pipe the job triggers to other cmdlets. @@ -45,39 +51,54 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Get a job trigger by scheduled job name -``` -PS C:\> Get-JobTrigger -Name BackupJob + +```powershell +Get-JobTrigger -Name BackupJob ``` The command uses the **Name** parameter of Get-JobTrigger to get the job triggers of the BackupJob scheduled job. + ### Example 2: Get a job trigger by ID -``` + The first command uses the Get-ScheduledJob cmdlet to display the scheduled jobs on the local computer. The display includes the IDs of the scheduled jobs. -PS C:\> Get-ScheduledJob + +```powershell +Get-ScheduledJob +``` + +```output Id Name Triggers Command Enabled -- ---- -------- ------- ------- 1 ArchiveProjects {1} \\Server\Share\Archive-Projects.ps1 True 2 Backup {1,2} \\Server\Share\Run-Backup.ps1 True 3 Test-HelpFiles {1} \\Server\Share\Test-HelpFiles.ps1 True 4 TestJob {} \\Server\Share\Run-AllTests.ps1 True +``` The second command uses the **Get-JobTrigger** cmdlet to get the job trigger for the Test-HelpFiles job (ID = 3) -PS C:\> Get-JobTrigger -ID 3 + +```powershell +Get-JobTrigger -Id 3 ``` The example uses the **ID** parameter of Get-JobTrigger to get the job triggers of a scheduled job. + ### Example 3: Get job triggers by piping a job -``` -PS C:\> Get-ScheduledJob -Name *Backup*, *Archive* | Get-JobTrigger + +```powershell +Get-ScheduledJob -Name *Backup*, *Archive* | Get-JobTrigger ``` This command gets the job triggers of all jobs that have "Backup" or "Archive" in their names. + ### Example 4: Get the job trigger of a job on a remote computer -``` -PS C:\> Invoke-Command -ComputerName Server01 { Get-ScheduledJob Backup | Get-JobTrigger -TriggerID 2 } + +```powershell +Invoke-Command -ComputerName Server01 { Get-ScheduledJob Backup | Get-JobTrigger -TriggerId 2 } ``` This command gets one of the two job triggers of a scheduled job on a remote computer. @@ -85,9 +106,14 @@ This command gets one of the two job triggers of a scheduled job on a remote com The command uses the Invoke-Command cmdlet to run a command on the Server01 computer. It uses the Get-ScheduledJob cmdlet to get the Backup scheduled job, which it pipes to the **Get-JobTrigger** cmdlet. It uses the TriggerID parameter to get only the second trigger. + ### Example 5: Get all job triggers + +```powershell +Get-ScheduledJob | Get-JobTrigger | Format-Table -Property ID, Frequency, At, DaysOfWeek, Enabled, @{Label="ScheduledJob";Expression={$_.JobDefinition.Name}} -AutoSize ``` -PS C:\> Get-ScheduledJob | Get-JobTrigger | For mat-Table -Property ID, Frequency, At, DaysOfWeek, Enabled, @{Label="ScheduledJob";Expression={$_.JobDefinition.Name}} -AutoSize + +```output Id Frequency At DaysOfWeek Enabled ScheduledJob -- --------- -- ---------- ------- ------------ 1 Weekly 9/28/2011 3:00:00 AM {Monday} True Backup @@ -100,34 +126,58 @@ The command uses the Get-ScheduledJob to get the scheduled jobs on the local com To add the name of the scheduled job to the job trigger display, the command uses the "calculated property" feature of the Format-Table cmdlet. In addition to the job trigger properties that are displayed by default, the command creates a new "ScheduledJob" property that displays the name of the scheduled job. + ### Example 6: Get the job trigger property of a scheduled job -``` + The command uses the Get-ScheduledJob cmdlet to get the Test-HelpFiles scheduled job. Then it uses the dot method (.) to get the **JobTriggers** property of the Test-HelpFiles scheduled job. -PS C:\> (Get-ScheduledJob Test-HelpFiles).JobTriggers + +```powershell +(Get-ScheduledJob Test-HelpFiles).JobTriggers +``` The second command uses the Get-ScheduledJob cmdlet to get all scheduled jobs on the local computer. It uses the Foreach-Object cmdlet to get the value of the JobTrigger property of each scheduled job. -PS C:\> Get-ScheduledJob | foreach {$_.JobTriggers} + +```powershell +Get-ScheduledJob | ForEach-Object {$_.JobTriggers} ``` The job triggers of a scheduled job are stored in the **JobTriggers** property of the job. This example shows alternatives to using the Get-JobTrigger cmdlet to get job triggers. The results are identical to using the **Get-JobTrigger** cmdlet and the techniques can be used interchangeably. + ### Example 7: Compare job triggers -``` + The first command gets the job trigger of the ArchiveProjects scheduled job. The command pipes the job trigger to the Tee-Object cmdlet, which saves the job trigger in the $t1 variable and displays it at the command line. -PS C:\> Get-ScheduledJob -Name ArchiveProjects | Get-JobTrigger | Tee-Object -Variable t1 + +```powershell +Get-ScheduledJob -Name ArchiveProjects | Get-JobTrigger | Tee-Object -Variable t1 +``` + +```output Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 0 Daily 9/26/2011 3:00:00 AM True +``` The second command gets the job trigger of the Test-HelpFiles scheduled job. The command pipes the job trigger to the Tee-Object cmdlet, which saves the job trigger in the $t2 variable and displays it at the command line. -PS C:\> Get-ScheduledJob -Name Test-HelpFiles | Get-JobTrigger | Tee-Object -Variable t2 + +```powershell +Get-ScheduledJob -Name Test-HelpFiles | Get-JobTrigger | Tee-Object -Variable t2 +``` + +```output Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 0 Daily 9/26/2011 3:00:00 AM True +``` The third command compares the job triggers in the $t1 and $t2 variables. It uses the Get-Member cmdlet to get the properties of the job trigger in the $t1 variable. It pipes the properties to the ForEach-Object cmdlet, which compares each property to the properties of the job trigger in the $t2 variable by name. The command then pipes the differing properties to the Format-List cmdlet, which displays them in a list.The output indicates that, although the job triggers appear to be the same, the HelpFiles job trigger includes a random delay of three (3) minutes. -PS C:\> $t1 | Get-Member -Type property | ForEach-Object { Compare-Object $t1 $t2 -Property $_.Name} + +```powershell +$t1 | Get-Member -MemberType property | ForEach-Object { Compare-Object $t1 $t2 -Property $_.Name} +``` + +```output RandomDelay SideIndicator ----------- ------------- 00:00:00 => @@ -135,9 +185,11 @@ RandomDelay SideIndicator ``` This example shows how to compare the job triggers of two scheduled jobs. + ## PARAMETERS ### -Id + Specifies the identification number of a scheduled job. **Get-JobTrigger** gets the job trigger of the specified scheduled job. @@ -156,6 +208,7 @@ Accept wildcard characters: False ``` ### -InputObject + Specifies a scheduled job. Enter a variable that contains **ScheduledJob** objects or type a command or expression that gets **ScheduledJob** objects, such as a Get-ScheduledJob command. You can also pipe **ScheduledJob** objects to **Get-JobTrigger**. @@ -173,6 +226,7 @@ Accept wildcard characters: False ``` ### -Name + Specifies the name of a scheduled job. **Get-JobTrigger** gets the job trigger of the specified scheduled job. Wildcards are supported. @@ -192,6 +246,7 @@ Accept wildcard characters: True ``` ### -TriggerId + Gets the specified job triggers. Enter the trigger IDs of one or more job triggers of a scheduled job. Use this parameter when the scheduled job that is specified by the **Name**, **ID**, or **InputObject** parameters has multiple job triggers. @@ -209,11 +264,15 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition + You can pipe a scheduled job from Get-ScheduledJob to **Get-JobTrigger**. + ## OUTPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobTrigger diff --git a/reference/3.0/PSScheduledJob/Get-ScheduledJob.md b/reference/3.0/PSScheduledJob/Get-ScheduledJob.md index 998ca83d8be6..3540674c3a8a 100644 --- a/reference/3.0/PSScheduledJob/Get-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Get-ScheduledJob.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,23 +7,28 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223923 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Get-ScheduledJob --- - # Get-ScheduledJob + ## SYNOPSIS + Gets scheduled jobs on the local computer. + ## SYNTAX ### DefinitionId (Default) + ``` Get-ScheduledJob [[-Id] ] [] ``` ### DefinitionName + ``` Get-ScheduledJob [-Name] [] ``` ## DESCRIPTION + The **Get-ScheduledJob** cmdlet gets scheduled jobs on the local computer. **Get-ScheduledJob** gets only scheduled jobs that are created by the current user using the Register-ScheduledJob cmdlet. @@ -39,38 +44,48 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Get all scheduled jobs -``` -PS C:\> Get-ScheduledJob + +```powershell +Get-ScheduledJob ``` This command gets all scheduled jobs on the local computer. + ### Example 2: Get scheduled jobs by name -``` -PS C:\> Get-ScheduledJob -Name *Backup*, *Archive* + +```powershell +Get-ScheduledJob -Name *Backup*, *Archive* ``` This command gets all scheduled jobs on the computer that have names that include "Backup" or "Archive". This command format lets you search for particular jobs. + ### Example 3: Get scheduled jobs on remote computers -``` -PS C:\> Invoke-Command -ComputerName (Get-Content Servers.txt) {Get-ScheduledJob} + +```powershell +Invoke-Command -ComputerName (Get-Content Servers.txt) {Get-ScheduledJob} ``` This command gets all scheduled jobs on the computers that are listed in the Servers.txt file. The command uses the Invoke-Command cmdlet to run a **Get-ScheduleJob** command on each computer. + ### Example 4: Pipe scheduled jobs to other cmdlets -``` -PS C:\> Get-ScheduledJob DailyBackup, WeeklyBackup | Get-JobTrigger + +```powershell +Get-ScheduledJob DailyBackup, WeeklyBackup | Get-JobTrigger ``` This command gets the job triggers of the DailyBackup and WeeklyBackup scheduled jobs. It uses the **Get-ScheduledJob** cmdlet to get the scheduled jobs and the Get-JobTrigger cmdlet to get the job triggers of the scheduled jobs. + ## PARAMETERS ### -Id + Gets only the scheduled jobs with the specified identification number (ID). Enter one or more IDs of scheduled jobs on the computer. By default, **Get-ScheduledJob** gets all scheduled jobs on the computer. @@ -88,6 +103,7 @@ Accept wildcard characters: False ``` ### -Name + Gets only the scheduled jobs with the specified names. Enter one or more names of scheduled jobs on the computer. Wildcards are supported. @@ -106,19 +122,25 @@ Accept wildcard characters: True ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### None + You cannot pipe input to **Get-ScheduledJob**. + ## OUTPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition ## NOTES -* Each scheduled job is saved in a subdirectory of the $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs directory on the local computer. The subdirectory is named for the scheduled job and contains the XML file for the scheduled job and records of its execution history. For more information about scheduled jobs on disk, see about_Scheduled_Jobs_Advanced. -* Scheduled jobs that you create in Windows PowerShell appear in Task Scheduler in the Task Scheduler Library\Microsoft\Windows\PowerShell\ScheduledJobs folder. You can use Task Scheduler to view and edit the scheduled job. -* You can use Task Scheduler, the SchTasks.exe command-line tool, and the Task Scheduler cmdlets to manage scheduled jobs that you create with the Scheduled Job cmdlets. However, you cannot use the Scheduled Job cmdlets to manage tasks that you create in Task Scheduler. + +- Each scheduled job is saved in a subdirectory of the $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs directory on the local computer. The subdirectory is named for the scheduled job and contains the XML file for the scheduled job and records of its execution history. For more information about scheduled jobs on disk, see about_Scheduled_Jobs_Advanced. +- Scheduled jobs that you create in Windows PowerShell appear in Task Scheduler in the Task Scheduler Library\Microsoft\Windows\PowerShell\ScheduledJobs folder. You can use Task Scheduler to view and edit the scheduled job. +- You can use Task Scheduler, the SchTasks.exe command-line tool, and the Task Scheduler cmdlets to manage scheduled jobs that you create with the Scheduled Job cmdlets. However, you cannot use the Scheduled Job cmdlets to manage tasks that you create in Task Scheduler. + ## RELATED LINKS [about_Scheduled_Jobs](About/about_Scheduled_Jobs.md) diff --git a/reference/3.0/PSScheduledJob/Get-ScheduledJobOption.md b/reference/3.0/PSScheduledJob/Get-ScheduledJobOption.md index 91557c382791..173daa02befe 100644 --- a/reference/3.0/PSScheduledJob/Get-ScheduledJobOption.md +++ b/reference/3.0/PSScheduledJob/Get-ScheduledJobOption.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,28 +7,34 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223920 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Get-ScheduledJobOption --- - # Get-ScheduledJobOption + ## SYNOPSIS + Gets the job options of scheduled jobs. + ## SYNTAX ### JobDefinition (Default) + ``` Get-ScheduledJobOption [-InputObject] [] ``` ### JobDefinitionId + ``` Get-ScheduledJobOption [-Id] [] ``` ### JobDefinitionName + ``` Get-ScheduledJobOption [-Name] [] ``` ## DESCRIPTION + The **Get-ScheduledJobOption** cmdlet gets the job options of scheduled jobs. You can use this command to examine the job options or to pipe the job options to other cmdlets. @@ -44,11 +50,16 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Get job options + +```powershell +Get-ScheduledJobOption -Name *Backup* ``` -PS C:\> Get-ScheduledJobOption -Name *Backup* + +```output StartIfOnBatteries : False StopIfGoingOnBatteries : True @@ -80,19 +91,27 @@ NewJobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinitio This command gets the job options of scheduled jobs that have "BackUp" in their names. The results show the job options object that **Get-ScheduledJobOption** returned. + ### Example 2: Get all job options -``` -PS C:\> Get-ScheduledJob | Get-ScheduledJobOptions + +```powershell +Get-ScheduledJob | Get-ScheduledJobOption ``` This command gets the job options of all scheduled jobs on the local computer. It uses the Get-ScheduledJob cmdlet to get the scheduled jobs on the local computer. -A pipeline operator (|) sends the scheduled jobs to the **Get-ScheduledJobOptions** cmdlet, which gets the job options of each scheduled job. +A pipeline operator (|) sends the scheduled jobs to the **Get-ScheduledJobOption** cmdlet, which gets the job options of each scheduled job. + ### Example 3: Get selected job options -``` + The first command gets job options in which the **RunElevated** property has a value of "True" ($true) and the **RunWithoutNetwork** property has a value of "False" ($false) The output shows the job options object that was selected. -PS C:\> Get-ScheduledJob | Get-ScheduledJobOption | Where {$_.RunElevated -and !$_.WaketoRun} + +```powershell +Get-ScheduledJob | Get-ScheduledJobOption | Where-Object {$_.RunElevated -and !$_.WaketoRun} +``` + +```output StartIfOnBatteries : False StopIfGoingOnBatteries : True @@ -120,41 +139,50 @@ DoNotAllowDemandStart : False MultipleInstancePolicy : Ignore NewJobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition +``` The second command shows how to find to which scheduled job the job options belong. This command uses a pipeline operator (|) to send the selected job options to the ForEach-Object cmdlet which gets the **JobDefinition** property of each options object. The **JobDefinition** property contains the originating job object. The results show that the selected options came from the "DeployPkg" scheduled job. -PS C:\> Get-ScheduledJob | Get-ScheduledJobOption | Where {$_.RunElevated -and !$_.WaketoRun} | ForEach-Object {$_.JobDefinition} -Id Name Triggers Command Enabled --- ---- -------- ------- ------- +```powershell +Get-ScheduledJob | Get-ScheduledJobOption | Where-Object {$_.RunElevated -and !$_.WaketoRun} | ForEach-Object {$_.JobDefinition} +``` +```output +Id Name Triggers Command Enabled +-- ---- -------- ------- ------- 2 DeployPkg {1, 2} DeployPackage.ps1 True ``` This example shows how to find job options object with particular values. + ### Example 4: Use job options to create a new job -``` -PS C:\> $Opts = Get-ScheduledJobOption -Name BackupTestLogs -PS C:\> Register-ScheduledJob -Name Archive-Scripts -FilePath \\Srv01\Scripts\ArchiveScripts.ps1 -ScheduledJobOption $Opts +```powershell +$Opts = Get-ScheduledJobOption -Name BackupTestLogs +Register-ScheduledJob -Name Archive-Scripts -FilePath \\Srv01\Scripts\ArchiveScripts.ps1 -ScheduledJobOption $Opts ``` -This example shows how to use the job options that Get-ScheduledJobOptions gets in a new scheduled job. +This example shows how to use the job options that Get-ScheduledJobOption gets in a new scheduled job. -The first command uses **Get-ScheduledJobOptions** to get the jobs options of the BackupTestLogs scheduled job. +The first command uses **Get-ScheduledJobOption** to get the jobs options of the BackupTestLogs scheduled job. The command saves the options in the $Opts variable. The second command uses Register-ScheduledJob cmdlet to create a new scheduled job. The value of the **ScheduledJobOption** parameter is the options object in the $Opts variable. + ### Example 5: Get job options from a remote computer -``` -PS C:\> $o = Invoke-Command -ComputerName Srv01 -ScriptBlock {Get-ScheduledJob -Name DataDemon } + +```powershell +$o = Invoke-Command -ComputerName Srv01 -ScriptBlock {Get-ScheduledJob -Name DataDemon } ``` This command uses the Invoke-Command cmdlet to get the scheduled job options of the DataDemon job on the Srv01 computer. The command saves the options in the $o variable. + ## PARAMETERS ### -Id + Specifies the identification number of a scheduled job. **Get-ScheduledJobOption** gets the job options of the specified scheduled job. @@ -173,6 +201,7 @@ Accept wildcard characters: False ``` ### -InputObject + Specifies a scheduled job. Enter a variable that contains a **ScheduledJob** object or type a command or expression that gets a **ScheduledJob** object, such as a Get-ScheduledJob command. You can also pipe a **ScheduledJob** object to **Get-ScheduledJobOption**. @@ -190,6 +219,7 @@ Accept wildcard characters: False ``` ### -Name + Specifies the names of scheduled jobs. **Get-ScheduledJobOption** gets the job options of the specified scheduled job. Wildcards are supported. @@ -209,11 +239,15 @@ Accept wildcard characters: True ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition + You can pipe a scheduled job from Get-ScheduledJob to **Get-ScheduledJobOption**. + ## OUTPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobOptions diff --git a/reference/3.0/PSScheduledJob/New-JobTrigger.md b/reference/3.0/PSScheduledJob/New-JobTrigger.md index 6c99bf3f3ec4..5e7816eb19df 100644 --- a/reference/3.0/PSScheduledJob/New-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/New-JobTrigger.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,40 +7,48 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223912 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: New-JobTrigger --- - # New-JobTrigger + ## SYNOPSIS + Creates a job trigger for a scheduled job + ## SYNTAX ### Once (Default) + ``` New-JobTrigger [-RandomDelay ] -At [-Once] [-RepetitionInterval ] [-RepetitionDuration ] [] ``` ### Daily + ``` New-JobTrigger [-DaysInterval ] [-RandomDelay ] -At [-Daily] [] ``` ### Weekly + ``` New-JobTrigger [-WeeksInterval ] [-RandomDelay ] -At -DaysOfWeek [-Weekly] [] ``` ### AtLogon + ``` New-JobTrigger [-RandomDelay ] [-User ] [-AtLogOn] [] ``` ### AtStartup + ``` New-JobTrigger [-RandomDelay ] [-AtStartup] [] ``` ## DESCRIPTION + The **New-JobTrigger** cmdlet creates a "job trigger" that starts a scheduled job on a one-time or recurring schedule, or when an event occurs. You can use the **ScheduledJobTrigger** object that **New-JobTrigger** returns to set a job trigger for a new or existing scheduled job. @@ -55,20 +63,27 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Once Schedule -``` -PS C:\> New-JobTrigger -Once -At "1/20/2012 3:00 AM" + +```powershell +New-JobTrigger -Once -At "1/20/2012 3:00 AM" ``` This command uses the **New-JobTrigger** cmdlet to create a job trigger that starts a scheduled job only one time. The value of the **At** parameter is a string that Windows PowerShell converts into a **DateTime** object. The **At** parameter value includes an explicit date, not just a time. If the date were omitted, the trigger would be created with the current date and 3:00 AM time, which is likely to represent a time in the past. + ### Example 2: Daily Schedule + +```powershell +New-JobTrigger -Daily -At "4:15 AM" -DaysInterval 3 ``` -PS C:\> New-JobTrigger -Daily -At "4:15 AM" -DaysInterval 3 + +```output Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 0 Daily 9/21/2012 4:15:00 AM True @@ -78,9 +93,14 @@ This command creates a job trigger that starts a scheduled job every 3 days at 4 Because the value of the **At** parameter does not include a date, the current date is used as the date value in the **DateTime** object. If the date and time is in the past, the scheduled job is started at the next occurrence, which is 3 days later from the **At** parameter value. + ### Example 3: Weekly Schedule + +```powershell +New-JobTrigger -Weekly -DaysOfWeek Monday, Wednesday, Friday -At "23:00" -WeeksInterval 4 ``` -PS C:\> New-JobTrigger -Weekly -DaysOfWeek Monday, Wednesday, Friday -At "23:00" -WeeksInterval 4 + +```output Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 0 Weekly 9/21/2012 11:00:00 PM {Monday, Wednesday, Friday} True @@ -89,15 +109,19 @@ Id Frequency Time DaysOfWeek Enabled This command creates a job trigger that starts a scheduled job every 4 weeks on Monday, Wednesday, and Friday at 2300 hours (11:00 PM). You can also enter the **DaysOfWeek** parameter value in integers, such as "`-DaysOfWeek 1, 5`". + ### Example 4: Logon Schedule -``` -PS C:\> New-JobTrigger -AtLogOn -User Domain01\Admin01 + +```powershell +New-JobTrigger -AtLogOn -User Domain01\Admin01 ``` This command creates a job trigger that starts a scheduled job whenever the domain administrator logs onto the computer. + ### Example 5: Using a Random Delay -``` -PS C:\> New-JobTrigger -Daily -At 1:00 -RandomDelay 00:20:00 + +```powershell +New-JobTrigger -Daily -At 1:00 -RandomDelay 00:20:00 ``` This command creates a job trigger that starts a scheduled job every day at 1:00 in the morning. @@ -106,20 +130,27 @@ As a result, the job runs every day between 1:00 AM and 1:20 AM, with the interv You can use a random delay for sampling, load balancing, and other administrative tasks. When setting the delay value, review the effective and default values of the New-ScheduledJobOption cmdlet and coordinate the delay with the option settings. + ### Example 6: Create a Job Trigger for a New Scheduled Job -``` + The first command uses the **New-JobTrigger** cmdlet to create a job trigger that starts a job every Monday, Wednesday, and Friday at 12:01 a.m. The command saves the job trigger in the $t variable. -PS C:\> $t = New-JobTrigger -Weekly -DaysOfWeek 1,3,5 -At 12:01AM +```powershell +$t = New-JobTrigger -Weekly -DaysOfWeek 1,3,5 -At 12:01AM +``` The second command uses the Register-ScheduledJob cmdlet to create a scheduled job that starts a job every Monday, Wednesday, and Friday at 12:01 a.m. The value of the **Trigger** parameter is the trigger that is stored in the $t variable. -PS C:\> Register-ScheduledJob -Name Test-HelpFiles -FilePath C:\Scripts\Test-HelpFiles.ps1 -Trigger $t + +```powershell +Register-ScheduledJob -Name Test-HelpFiles -FilePath C:\Scripts\Test-HelpFiles.ps1 -Trigger $t ``` These commands use a job trigger to create a new scheduled job. + ### Example 7: Add a Job Trigger to a Scheduled Job -``` -PS C:\> Add-JobTrigger -Name SynchronizeApps -Trigger (New-JobTrigger -Daily -At 3:10AM) + +```powershell +Add-JobTrigger -Name SynchronizeApps -Trigger (New-JobTrigger -Daily -At 3:10AM) ``` This example shows how to add a job trigger to an existing scheduled job. @@ -129,30 +160,38 @@ The command uses the Add-JobTrigger cmdlet to add the job trigger to the Synchro The value of the **Trigger** parameter is a **New-JobTrigger** command that runs the job every day at 3:10 AM. When the command completes, SynchronizeApps is a scheduled job that runs at the times specified by the job trigger. + ### Example 8: Create a repeating job trigger -``` -PS C:\> New-JobTrigger -Once -At "09/12/2013 1:00:00" -RepetitionInterval (New-TimeSpan -Hours 1) -RepetitionDuration (New-Timespan -Hours 48) + +```powershell +New-JobTrigger -Once -At "09/12/2013 1:00:00" -RepetitionInterval (New-TimeSpan -Hours 1) -RepetitionDuration (New-TimeSpan -Hours 48) ``` This command creates a job trigger that runs a job every 60 minutes for 48 hours beginning on September 12, 2013 at 1:00 a.m. + ### Example 9: Stop a repeating job trigger -``` -PS C:\> Get-JobTrigger -Name SecurityCheck | Set-JobTrigger -RepetitionInterval 0:00 -RepetitionDuration 0:00 + +```powershell +Get-JobTrigger -Name SecurityCheck | Set-JobTrigger -RepetitionInterval 0:00 -RepetitionDuration 0:00 ``` This command forcibly stops the SecurityCheck job, which is triggered to run every 60 minutes until its job trigger expires. To prevent the job from repeating, the command uses the Get-JobTrigger to get the job trigger of the SecurityCheck job and the Set-JobTrigger cmdlet to change the repetition interval and repetition duration of the job trigger to zero (0). + ### Example 10: Create an hourly job trigger -``` -PS C:\> New-JobTrigger -Once -At "9/21/2012 0am" -RepetitionInterval (New-TimeSpan -Hour 12) -RepetitionDuration ([TimeSpan]::MaxValue) + +```powershell +New-JobTrigger -Once -At "9/21/2012 0am" -RepetitionInterval (New-TimeSpan -Hours 12) -RepetitionDuration ([TimeSpan]::MaxValue) ``` The following command creates a job trigger that runs a scheduled job once every 12 hours for an indefinite period of time. The schedule begins tomorrow (9/21/2012) at midnight (0:00 AM). + ## PARAMETERS ### -At + Starts the job at the specified date and time. Enter a **DateTime** object, such as one that the Get-Date cmdlet returns, or a string that can be converted to a date and time, such as "April 19, 2012 15:00", "12/31", or "3am". If you don't specify an element of the date, such as the year, the date in the trigger has the corresponding element from the current date. @@ -175,6 +214,7 @@ Accept wildcard characters: False ``` ### -AtLogOn + Starts the scheduled job when the specified users log on to the computer. To specify a user, use the **User** parameter. @@ -191,6 +231,7 @@ Accept wildcard characters: False ``` ### -AtStartup + Starts the scheduled job when Windows starts. ```yaml @@ -206,6 +247,7 @@ Accept wildcard characters: False ``` ### -Daily + Specifies a recurring daily job schedule. Use the other parameters in the Daily parameter set to specify the schedule details. @@ -222,6 +264,7 @@ Accept wildcard characters: False ``` ### -DaysInterval + Specifies the number of days between occurrences on a daily schedule. For example, a value of 3 starts the scheduled job on days 1, 4, 7 and so on. The default value is 1. @@ -239,6 +282,7 @@ Accept wildcard characters: False ``` ### -DaysOfWeek + Specifies the days of the week on which a weekly scheduled job runs. Enter day names, such as "Monday" or integers 0-6, where 0 represents Sunday. This parameter is required in the Weekly parameter set. @@ -261,6 +305,7 @@ Accept wildcard characters: False ``` ### -Once + Specifies a non-recurring (one time) or custom repeating schedule. To create a repeating schedule, use the **Once** parameter with the **RepetitionDuration** and **RepetitionInterval** parameters. @@ -277,6 +322,7 @@ Accept wildcard characters: False ``` ### -RandomDelay + Enables a random delay that begins at the scheduled start time, and sets the maximum delay value. The length of the delay is set pseudo-randomly for each start and varies from no delay to the time specified by the value of this parameter. The default value, zero (00:00:00), disables the random delay. @@ -296,6 +342,7 @@ Accept wildcard characters: False ``` ### -RepetitionDuration + Repeats the job until the specified time expires. The repetition frequency is determined by the value of the **RepetitionInterval** parameter. For example, if the value of **RepetitionInterval** is 5 minutes and the value of **RepetitionDuration** is 2 hours, the job is triggered every five minutes for two hours. @@ -321,6 +368,7 @@ Accept wildcard characters: False ``` ### -RepetitionInterval + Repeats the job at the specified time interval. For example, if the value of this parameter is 2 hours, the job is triggered every two hours. The default value, 0, does not repeat the job. @@ -342,6 +390,7 @@ Accept wildcard characters: False ``` ### -User + Specifies the users who trigger an **AtLogon** start of a scheduled job. Enter the name of a user in \ or \ format or enter an asterisk (*) to represent all users. The default value is all users. @@ -359,6 +408,7 @@ Accept wildcard characters: False ``` ### -Weekly + Specifies a recurring weekly job schedule. Use the other parameters in the Weekly parameter set to specify the schedule details. @@ -375,6 +425,7 @@ Accept wildcard characters: False ``` ### -WeeksInterval + Specifies the number of weeks between occurrences on a weekly job schedule. For example, a value of 3 starts the scheduled job on weeks 1, 4, 7 and so on. The default value is 1. @@ -392,19 +443,24 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### None + You cannot pipe input to this cmdlet. + ## OUTPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobTrigger ## NOTES -* Job triggers are not saved to disk. However, scheduled jobs are saved to disk, and you can use the Get-JobTrigger to get the job trigger of any scheduled job. -* **New-JobTrigger** does not prevent you from creating a job trigger that will not run a scheduled job, such as one-time trigger for a date in the past. -* The Register-ScheduledJob cmdlet accepts a ScheduledJobTrigger object, such as one returned by the **New-JobTrigger** or Get-JobTrigger cmdlets, or a hash table with trigger values. + +- Job triggers are not saved to disk. However, scheduled jobs are saved to disk, and you can use the Get-JobTrigger to get the job trigger of any scheduled job. +- **New-JobTrigger** does not prevent you from creating a job trigger that will not run a scheduled job, such as one-time trigger for a date in the past. +- The Register-ScheduledJob cmdlet accepts a ScheduledJobTrigger object, such as one returned by the **New-JobTrigger** or Get-JobTrigger cmdlets, or a hash table with trigger values. To submit a hash table, use the following keys. @@ -414,6 +470,7 @@ Interval=2 (or any valid frequency interval); RandomDelay="30minutes" (or any valid timespan string); User="Domain1\User01 (or any valid user; used only with the AtLogon frequency value) } + ## RELATED LINKS [about_Scheduled_Jobs](About/about_Scheduled_Jobs.md) diff --git a/reference/3.0/PSScheduledJob/New-ScheduledJobOption.md b/reference/3.0/PSScheduledJob/New-ScheduledJobOption.md index 294fae447f5c..457c20df07d3 100644 --- a/reference/3.0/PSScheduledJob/New-ScheduledJobOption.md +++ b/reference/3.0/PSScheduledJob/New-ScheduledJobOption.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,10 +7,12 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223919 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: New-ScheduledJobOption --- - # New-ScheduledJobOption + ## SYNOPSIS + Creates an object that contains advanced options for a scheduled job. + ## SYNTAX ``` @@ -21,6 +23,7 @@ New-ScheduledJobOption [-RunElevated] [-HideInTaskScheduler] [-RestartOnIdleResu ``` ## DESCRIPTION + The **New-ScheduledJobOption** cmdlet creates an object that contains advanced options for a scheduled job. You can use the **ScheduledJobOptions** object that **New-ScheduledJobOption** returns to set job options for a new or existing scheduled job. @@ -38,11 +41,16 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Create a scheduled job option object with default values + +```powershell +New-ScheduledJobOption ``` -PS C:\> New-ScheduledJobOption + +```output StartIfOnBatteries : False StopIfGoingOnBatteries : True WakeToRun : False @@ -60,9 +68,14 @@ NewJobDefinition : ``` This command creates a scheduled job option object that has all of the default values. + ### Example 2: Create a scheduled job option object with custom values + +```powershell +New-ScheduledJobOption -RequireNetwork -StartIfOnBattery ``` -PS C:\> New-ScheduledJobOption -RequireNetwork -StartIfOnBattery + +```output StartIfOnBatteries : True StopIfGoingOnBatteries : True WakeToRun : False @@ -82,16 +95,28 @@ NewJobDefinition : The following command creates a scheduled job object that requires the network and runs the scheduled job even if the computer is not connected to AC power. The output shows that the **RequireNetwork** parameter changed the value of the **RunWithoutNetwork** property to false and the **StartIfOnBattery** parameter changed the value of the **StartIfOnBatteries** property to True. + ### Example 3: Set options for a new scheduled job -``` + The first command creates a **ScheduledJobOptions** object with the **RunElevated** parameter. It saves the object in the $RunAsAdmin variable. -PS C:\> $RunAsAdmin = New-ScheduledJobOption -RunElevated + +```powershell +$RunAsAdmin = New-ScheduledJobOption -RunElevated +``` The second command uses the Register-ScheduledJob cmdlet to create a new scheduled job. The value of the **ScheduledJobOption** parameter is the option object in the value of the $RunAsAdmin variable. -PS C:\> Register-ScheduledJob -Name Backup -FilePath D:\Scripts\Backup.ps1 -Trigger $Mondays -ScheduledJobOption $RunAsAdmin + +```powershell +Register-ScheduledJob -Name Backup -FilePath D:\Scripts\Backup.ps1 -Trigger $Mondays -ScheduledJobOption $RunAsAdmin +``` The third command uses the Get-ScheduledJobOption cmdlet to get the job options of the Backup scheduled job.The cmdlet output shows that the **RunElevated** property is set to True and the **JobDefinition** property of the job option object is now populated with the scheduled job object for the Backup scheduled job. -PS C:\> Get-ScheduledJobOption -Name Backup + +```powershell +Get-ScheduledJobOption -Name Backup +``` + +```output StartIfOnBatteries : False StopIfGoingOnBatteries : True WakeToRun : False @@ -108,11 +133,15 @@ JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinitio ``` This example shows how to use the **ScheduledJobOptions** object that **New-ScheduledJobOption** returns to set the options for a new scheduled job. + ### Example 4: Sort the properties of a scheduled job option object + +```powershell +$Options = New-ScheduledJobOption -WakeToRun +$Options.PSObject.Properties | Sort-Object -Property Name | Format-Table -Property Name, Value -Autosize ``` -PS C:\> $Options = New-ScheduledJobOption -WakeToRun -PS C:\> $Options.PSObject.Properties | Sort-Object -Property Name | Format-Table -Property Name, Value -Autosize +```output Name Value ---- ----- DoNotAllowDemandStart False @@ -140,9 +169,11 @@ To get the properties of $Options as objects, the second command uses the **PSOb The command then pipes the property objects to the Sort-Object cmdlet, which sorts the properties in alphabetical order by name, and then to the Format-Table cmdlet, which displays the names and values of the properties in a table. This format makes it much easier to find the **WakeToRun** property of the **ScheduledJobOptions** object in $Options and to verify that its value was changed from False to True. + ## PARAMETERS ### -ContinueIfGoingOnBattery + Do not stop the scheduled job if the computer switches to battery power (disconnects from AC power) while the job is running. By default, scheduled jobs stop when the computer disconnects from AC power. @@ -161,6 +192,7 @@ Accept wildcard characters: False ``` ### -DoNotAllowDemandStart + Start the job only when it is triggered. Users cannot start the job manually, such as by using the Run feature in Task Scheduler. @@ -182,6 +214,7 @@ Accept wildcard characters: False ``` ### -HideInTaskScheduler + Do not display the job in Task Scheduler. This value affects only the computer on which the job runs. By default, scheduled tasks appear in Task Scheduler. @@ -203,6 +236,7 @@ Accept wildcard characters: False ``` ### -IdleDuration + Specifies how long the computer must be idle before the job starts. The default value is 10 minutes. If the computer is not idle for the specified duration before the value of **IdleTimeout** expires, the scheduled job does not run until the next scheduled time, if any. @@ -225,6 +259,7 @@ Accept wildcard characters: False ``` ### -IdleTimeout + Specifies how long the scheduled job waits for the computer to be idle. If this timeout expires before the computer remains idle for the time period that is specified by the **IdleDuration** parameter, the job does not run until the next scheduled time, if any. The default value is one hour. @@ -247,6 +282,7 @@ Accept wildcard characters: False ``` ### -MultipleInstancePolicy + Determines how the system responds to a request to start an instance of a scheduled job while another instance of the job is running. The default value is **IgnoreNew**. @@ -273,6 +309,7 @@ Accept wildcard characters: False ``` ### -RequireNetwork + Runs the scheduled job only when network connections are available. If you specify this parameter and the network is not available at the scheduled start time, the job does not run until the next scheduled start time, if any. @@ -292,6 +329,7 @@ Accept wildcard characters: False ``` ### -RestartOnIdleResume + Restarts a scheduled job when the computer becomes idle. This parameter works with the **StopIfGoingOffIdle** parameter, which suspends a running scheduled job if the computer becomes active (leaves the idle state). @@ -310,6 +348,7 @@ Accept wildcard characters: False ``` ### -RunElevated + Runs the scheduled job with the permissions of a member of the Administrators group on the computer on which the job runs. To enable a scheduled job to run with Administrator permissions, use the **Credential** parameter of Register-ScheduledJob to provide explicit credential for the job. @@ -329,6 +368,7 @@ Accept wildcard characters: False ``` ### -StartIfIdle + Starts the scheduled job if the computer has been idle for the time specified by the **IdleDuration** parameter before the time specified by the **IdleTimeout** parameter expires. By default, the **IdleDuration** and **IdleTimeout** parameters are ignored and the job starts at the scheduled start time even if the computer is busy. @@ -350,6 +390,7 @@ Accept wildcard characters: False ``` ### -StartIfOnBattery + Starts the scheduled job even if the computer is running on batteries at the scheduled start time. The default value is False. @@ -368,6 +409,7 @@ Accept wildcard characters: False ``` ### -StopIfGoingOffIdle + Suspends a running scheduled job if the computer becomes active (not idle) while the job is running. By default, a scheduled job that is suspended when the computer becomes active resumes when the computer becomes idle again. @@ -388,6 +430,7 @@ Accept wildcard characters: False ``` ### -WakeToRun + Wakes the computer from a Hibernate or Sleep state at the scheduled start time so it can run the job. By default, if the computer is in a Hibernate or Sleep state at the scheduled start time, the job does not run. @@ -406,21 +449,27 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### None + You cannot pipe input to this cmdlet. + ## OUTPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobOptions ## NOTES -* You can use the **ScheduledJobOptions** object that **New-ScheduledJobOption** creates as the value of the **ScheduledJobOption** parameter of the Register-ScheduledJob cmdlet. However, the **ScheduledJobOption** parameter can also take a hash table value that specifies the properties of the ScheduledJobOptions object and their values, such as: + +- You can use the **ScheduledJobOptions** object that **New-ScheduledJobOption** creates as the value of the **ScheduledJobOption** parameter of the Register-ScheduledJob cmdlet. However, the **ScheduledJobOption** parameter can also take a hash table value that specifies the properties of the ScheduledJobOptions object and their values, such as: `@{ShowInTaskScheduler=$False; RunElevated=$True; IdleDuration="00:05"}` For more information, see Register-ScheduledJob. + ## RELATED LINKS [about_Scheduled_Jobs](About/about_Scheduled_Jobs.md) diff --git a/reference/3.0/PSScheduledJob/PSScheduledJob.md b/reference/3.0/PSScheduledJob/PSScheduledJob.md index aa1e109df581..74ecc77ab036 100644 --- a/reference/3.0/PSScheduledJob/PSScheduledJob.md +++ b/reference/3.0/PSScheduledJob/PSScheduledJob.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -9,71 +9,89 @@ Module Guid: 50cdb55f-5ab7-489f-9e94-4ec21ff51e59 title: PSScheduledJob Module Name: PSScheduledJob --- - # PSScheduledJob Module + ## Description + This section contains the help topics for the cmdlets that are installed with Windows PowerShell PSScheduledJob module. The PSScheduledJob module contains cmdlets and providers that manage scheduled jobs in Windows PowerShell. ## PSScheduledJob Cmdlets + ### [Add-JobTrigger](Add-JobTrigger.md) + Adds job triggers to scheduled jobs ### [Disable-JobTrigger](Disable-JobTrigger.md) + Disables the job triggers of scheduled jobs ### [Disable-ScheduledJob](Disable-ScheduledJob.md) + Disables a scheduled job ### [Enable-JobTrigger](Enable-JobTrigger.md) + Enables the job triggers of scheduled jobs ### [Enable-ScheduledJob](Enable-ScheduledJob.md) + Enables a scheduled job ### [Get-JobTrigger](Get-JobTrigger.md) + Gets the job triggers of scheduled jobs. ### [Get-ScheduledJobOption](Get-ScheduledJobOption.md) + Gets the job options of scheduled jobs. ### [Get-ScheduledJob](Get-ScheduledJob.md) + Gets scheduled jobs on the local computer. ### [New-JobTrigger](New-JobTrigger.md) + Creates a job trigger for a scheduled job ### [New-ScheduledJobOption](New-ScheduledJobOption.md) + Creates an object that contains advanced options for a scheduled job. ### [Register-ScheduledJob](Register-ScheduledJob.md) + Creates a new scheduled job. ### [Remove-JobTrigger](Remove-JobTrigger.md) + Delete job triggers from scheduled jobs ### [Set-JobTrigger](Set-JobTrigger.md) + Changes the job trigger of a scheduled job. ### [Set-ScheduledJobOption](Set-ScheduledJobOption.md) + Changes the job options of a scheduled job. ### [Set-ScheduledJob](Set-ScheduledJob.md) + Changes scheduled jobs ### [Unregister-ScheduledJob](Unregister-ScheduledJob.md) + Deletes scheduled jobs on the local computer. \ No newline at end of file diff --git a/reference/3.0/PSScheduledJob/Register-ScheduledJob.md b/reference/3.0/PSScheduledJob/Register-ScheduledJob.md index f25e47dc3541..d1a2ef121e83 100644 --- a/reference/3.0/PSScheduledJob/Register-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Register-ScheduledJob.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,13 +7,16 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223922 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Register-ScheduledJob --- - # Register-ScheduledJob + ## SYNOPSIS + Creates a new scheduled job. + ## SYNTAX ### ScriptBlock (Default) + ``` Register-ScheduledJob [-ScriptBlock] [-Name] [-Trigger ] [-InitializationScript ] [-RunAs32] [-Credential ] @@ -22,6 +25,7 @@ Register-ScheduledJob [-ScriptBlock] [-Name] [-Trigger [-Name] [-Trigger ] [-InitializationScript ] [-RunAs32] [-Credential ] @@ -30,6 +34,7 @@ Register-ScheduledJob [-FilePath] [-Name] [-Trigger Register-ScheduledJob -Name Archive-Scripts -ScriptBlock { dir $home\*.ps1 -Recurse | Copy-Item -Destination \\Server\Share\PSScriptArchive } + +```powershell +Register-ScheduledJob -Name Archive-Scripts -ScriptBlock { dir $home\*.ps1 -Recurse | Copy-Item -Destination \\Server\Share\PSScriptArchive } ``` This command creates the Archive-Scripts scheduled job. @@ -69,30 +76,43 @@ The **ScriptBlock** parameter value contains a command that searches the $home d Because the scheduled job does not contain a trigger, it is not started automatically. You can use add job triggers later, use the Start-Job cmdlet to start the job on demand, or use the scheduled job as a template for other scheduled jobs. + ### Example 2: Create a scheduled job with triggers and custom options -``` + The first command uses the New-ScheduledJobOption cmdlet to create a job option object, which it saves in the $o parameter. The options start the scheduled job even if the computer is not idle, wake the computer to run the job, if necessary, and allows multiple instances of the job to run in a series. -PS C:\> $o = New-ScheduledJobOption -WakeToRun -StartIfNotIdle -MultipleInstancesPolicy Queue +```powershell +$o = New-ScheduledJobOption -WakeToRun -StartIfNotIdle -MultipleInstancesPolicy Queue +``` The second command uses the New-JobTrigger cmdlet to create job trigger that starts a job every other Monday at 9:00 p.m. -PS C:\> $t = New-JobTrigger -Weekly -At "9:00 PM" -DaysOfWeek Monday -WeeksInterval 2 + +```powershell +$t = New-JobTrigger -Weekly -At "9:00 PM" -DaysOfWeek Monday -WeeksInterval 2 +``` This command creates the UpdateVersion scheduled job, which runs the UpdateVersion.ps1 script every Monday at 9:00 p.m. The command uses the **FilePath** parameter to specify the script that the job runs. It uses the **Trigger** parameter to specify the job triggers in the $t variable and the **ScheduledJobOption** parameter to specify the option object in the $o variable. -PS C:\> Register-ScheduledJob -Name UpdateVersion -FilePath \\Srv01\Scripts\UpdateVersion.ps1 -Trigger $t -ScheduledJobOption $o + +```powershell +Register-ScheduledJob -Name UpdateVersion -FilePath \\Srv01\Scripts\UpdateVersion.ps1 -Trigger $t -ScheduledJobOption $o ``` This example shows how to create a scheduled job that has a job trigger and custom job options. + ### Example 3: Use hash tables to specify a trigger and job options -``` -PS C:\> Register-ScheduledJob -FilePath \\Srv01\Scripts\Update-Version.ps1 -Trigger @{Frequency=Weekly; At="9:00PM"; DaysOfWeek="Monday"; Interval=2} -ScheduledJobOption @{WakeToRun; StartIfNotIdle; MultipleInstancesPolicy="Queue"} + +```powershell +Register-ScheduledJob -FilePath \\Srv01\Scripts\Update-Version.ps1 -Trigger @{Frequency=Weekly; At="9:00PM"; DaysOfWeek="Monday"; Interval=2} -ScheduledJobOption @{WakeToRun; StartIfNotIdle; +MultipleInstancesPolicy="Queue"} ``` This command is has the same effect as the command in Example 2. It creates a scheduled job, but it uses hash tables to specify the values of the **Trigger** and **ScheduledJobOption** parameters. + ### Example 4: Create scheduled jobs on remote computers -``` -PS C:\> Invoke-Command -ComputerName (Get-Content Servers.txt) -ScriptBlock {Register-ScheduledJob -Name Get-EnergyData -FilePath "\\Srv01\Scripts\Get-EnergyData.ps1" -ScheduledJobOption $o -Trigger $t } -Credential $cred + +```powershell +Invoke-Command -ComputerName (Get-Content Servers.txt) -ScriptBlock {Register-ScheduledJob -Name Get-EnergyData -FilePath "\\Srv01\Scripts\Get-EnergyData.ps1" -ScheduledJobOption $o -Trigger $t } -Credential $cred ``` This command creates the EnergyData scheduled job on multiple remote computers. @@ -104,9 +124,11 @@ The Invoke-Command command uses the **Credential** parameter to provider the cre The Register-ScheduledJob command creates a scheduled job on the remote computer that runs the EnergyData.ps1 script on the scheduled specified by the job trigger in the $t variable. The script is located on a file server that is available to all participating computers. + ### Example 5: Create a scheduled job that runs a script on remote computers -``` -PS C:\> Register-ScheduledJob -Name CollectEnergyData -Trigger $t -MaxResultCount 99 -ScriptBlock { Invoke-Command -AsJob -ComputerName (Servers.txt) -FilePath "\\Srv01\Scripts\Get-EnergyData.ps1" -Credential $Admin -Authentication CredSSP } + +```powershell +Register-ScheduledJob -Name CollectEnergyData -Trigger $t -MaxResultCount 99 -ScriptBlock { Invoke-Command -AsJob -ComputerName (Servers.txt) -FilePath "\\Srv01\Scripts\Get-EnergyData.ps1" -Credential $Admin -Authentication CredSSP } ``` This command uses the **Register-ScheduledJob** cmdlet to create the CollectEnergyData scheduled job on the local computer. @@ -115,9 +137,11 @@ The command uses the **Trigger** parameter to specify the job schedule and the * The CollectEnergyData job uses the Invoke-Command cmdlet to run the EnergyData.ps1 script as a background on the computers listed in the Servers.txt file. The **Invoke-Command** command uses the **AsJob** parameter to create the background job object on the local computer , even though the Energydata.ps1 script runs on the remote computers. The command uses the **Credential** parameter to specify a user account that has permission to run scripts on the remote computers and the **Authentication** parameter with a value of **CredSSP** to allow delegated credentials. + ## PARAMETERS ### -ArgumentList + Specifies values for the parameters of the script that is specified by the **FilePath** parameter or for the command that is specified by the **ScriptBlock** parameter. ```yaml @@ -133,6 +157,7 @@ Accept wildcard characters: False ``` ### -Authentication + Specifies the mechanism that is used to authenticate the user's credentials. Valid values are Default, Basic, Credssp, Digest, Kerberos, Negotiate, and NegotiateWithImplicitCredential. The default value is Default. @@ -155,6 +180,7 @@ Accept wildcard characters: False ``` ### -Credential + Specifies a user account that has permission to run the scheduled job. The default is the current user. @@ -174,6 +200,7 @@ Accept wildcard characters: False ``` ### -FilePath + Specifies a script that the scheduled job runs. Enter the path to a .ps1 file on the local computer. To specify default values for the script parameters, use the **ArgumentList** parameter. @@ -192,6 +219,7 @@ Accept wildcard characters: False ``` ### -InitializationScript + Specifies the fully qualified path to a Windows PowerShell script (.ps1). The initialization script runs in the session that is created for the background job before the commands that are specified by the **ScriptBlock** parameter or the script that is specified by the **FilePath** parameter . You can use the initialization script to configure the session, such as adding files, functions, or aliases, creating directories, or checking for prerequisites. @@ -213,6 +241,7 @@ Accept wildcard characters: False ``` ### -MaxResultCount + Specifies how many job result entries are maintained for the scheduled job. The default value is 32. @@ -241,6 +270,7 @@ Accept wildcard characters: False ``` ### -Name + Specifies a name for the scheduled job. The name is also used for all started instances of the scheduled job. The name must be unique on the computer. @@ -259,6 +289,7 @@ Accept wildcard characters: False ``` ### -RunAs32 + Runs the scheduled job in a 32-bit process. ```yaml @@ -274,6 +305,7 @@ Accept wildcard characters: False ``` ### -ScheduledJobOption + Sets options for the scheduled job. Enter a **ScheduledJobOptions** object, such as one that you create by using the New-ScheduledJobOption cmdlet, or a hash table value. @@ -301,6 +333,7 @@ Accept wildcard characters: False ``` ### -ScriptBlock + Specifies the commands that the scheduled job runs. Enclose the commands in braces ( { } ) to create a script block. To specify default values for command parameters, use the **ArgumentList** parameter. @@ -320,6 +353,7 @@ Accept wildcard characters: False ``` ### -Trigger + Specifies the triggers for the scheduled job. Enter one or more **ScheduledJobTrigger** objects, such as the objects that the New-JobTrigger cmdlet returns, or a hash table of job trigger keys and values. @@ -352,6 +386,7 @@ Accept wildcard characters: False ``` ### -Confirm + Prompts you for confirmation before running the cmdlet. ```yaml @@ -367,6 +402,7 @@ Accept wildcard characters: False ``` ### -WhatIf + Shows what would happen if the cmdlet runs. The cmdlet is not run. @@ -383,20 +419,25 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### None + You cannot pipe input to this cmdlet. + ## OUTPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition ## NOTES -* Each scheduled job is saved in a subdirectory of the $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs directory on the local computer. The subdirectory is named for the scheduled job and contains an XML file for the scheduled job and records of its execution history. For more information about scheduled jobs on disk, see about_Scheduled_Jobs_Advanced. -* Scheduled jobs that you create in Windows PowerShell appear in Task Scheduler in the Task Scheduler Library\Microsoft\Windows\PowerShell\ScheduledJobs folder. You can use Task Scheduler to view and edit the scheduled job. -* You can use Task Scheduler, the SchTasks.exe command-line tool, and the Task Scheduler cmdlets to manage scheduled jobs that you create with the Scheduled Job cmdlets. However, you cannot use the Scheduled Job cmdlets to manage tasks that you create in Task Scheduler. -* If a scheduled job command fails, Windows PowerShell returns an error message. However, if the job fails when Task Scheduler tries to run it, the error is not available to Windows PowerShell. + +- Each scheduled job is saved in a subdirectory of the $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs directory on the local computer. The subdirectory is named for the scheduled job and contains an XML file for the scheduled job and records of its execution history. For more information about scheduled jobs on disk, see about_Scheduled_Jobs_Advanced. +- Scheduled jobs that you create in Windows PowerShell appear in Task Scheduler in the Task Scheduler Library\Microsoft\Windows\PowerShell\ScheduledJobs folder. You can use Task Scheduler to view and edit the scheduled job. +- You can use Task Scheduler, the SchTasks.exe command-line tool, and the Task Scheduler cmdlets to manage scheduled jobs that you create with the Scheduled Job cmdlets. However, you cannot use the Scheduled Job cmdlets to manage tasks that you create in Task Scheduler. +- If a scheduled job command fails, Windows PowerShell returns an error message. However, if the job fails when Task Scheduler tries to run it, the error is not available to Windows PowerShell. If a scheduled job does not run, use the following methods to find the reason. @@ -407,6 +448,7 @@ You cannot pipe input to this cmdlet. - Check the Task Scheduler event log for errors. For more information, see about_Scheduled_Jobs_Troubleshooting. + ## RELATED LINKS [about_Scheduled_Jobs](About/about_Scheduled_Jobs.md) diff --git a/reference/3.0/PSScheduledJob/Remove-JobTrigger.md b/reference/3.0/PSScheduledJob/Remove-JobTrigger.md index ec9c1e4e2b5a..83f44b60338a 100644 --- a/reference/3.0/PSScheduledJob/Remove-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/Remove-JobTrigger.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,28 +7,34 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223914 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Remove-JobTrigger --- - # Remove-JobTrigger + ## SYNOPSIS + Delete job triggers from scheduled jobs + ## SYNTAX ### JobDefinition (Default) + ``` Remove-JobTrigger [-TriggerId ] [-InputObject] [] ``` ### JobDefinitionName + ``` Remove-JobTrigger [-TriggerId ] [-Name] [] ``` ### JobDefinitionId + ``` Remove-JobTrigger [-TriggerId ] [-Id] [] ``` ## DESCRIPTION + The Remove-JobTrigger cmdlet deletes job triggers from scheduled jobs. A "job trigger" defines a recurring schedule or conditions for starting a scheduled job. @@ -44,26 +50,31 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Delete all job triggers -``` -PS C:\> Remove-JobTrigger -Name Test* + +```powershell +Remove-JobTrigger -Name Test* ``` This command deletes all job triggers from scheduled job that have names that begin with "Test". + ### Example 2: Delete selected job triggers -``` -PS C:\> Remove-JobTrigger -Name BackupArchive -TriggerID 3 + +```powershell +Remove-JobTrigger -Name BackupArchive -TriggerId 3 ``` This command deletes only the third trigger (ID = 3) from the BackupArchive scheduled job. + ### Example 3: Delete AtStartup job triggers from all scheduled jobs -``` -PS C:\> + +```powershell function Delete-AtStartup { - Get-ScheduledJob | Get-JobTrigger | Where-Object {$_.Frequency -eq "AtStartup"} | ForEach-Object { Remove-JobTrigger -InputObject $_.JobDefinition -TriggerID $_.ID} + Get-ScheduledJob | Get-JobTrigger | Where-Object {$_.Frequency -eq "AtStartup"} | ForEach-Object { Remove-JobTrigger -InputObject $_.JobDefinition -TriggerId $_.ID} } ``` @@ -81,9 +92,11 @@ The remainder of the command uses that valuable feature. A pipeline operator sends the AtStartup job triggers to the ForEach-Object cmdlet, which runs a **Remove-JobTrigger** command on each AtStartup trigger. The value of the **InputObject** parameter of **Remove-JobTrigger** is the scheduled job in the **JobDefinition** property of the job trigger. The value of the **TriggerID** parameter is the identifier in the **ID** property of the job trigger. + ### Example 4: Delete a job trigger from a remote scheduled job -``` -PS C:\> Invoke-Command -ComputerName Server01 { Remove-JobTrigger -ID 38 -TriggerID 1 } + +```powershell +Invoke-Command -ComputerName Server01 { Remove-JobTrigger -Id 38 -TriggerId 1 } ``` This command deletes the first job trigger from the Inventory job on the Server01 computer. @@ -91,9 +104,11 @@ This command deletes the first job trigger from the Inventory job on the Server0 The command uses the Invoke-Command cmdlet to run a Remove-JobTrigger command on the Server01 computer. The Remove-JobTrigger command uses the ID parameter to identify the Inventory scheduled job and the TriggerID parameter to specify the first trigger. The ID parameter is especially useful when multiple scheduled jobs have the same or similar names. + ## PARAMETERS ### -Id + Specifies the identification numbers of the scheduled jobs. **Remove-JobTrigger** deletes job triggers from the specified scheduled jobs. @@ -112,6 +127,7 @@ Accept wildcard characters: False ``` ### -InputObject + Specifies the scheduled jobs. Enter a variable that contains **ScheduledJob** objects or type a command or expression that gets **ScheduledJob** objects, such as a Get-ScheduledJob command. You can also pipe **ScheduledJob** objects to **Remove-JobTrigger**. @@ -129,6 +145,7 @@ Accept wildcard characters: False ``` ### -Name + Specifies the names of the scheduled jobs. **Remove-JobTrigger** deletes the job triggers from the specified scheduled jobs. Wildcards are supported. @@ -148,6 +165,7 @@ Accept wildcard characters: True ``` ### -TriggerId + Deletes only the specified job triggers. By default, **Remove-JobTrigger** deletes all triggers from the scheduled jobs. Use this parameter when the scheduled jobs have multiple job triggers. @@ -168,15 +186,21 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition + You can pipe scheduled jobs to the **Remove-JobTrigger** cmdlet. + ## OUTPUTS ### None + The cmdlet does not generate any output. + ## NOTES ## RELATED LINKS diff --git a/reference/3.0/PSScheduledJob/Set-JobTrigger.md b/reference/3.0/PSScheduledJob/Set-JobTrigger.md index 26d52ec65ac7..0a051188e966 100644 --- a/reference/3.0/PSScheduledJob/Set-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/Set-JobTrigger.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,10 +7,12 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223916 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Set-JobTrigger --- - # Set-JobTrigger + ## SYNOPSIS + Changes the job trigger of a scheduled job. + ## SYNTAX ``` @@ -21,6 +23,7 @@ Set-JobTrigger [-InputObject] [-DaysInterval ] [- ``` ## DESCRIPTION + The **Set-JobTrigger** cmdlet changes the properties of the job triggers of scheduled jobs. You can use it to change the time or frequency at which the jobs start or to change from a time-based schedules to schedules that are triggered by a logon or startup. @@ -41,35 +44,59 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Change the days in a job trigger -``` + The first command uses the Get-JobTrigger cmdlet to get the job trigger of the DeployPackage scheduled job. The output shows that the trigger starts the job at midnight on Wednesdays and Saturdays.This command is not required; it is included only to show the effect of the trigger change. -PS C:\> Get-JobTrigger -Name DeployPackage + +```powershell +Get-JobTrigger -Name DeployPackage +``` + +```output Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 1 Weekly 9/29/2011 12:00:00 AM {Wednesday, Saturday} True +``` The second command uses the Get-JobTrigger cmdlet to get the job trigger of the DeployPackage scheduled job. A pipeline operator (|) sends the trigger to the **Set-JobTrigger** cmdlet which changes the job trigger so that it starts the DeployPackage job on Wednesdays and Sundays. The command uses the **Passthru** parameter to return the trigger after the change. -PS C:\> Get-JobTrigger -Name DeployPackage | Set-JobTrigger -DaysOfWeek "Wednesday", "Sunday" -Passthru + +```powershell +Get-JobTrigger -Name DeployPackage | Set-JobTrigger -DaysOfWeek "Wednesday", "Sunday" -Passthru +``` + +```output Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 1 Weekly 9/29/2011 12:00:00 AM {Wednesday, Sunday} True ``` This example shows how to change the days in a weekly job trigger. + ### Example 2: Change the job trigger type -``` + The first command uses the Get-JobTrigger cmdlet to get the job trigger of the Inventory scheduled job. The output shows that the job has two triggers a daily trigger and an AtStartup trigger.This command is not required; it is included only to show the effect of the trigger change. -PS C:\> Get-JobTrigger -Name Inventory + +```powershell +Get-JobTrigger -Name Inventory +``` + +```output Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 1 Daily 9/27/2011 11:00:00 PM True 2 AtStartup True +``` The second command uses the Get-JobTrigger cmdlet to get the AtStartup job trigger of the Inventory job. The command uses the TriggerID parameter to identify the job trigger. A pipeline operator (|) sends the job trigger to the **Set-JobTrigger** cmdlet which changes it to a weekly job trigger that runs every four weeks on Monday at midnight. The command uses the **Passthru** parameter to return the trigger after the change. -PS C:\> Get-JobTrigger -Name Inventory -TriggerID 2 | Set-JobTrigger -Weekly -WeeksInterval 4 -DaysOfWeek Monday -At "12:00 AM" + +```powershell +Get-JobTrigger -Name Inventory -TriggerId 2 | Set-JobTrigger -Weekly -WeeksInterval 4 -DaysOfWeek Monday -At "12:00 AM" +``` + +```output Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 1 Daily 9/27/2011 11:00:00 PM True @@ -78,9 +105,11 @@ Id Frequency Time DaysOfWeek Enable This example shows how to change the type of job trigger that starts a job. The commands in this example replace an AtStartup job trigger with a weekly trigger. + ### Example 3: Change the user on a remote job trigger -``` -PS C:\> Invoke-Command -Computer Server01 -ScriptBlock {Get-ScheduledJob | Get-JobTrigger | Where-Object {$_.User} | Set-JobTrigger -User "Domain01/Admin02"} + +```powershell +Invoke-Command -ComputerName Server01 -ScriptBlock {Get-ScheduledJob | Get-JobTrigger | Where-Object {$_.User} | Set-JobTrigger -User "Domain01/Admin02"} ``` This command changes the user in all AtLogon job triggers of scheduled jobs on the Server01 computer. @@ -93,18 +122,30 @@ Each job trigger contains a **JobDefinition** property that contains the schedul The job triggers are piped to the Where-Object cmdlet which gets job triggers that have the **User** property. The selected job triggers are piped to the **Set-JobTrigger** cmdlet, which changes the user to Domain01\Admin02. + ### Example 4: Change one of many job triggers -``` + The first command uses the **Get-JobTrigger** cmdlet to get all job triggers of the SecurityCheck scheduled job. The output, which displays the IDs of the job triggers, reveals that the **Once** job trigger has an ID of 3. -PS C:\> Get-JobTrigger -Name SecurityCheck + +```powershell +Get-JobTrigger -Name SecurityCheck +``` + +```output Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 1 Daily 4/24/2013 3:00:00 AM True 2 Weekly 4/24/2013 4:00:00 PM {Sunday} True 3 Once 4/24/2013 4:00:00 PM True +``` The second command uses the **TriggerID** parameter of the **Get-JobTrigger** cmdlet to get the **Once** trigger of the SecurityCheck scheduled job. The command pipes the trigger to the Format-List cmdlet, which displays all of the properties of the **Once** job trigger.The output shows that the trigger starts the job once every hour (RepetitionInterval = 1 hour) for one day (RepetitionDuration = 1 day). -PS C:\> Get-JobTrigger -Name SecurityCheck -TriggerID 3 | Format-List -Property * + +```powershell +Get-JobTrigger -Name SecurityCheck -TriggerId 3 | Format-List -Property * +``` + +```output At : 4/24/2012 4:00:00 PM DaysOfWeek : Interval : 1 @@ -116,12 +157,21 @@ User : Id : 3 Enabled : True JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition +``` The third command changes the repetition interval of the job trigger from one hour to 90 minutes. The command does not return any output. -PS C:\> Get-JobTrigger -Name SecurityCheck -TriggerId 3 | Set-JobTrigger -RepetitionInterval (New-TimeSpan -Minutes 90) + +```powershell +Get-JobTrigger -Name SecurityCheck -TriggerId 3 | Set-JobTrigger -RepetitionInterval (New-TimeSpan -Minutes 90) +``` The fourth command displays the effect of the change.The output shows that the trigger starts the job once every 90 minutes (RepetitionInterval = 1 hour, 30 minutes) for one day (RepetitionDuration = 1 day). -PS C:\> Get-JobTrigger -Name SecurityCheck -TriggerID 3 | Format-List -Property * + +```powershell +Get-JobTrigger -Name SecurityCheck -TriggerId 3 | Format-List -Property * +``` + +```output At : 4/24/2012 4:00:00 PM DaysOfWeek : Interval : 1 @@ -137,9 +187,11 @@ JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition The commands in this example changes the repetition interval of the **Once** job trigger of SecurityCheck scheduled job from every 60 minutes to every 90 minutes. The SecurityCheck scheduled job has three job triggers, so the commands use the **TriggerId** parameter of the Get-JobTrigger cmdlet to identify the job trigger that is being changed. + ## PARAMETERS ### -At + Starts the job at the specified date and time. Enter a **DateTime** object, such as one that the Get-Date cmdlet returns, or a string that can be converted to a time, such as "April 19, 2012 15:00", "12/31/2013 9:00 PM", or "3am". @@ -164,6 +216,7 @@ Accept wildcard characters: False ``` ### -AtLogOn + Starts the scheduled job when the specified users log on to the computer. To specify a user, use the **User** parameter. @@ -180,6 +233,7 @@ Accept wildcard characters: False ``` ### -AtStartup + Starts the scheduled job when Windows starts. ```yaml @@ -195,6 +249,7 @@ Accept wildcard characters: False ``` ### -Daily + Specifies a recurring daily job schedule. Use the other parameters in the Daily parameter set to specify the schedule details. @@ -211,6 +266,7 @@ Accept wildcard characters: False ``` ### -DaysInterval + Specifies the number of days between occurrences on a daily schedule. For example, a value of 3 starts the scheduled job on days 1, 4, 7 and so on. The default value is 1. @@ -228,6 +284,7 @@ Accept wildcard characters: False ``` ### -DaysOfWeek + Specifies the days of the week on which a weekly scheduled job runs. Enter day names, such as '"Monday", "Thursday"', integers 0-6, where 0 represents Sunday, or an asterisk (*) to represent every day. This parameter is required in the Weekly parameter set. @@ -250,6 +307,7 @@ Accept wildcard characters: True ``` ### -InputObject + Specifies the job triggers. Enter a variable that contains **ScheduledJobTrigger** objects or type a command or expression that gets **ScheduledJobTrigger** objects, such as a Get-JobTrigger command. You can also pipe a **ScheduledJobTrigger** object to **Set-JobTrigger**. @@ -269,6 +327,7 @@ Accept wildcard characters: False ``` ### -Once + Specifies a non-recurring (one time) schedule. ```yaml @@ -284,6 +343,7 @@ Accept wildcard characters: False ``` ### -PassThru + Returns the job triggers that changed. By default, this cmdlet does not generate any output. @@ -300,6 +360,7 @@ Accept wildcard characters: False ``` ### -RandomDelay + Enables a random delay that begins at the scheduled start time, and sets the maximum delay value. The length of the delay is set pseudo-randomly for each start and varies from no delay to the time specified by the value of this parameter. The default value, zero (00:00:00), disables the random delay. @@ -319,6 +380,7 @@ Accept wildcard characters: False ``` ### -RepetitionDuration + Repeats the job until the specified time expires. The repetition frequency is determined by the value of the **RepetitionInterval** parameter. For example, if the value of **RepetitionInterval** is 5 minutes and the value of **RepetitionDuration** is 2 hours, the job is triggered every five minutes for two hours. @@ -345,6 +407,7 @@ Accept wildcard characters: False ``` ### -RepetitionInterval + Repeats the job at the specified time interval. For example, if the value of this parameter is 2 hours, the job is triggered every two hours. The default value, 0, does not repeat the job. @@ -367,6 +430,7 @@ Accept wildcard characters: False ``` ### -User + Specifies the users who trigger an **AtLogon** start of a scheduled job. Enter the name of a user in \ or \ format or enter an asterisk (*) to represent all users. The default value is all users. @@ -384,6 +448,7 @@ Accept wildcard characters: False ``` ### -Weekly + Specifies a recurring weekly job schedule. Use the other parameters in the Weekly parameter set to specify the schedule details. @@ -400,6 +465,7 @@ Accept wildcard characters: False ``` ### -WeeksInterval + Specifies the number of weeks between occurrences on a weekly job schedule. For example, a value of 3 starts the scheduled job on weeks 1, 4, 7 and so on. The default value is 1. @@ -417,18 +483,26 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobTrigger + You can pipe multiple job triggers to Set-JobTrigger. + ## OUTPUTS ### None or Microsoft.PowerShell.ScheduledJob.ScheduledJobTrigger + When you use the **Passthru** parameter, **Set-JobTrigger** returns the job triggers that were changed. Otherwise, this cmdlet does not generate any output. + ## NOTES -* Job triggers have a **JobDefintion** property that associates them with the scheduled job. When you change the job trigger of a scheduled job, the job is changed. You do not need to use a Set-ScheduledJob command to apply the changed trigger to the scheduled job. + +- Job triggers have a **JobDefintion** property that associates them with the scheduled job. When you change the job trigger of a scheduled job, the job is changed. You do not need to use a Set-ScheduledJob command to apply the changed trigger to the scheduled job. + ## RELATED LINKS [about_Scheduled_Jobs](About/about_Scheduled_Jobs.md) diff --git a/reference/3.0/PSScheduledJob/Set-ScheduledJob.md b/reference/3.0/PSScheduledJob/Set-ScheduledJob.md index 27291026579d..dde062ee137c 100644 --- a/reference/3.0/PSScheduledJob/Set-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Set-ScheduledJob.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,13 +7,16 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223924 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Set-ScheduledJob --- - # Set-ScheduledJob + ## SYNOPSIS + Changes scheduled jobs + ## SYNTAX ### ScriptBlock (Default) + ``` Set-ScheduledJob [-Name ] [-ScriptBlock ] [-Trigger ] [-InitializationScript ] [-RunAs32] [-Credential ] @@ -23,6 +26,7 @@ Set-ScheduledJob [-Name ] [-ScriptBlock ] [-Trigger ] [-FilePath ] [-Trigger ] [-InitializationScript ] [-RunAs32] [-Credential ] @@ -32,12 +36,14 @@ Set-ScheduledJob [-Name ] [-FilePath ] [-Trigger [-ClearExecutionHistory] [-PassThru] [] ``` ## DESCRIPTION + The **Set-ScheduledJob** cmdlet changes the properties of scheduled jobs, such as the commands that the jobs run or the credentials required to run the job. You can also use it to clear the execution history of the scheduled job. @@ -54,27 +60,41 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Change the script that a job runs -``` + The first command uses the Get-ScheduledJob cmdlet to get the Inventory scheduled job. The output shows that the job runs the Get-Inventory.ps1 script.This command is not required; it is included only to show the effect of the script change. -PS C:\> Get-ScheduledJob -Name Inventory + +```powershell +Get-ScheduledJob -Name Inventory +``` + +```output Id Name Triggers Command Enabled -- ---- -------- ------- ------- 1 Inventory {1} C:\Scripts\Get-Inventory.ps1 True +``` The second command uses the Get-ScheduledJob cmdlet to get the Inventory scheduled job. A pipeline operator (|) sends the scheduled job to the **Set-ScheduledJob** cmdlet. The Set-ScheduledJob command uses the Script parameter to specify a new script, Get-FullInventory.ps1. The command uses the **Passthru** parameter to return the scheduled job after the change. -PS C:\> Get-ScheduledJob -Name Inventory | Set-ScheduledJob -FilePath C:\Scripts\Get-FullInventory.ps1 -Passthru + +```powershell +Get-ScheduledJob -Name Inventory | Set-ScheduledJob -FilePath C:\Scripts\Get-FullInventory.ps1 -Passthru +``` + +```output Id Name Triggers Command Enabled -- ---- -------- ------- ------- 1 Inventory {1} C:\Scripts\Get-FullInventory.ps1 True ``` This example shows how to change the script that is run in a scheduled job. + ### Example 2: Delete the execution history of a scheduled job -``` -PS C:\> Get-ScheduledJob BackupArchive | Set-ScheduledJob -ClearExecutionHistory + +```powershell +Get-ScheduledJob BackupArchive | Set-ScheduledJob -ClearExecutionHistory ``` This command deletes the current execution history and saved job results for the BackupArchive scheduled job. @@ -84,9 +104,11 @@ A pipeline operator (|) sends the job to the **Set-ScheduledJob** cmdlet to chan The **Set-ScheduledJob** command uses the **ClearExecutionHistory** parameter to delete the execution history and saved results. For more information about the execution history and saved job results of scheduled jobs, see about_Scheduled_Jobs. + ### Example 3: Change scheduled jobs on a remote computer -``` -PS C:\> Invoke-Command -Computer Server01, Server02 -ScriptBlock {Get-ScheduledJob | Set-ScheduledJob -InitializationScript \\SrvA\Scripts\SetForRun.ps1} + +```powershell +Invoke-Command -ComputerName Server01, Server02 -ScriptBlock {Get-ScheduledJob | Set-ScheduledJob -InitializationScript \\SrvA\Scripts\SetForRun.ps1} ``` This command changes the initialization script in all scheduled jobs on the Server01 and Server02 computers. @@ -95,9 +117,11 @@ The command uses the Invoke-Command cmdlet to run a command on the Server01 and The remote command begins with a Get-ScheduledJob command that gets all scheduled jobs on the computer. The scheduled jobs are piped to the **Set-ScheduledJob** cmdlet which changes the initialization script to SetForRun.ps1. + ## PARAMETERS ### -ArgumentList + Specifies values for the parameters of the script that is specified by the **FilePath** parameter or for the command that is specified by the **ScriptBlock** parameter. ```yaml @@ -113,6 +137,7 @@ Accept wildcard characters: False ``` ### -Authentication + Specifies the mechanism that is used to authenticate the user's credentials. Valid values are Default, Basic, Credssp, Digest, Kerberos, Negotiate, and NegotiateWithImplicitCredential. The default value is Default. @@ -135,6 +160,7 @@ Accept wildcard characters: False ``` ### -ClearExecutionHistory + Deletes the current execution history and the saved results of the scheduled job. The job execution history and job results are saved with the scheduled job in the $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs directory on the computer on which the job is created. @@ -157,6 +183,7 @@ Accept wildcard characters: False ``` ### -Credential + Specifies a user account that has permission to run the scheduled job. The default is the current user. @@ -176,6 +203,7 @@ Accept wildcard characters: False ``` ### -FilePath + Specifies a script that the scheduled job runs. Enter the path to a .ps1 file on the local computer. To specify default values for the script parameters, use the **ArgumentList** parameter. @@ -194,6 +222,7 @@ Accept wildcard characters: False ``` ### -InitializationScript + Specifies the fully qualified path to a Windows PowerShell script (.ps1). The initialization script runs in the session that is created for the background job before the commands that are specified by the **ScriptBlock** parameter or the script that is specified by the **FilePath** parameter . You can use the initialization script to configure the session, such as adding files, functions, or aliases, creating directories, or checking for prerequisites. @@ -215,6 +244,7 @@ Accept wildcard characters: False ``` ### -InputObject + Specifies the scheduled job to be changed. Enter a variable that contains **ScheduledJobDefinition** objects or type a command or expression that gets **ScheduledJobDefinition** objects, such as a Get-ScheduledJob command. You can also pipe a **ScheduledJobDefinition** object to **Set-ScheduledJob**. @@ -234,6 +264,7 @@ Accept wildcard characters: False ``` ### -MaxResultCount + Specifies how many job result entries are maintained for the scheduled job. The default value is 32. @@ -262,6 +293,7 @@ Accept wildcard characters: False ``` ### -Name + Specifies a new name for the scheduled job and instances of the scheduled job. The name must be unique on the local computer. @@ -283,6 +315,7 @@ Accept wildcard characters: False ``` ### -PassThru + Returns the scheduled jobs that changed. By default, this cmdlet does not generate any output. @@ -299,6 +332,7 @@ Accept wildcard characters: False ``` ### -RunAs32 + Runs the scheduled job in a 32-bit process. ```yaml @@ -314,6 +348,7 @@ Accept wildcard characters: False ``` ### -ScheduledJobOption + Sets options for the scheduled job. Enter a **ScheduledJobOptions** object, such as one that you create by using the New-ScheduledJobOption cmdlet, or a hash table value. @@ -341,6 +376,7 @@ Accept wildcard characters: False ``` ### -ScriptBlock + Specifies the commands that the scheduled job runs. Enclose the commands in braces ( { } ) to create a script block. To specify default values for command parameters, use the **ArgumentList** parameter. @@ -360,6 +396,7 @@ Accept wildcard characters: False ``` ### -Trigger + Specifies the triggers for the scheduled job. Enter one or more **ScheduledJobTrigger** objects, such as the objects that the New-JobTrigger cmdlet returns, or a hash table of job trigger keys and values. @@ -391,16 +428,22 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition + You can pipe scheduled jobs to **Set-ScheduledJob**. + ## OUTPUTS ### None or Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition + If you use the **Passthru** parameter, **Set-ScheduledJob** returns the scheduled job that was changed. Otherwise, this cmdlet does not generate any output. + ## NOTES ## RELATED LINKS diff --git a/reference/3.0/PSScheduledJob/Set-ScheduledJobOption.md b/reference/3.0/PSScheduledJob/Set-ScheduledJobOption.md index 0fc410b64351..8defb3b911ec 100644 --- a/reference/3.0/PSScheduledJob/Set-ScheduledJobOption.md +++ b/reference/3.0/PSScheduledJob/Set-ScheduledJobOption.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,10 +7,12 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223921 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Set-ScheduledJobOption --- - # Set-ScheduledJobOption + ## SYNOPSIS + Changes the job options of a scheduled job. + ## SYNTAX ``` @@ -21,6 +23,7 @@ Set-ScheduledJobOption [-InputObject] [-PassThru] [-RunEle ``` ## DESCRIPTION + The **Set-ScheduledJobOptions** cmdlet changes the job options of scheduled jobs. To change the options of a scheduled job, begin by using the Get-ScheduledJobOption cmdlet to get the job options of a scheduled job. @@ -42,12 +45,18 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Change job options -``` + The first command uses the Get-ScheduledJobOption cmdlet to get the job options of the DeployPackage scheduled job. The output shows that the WakeToRun and RunElevated properties are set to False.This command is not required; it is included only to show the effect of the option change. -PS C:\> Get-ScheduledJobOption -Name DeployPackage + +```powershell +Get-ScheduledJobOption -Name DeployPackage +``` + +```output StartIfOnBatteries : False StopIfGoingOnBatteries : True WakeToRun : False @@ -62,9 +71,15 @@ RunWithoutNetwork : False DoNotAllowDemandStart : False MultipleInstancePolicy : IgnoreNew JobDefinition : +``` The second command uses the **Set-ScheduledJobOpton** cmdlet to change the job options so the values of the **WakeToRun** and **RunWithoutNetwork** properties are True. The command uses the **Passthru** parameter to return the trigger after the change. -PS C:\> Get-ScheduledJobOption -Name DeployPackage | Set-ScheduledJobOption -WakeToRun -RequireNetwork:$False -Passthru + +```powershell +Get-ScheduledJobOption -Name DeployPackage | Set-ScheduledJobOption -WakeToRun -RequireNetwork:$False -Passthru +``` + +```output StartIfOnBatteries : False StopIfGoingOnBatteries : True WakeToRun : True @@ -81,9 +96,11 @@ MultipleInstancePolicy : IgnoreNewJobDefinition : ``` This example shows how to change the options of a scheduled job on the local computer. + ### Example 2: Change an option on all remote scheduled jobs -``` -PS C:\> Invoke-Command -Computer Server01 -ScriptBlock {Get-ScheduledJob | Get-ScheduledJobOption | Set-ScheduledJobOption -IdleTimeout 2:00:00} + +```powershell +Invoke-Command -ComputerName Server01 -ScriptBlock {Get-ScheduledJob | Get-ScheduledJobOption | Set-ScheduledJobOption -IdleTimeout 2:00:00} ``` This command changes the value of the IdleTimeout from one hour (the default value) to two hours on all scheduled jobs on the Server01 computer. @@ -95,9 +112,11 @@ The scheduled jobs are piped to the Get-ScheduledJobOption cmdlet, which gets th Each job options object contains a **JobDefinition** property that contains the scheduled job, so the options object remains associated with the scheduled job even when it is changed. The job triggers are piped to the **Set-ScheduledJobOption** cmdlet, which changes the value of the IdleTimeout option to two hours (2:00:00). + ## PARAMETERS ### -ContinueIfGoingOnBattery + Do not stop the scheduled job if the computer switches to battery power (disconnects from AC power) while the job is running. By default, scheduled jobs stop when the computer disconnects from AC power. @@ -116,6 +135,7 @@ Accept wildcard characters: False ``` ### -DoNotAllowDemandStart + Start the job only when it is triggered. Users cannot start the job manually, such as by using the Run feature in Task Scheduler. @@ -137,6 +157,7 @@ Accept wildcard characters: False ``` ### -HideInTaskScheduler + Do not display the job in Task Scheduler. This value affects only the computer on which the job runs. By default, scheduled tasks appear in Task Scheduler. @@ -158,6 +179,7 @@ Accept wildcard characters: False ``` ### -IdleDuration + Specifies how long the computer must be idle before the job starts. The default value is 10 minutes. If the computer is not idle for the specified duration before the value of **IdleTimeout** expires, the scheduled job does not run until the next scheduled time, if any. @@ -180,6 +202,7 @@ Accept wildcard characters: False ``` ### -IdleTimeout + Specifies how long the computer must be idle before the job starts. The default value is 10 minutes. If the computer is not idle for the specified duration before the value of **IdleTimeout** expires, the scheduled job does not run until the next scheduled time, if any. @@ -202,6 +225,7 @@ Accept wildcard characters: False ``` ### -InputObject + Specifies the job options. Enter a variable that contains **ScheduledJobOptions** objects or type a command or expression that gets **ScheduledJobOptions** objects, such as a Get-ScheduledJobOption command. You can also pipe a **ScheduledJobOptions** object to **Set-ScheduledJobOption**. @@ -219,6 +243,7 @@ Accept wildcard characters: False ``` ### -MultipleInstancePolicy + Determines how the system responds to a request to start an instance of a scheduled job while another instance of the job is running. The default value is **IgnoreNew**. @@ -245,6 +270,7 @@ Accept wildcard characters: False ``` ### -PassThru + Returns the job options that changed. By default, this cmdlet does not generate any output. @@ -261,6 +287,7 @@ Accept wildcard characters: False ``` ### -RequireNetwork + Runs the scheduled job only when network connections are available. If you specify this parameter and the network is not available at the scheduled start time, the job does not run until the next scheduled start time, if any. @@ -280,6 +307,7 @@ Accept wildcard characters: False ``` ### -RestartOnIdleResume + Restarts a scheduled job when the computer becomes idle. This parameter works with the **StopIfGoingOffIdle** parameter, which suspends a running scheduled job if the computer becomes active (leaves the idle state). @@ -298,6 +326,7 @@ Accept wildcard characters: False ``` ### -RunElevated + Runs the scheduled job with the permissions of a member of the Administrators group on the computer on which the job runs. To enable a scheduled job to run with Administrator permissions, use the **Credential** parameter of Register-ScheduledJob to provide explicit credential for the job. @@ -317,6 +346,7 @@ Accept wildcard characters: False ``` ### -StartIfIdle + Starts the scheduled job if the computer has been idle for the time specified by the **IdleDuration** parameter before the time specified by the **IdleTimeout** parameter expires. By default, the **IdleDuration** and **IdleTimeout** parameters are ignored and the job starts at the scheduled start time even if the computer is busy. @@ -338,6 +368,7 @@ Accept wildcard characters: False ``` ### -StartIfOnBattery + Starts the scheduled job even if the computer is running on batteries at the scheduled start time. The default value is False. @@ -356,6 +387,7 @@ Accept wildcard characters: False ``` ### -StopIfGoingOffIdle + Suspends a running scheduled job if the computer becomes active (not idle) while the job is running. By default, a scheduled job that is suspended when the computer becomes active resumes when the computer becomes idle again. @@ -376,6 +408,7 @@ Accept wildcard characters: False ``` ### -WakeToRun + Wakes the computer from a Hibernate or Sleep state at the scheduled start time so it can run the job. By default, if the computer is in a Hibernate or Sleep state at the scheduled start time, the job does not run. @@ -394,16 +427,22 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobOptions + You can pipe a scheduled job options object to **Set-ScheduledJobOption**. + ## OUTPUTS ### None or Microsoft.PowerShell.ScheduledJob.ScheduledJobOptions + When you use the **Passthru** parameter, **Set-ScheduledJobOption** returns the job options that were changed. Otherwise, this cmdlet does not generate any output. + ## NOTES ## RELATED LINKS diff --git a/reference/3.0/PSScheduledJob/Unregister-ScheduledJob.md b/reference/3.0/PSScheduledJob/Unregister-ScheduledJob.md index b2ad15967594..cfd951abd995 100644 --- a/reference/3.0/PSScheduledJob/Unregister-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Unregister-ScheduledJob.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,29 +7,35 @@ online version: http://go.microsoft.com/fwlink/?LinkID=223925 external help file: Microsoft.PowerShell.ScheduledJob.dll-Help.xml title: Unregister-ScheduledJob --- - # Unregister-ScheduledJob + ## SYNOPSIS + Deletes scheduled jobs on the local computer. + ## SYNTAX ### Definition (Default) + ``` Unregister-ScheduledJob [-InputObject] [-Force] [-WhatIf] [-Confirm] [] ``` ### DefinitionId + ``` Unregister-ScheduledJob [-Id] [-Force] [-WhatIf] [-Confirm] [] ``` ### DefinitionName + ``` Unregister-ScheduledJob [-Name] [-Force] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION + The **Unregister-ScheduledJob** cmdlet deletes scheduled jobs from the local computer. When it deletes or "unregisters" a scheduled job, **Unregister-ScheduledJob** deletes the directory for the scheduled job (in the $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs directory), which contains the XML file that defines the scheduled job, the job execution history, and all job results. @@ -46,20 +52,24 @@ For more information about Scheduled Jobs, see the About topics in the PSSchedul Import the PSScheduledJob module and then type: `Get-Help about_Scheduled*` or see about_Scheduled_Jobs. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Delete a scheduled job -``` -PS C:\> Unregister-ScheduledJob TestJob + +```powershell +Unregister-ScheduledJob TestJob ``` This command deletes the TestJob scheduled job on the local computer. + ### Example 2: Delete all scheduled jobs -``` -PS C:\> Get-ScheduledJob | Unregister-ScheduledJob -Force +```powershell +Get-ScheduledJob | Unregister-ScheduledJob -Force -PS C:\> Unregister-ScheduledJob -Name * -Force + +Unregister-ScheduledJob -Name * -Force ``` This examples shows two different commands that delete all scheduled jobs on the local computer. @@ -70,16 +80,20 @@ A pipeline operator (|) sends the scheduled jobs to **Unregister-ScheduleJob**, The second command uses the **Name** parameter of **Unregister-ScheduledJob** with a value of all (*) to delete all scheduled jobs. Both commands use the **Force** parameter, which deletes a scheduled job even if an instance of the job is running. + ### Example 3: Delete a scheduled job on a remote computer -``` -PS C:\> Invoke-Command -ComputerName Server01 { Unregister-ScheduledJob -Name Test*} + +```powershell +Invoke-Command -ComputerName Server01 { Unregister-ScheduledJob -Name Test*} ``` This command deletes scheduled jobs with names that begin with "Test" on the Server01 remote computer. The command uses the Invoke-Command cmdlet to run the **Unregister-ScheduledJob** command on the Server02 computer. + ## PARAMETERS ### -Force + Deletes the scheduled job even if an instance of the job is running. By default, **Unregister-ScheduledJob** does not interrupt running jobs. @@ -96,6 +110,7 @@ Accept wildcard characters: False ``` ### -Id + Deletes the scheduled jobs with the specified identification numbers (ID). Enter the IDs of scheduled jobs on the computer. @@ -112,6 +127,7 @@ Accept wildcard characters: False ``` ### -InputObject + Specifies a scheduled job. Enter a variable that contains **ScheduledJob** objects or type a command or expression that gets **ScheduledJob** objects, such as a Get-ScheduledJob command. You can also pipe **ScheduledJob** objects to **Unregister-JobTrigger**. @@ -129,6 +145,7 @@ Accept wildcard characters: False ``` ### -Name + Deletes the scheduled jobs with the specified names. Enter the names of one or more scheduled jobs on the computer. Wildcards are supported. @@ -146,6 +163,7 @@ Accept wildcard characters: False ``` ### -Confirm + Prompts you for confirmation before running the cmdlet. ```yaml @@ -161,6 +179,7 @@ Accept wildcard characters: False ``` ### -WhatIf + Shows what would happen if the cmdlet runs. The cmdlet is not run. @@ -177,15 +196,21 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition + You can pipe scheduled jobs to Unregister-ScheduledJob + ## OUTPUTS ### None + This cmdlet does not generate any output. + ## NOTES ## RELATED LINKS diff --git a/reference/3.0/PSWorkflow/About/about_ActivityCommonParameters.md b/reference/3.0/PSWorkflow/About/about_ActivityCommonParameters.md index a804ca1efd72..ad51875d36e2 100644 --- a/reference/3.0/PSWorkflow/About/about_ActivityCommonParameters.md +++ b/reference/3.0/PSWorkflow/About/about_ActivityCommonParameters.md @@ -1,12 +1,12 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us keywords: powershell,cmdlet title: about_ActivityCommonParameters --- - # About ActivityCommonParameters + ## about_ActivityCommonParameters diff --git a/reference/3.0/PSWorkflow/New-PSWorkflowExecutionOption.md b/reference/3.0/PSWorkflow/New-PSWorkflowExecutionOption.md index 7bdfe94904d1..187ad2985662 100644 --- a/reference/3.0/PSWorkflow/New-PSWorkflowExecutionOption.md +++ b/reference/3.0/PSWorkflow/New-PSWorkflowExecutionOption.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,10 +7,12 @@ online version: http://go.microsoft.com/fwlink/?LinkID=210609 external help file: Microsoft.Powershell.Workflow.ServiceCore.dll-Help.xml title: New-PSWorkflowExecutionOption --- - # New-PSWorkflowExecutionOption + ## SYNOPSIS + Creates an object that contains session configuration options for workflow sessions. + ## SYNTAX ``` @@ -24,6 +26,7 @@ New-PSWorkflowExecutionOption [-PersistencePath ] [-MaxPersistenceStoreS ``` ## DESCRIPTION + The **New-PSWorkflowExecutionOption** cmdlet creates an object that contains advanced options for workflow session configurations, that is session configurations designed to run Windows PowerShell Workflow workflows. You can use the **PSWorkflowExecutionOption** object that **New-PSWorkflowExecutionOption** generates as the value of the **SessionTypeOption** parameter of cmdlets that create or change a session configuration, such as the Register-PSSessionConfiguration and Set-PSSessionConfiguration cmdlets. @@ -37,139 +40,119 @@ You can also add workflow common parameters to this command. For more information about workflow common parameters, see [about_WorkflowCommonParameters](About/about_WorkflowCommonParameters.md). This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1: Create a Workflow Options Object + +```powershell +New-PSWorkflowExecutionOption -MaxSessionsPerWorkflow 10 -MaxDisconnectedSessions 200 ``` -PS C:\> New-PSWorkflowExecutionOption -MaxSessionsPerWorkflow 10 -MaxDisconnectedSessions 200 -SessionThrottleLimit : 100 +```output +SessionThrottleLimit : 100 PersistencePath : C:\Users\User01\AppData\Local\Microsoft\Windows\PowerShell\WF\PS - MaxPersistenceStoreSizeGB : 10 - PersistWithEncryption : False - MaxRunningWorkflows : 30 - AllowedActivity : {PSDefaultActivities} - OutOfProcessActivity : {InlineScript} - EnableValidation : True - MaxDisconnectedSessions : 200 - MaxConnectedSessions : 100 - MaxSessionsPerWorkflow : 10 - MaxSessionsPerRemoteNode : 5 - MaxActivityProcesses : 5 - ActivityProcessIdleTimeoutSec : 60 - RemoteNodeSessionIdleTimeoutSec : 60 - WorkflowShutdownTimeoutMSec : 500 ``` This command uses the **New-PSWorkflowExecutionOption** cmdlet to increase the **MaxSessionsPerWorkflow** value to 10 and decrease the **MaxDisconnectedSessions** value to 200. The output shows the object that the cmdlet returns. + ### Example 2: Using a Workflow Options Object -``` + The first command uses the **New-PSWorkflowExecutionOption** cmdlet to create a workflow options object. The command saves the object in the $wo variable. -PS C:\> $wo = New-PSWorkflowExecutionOption -MaxSessionsPerWorkflow 10 -MaxDisconnectedSessions 200 +```powershell +$wo = New-PSWorkflowExecutionOption -MaxSessionsPerWorkflow 10 -MaxDisconnectedSessions 200 +``` The second command uses the Register-PSSessionConfiguration cmdlet to create the ITWorkflows session configuration. To set the workflow options in the session configuration, the command uses the **SessionTypeOption** parameter. The value of the **SessionTypeOption** parameter is the workflow options object in the $wo variable. The command also uses the **Force** parameter to suppress confirmations prompts. -PS C:\> Register-PSSessionConfiguration -Name ITWorkflows -SessionTypeOption $wo -Force - WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Plugin +```powershell +Register-PSSessionConfiguration -Name ITWorkflows -SessionTypeOption $wo -Force +``` + +```output + WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Plugin Type Keys Name - ---- ---- ---- - Container {Name=ITWorkflows} ITWorkflows +``` The third command shows the workflow options in the session configuration. The command uses the Get-PSSessionConfiguration cmdlet to the get the ITWorkflows session configuration and the Format-List to display all properties of the session configuration in a list.The output shows that the workflow options in the session configuration. Specifically, the session configuration has a **MaxSessionsPerWorkflow** property with a value of 10 and a **MaxDisconnectedSessions** property with a value of 200. -PS C:\> Get-PSSessionConfiguration ITWorkflows | Format-List -Property * -Architecture : 64 -Filename : %windir%\system32\pwrshplugin.dll +```powershell +Get-PSSessionConfiguration ITWorkflows | Format-List -Property * +``` +```output +Architecture : 64 +Filename : %windir%\system32\pwrshplugin.dll ResourceUri : http://schemas.microsoft.com/powershell/ITWorkflows - MaxConcurrentCommandsPerShell : 1000 - allowedactivity : PSDefaultActivities - UseSharedProcess : false - ProcessIdleTimeoutSec : 0 - xmlns : http://schemas.microsoft.com/wbem/wsman/1/config/PluginConfiguration - MaxConcurrentUsers : 5 - maxsessionsperworkflow : 10 - lang : en-US - -sessionconfigurationdata : - +sessionconfigurationdata : + + + + + + + + + + SupportsOptions : true - ExactMatch : true - RunAsUser : - IdleTimeoutms : 7200000 - PSVersion : 3.0 - OutputBufferingMode : Block - AutoRestart : false - MaxShells : 25 - MaxMemoryPerShellMB : 1024 - MaxIdleTimeoutms : 43200000 - outofprocessactivity : InlineScript - SDKVersion : 2 - Name : ITWorkflows - XmlRenderingType : text - Capability : {Shell} - RunAsPassword : - MaxProcessesPerShell : 15 - enablevalidation : True - Enabled : True - maxdisconnectedsessions : 200 - MaxShellsPerUser : 25 - Permission : ``` This example shows how to use a workflow options object to establish or change the workflow options in a session configuration. + ## PARAMETERS ### -ActivityProcessIdleTimeoutSec + Determines how long each activity host process is maintained after the process becomes idle. When the interval expires, the process closes. @@ -189,6 +172,7 @@ Accept wildcard characters: False ``` ### -AllowedActivity + Specifies the activities that are permitted to run in the session. Enter namespace-qualified activity names, such as "Microsoft.Powershell.HyperV.Activities.*". @@ -208,6 +192,7 @@ Accept wildcard characters: False ``` ### -EnableValidation + Verifies that all workflow activities in the session are included in the allowed activities list. The default value is True. @@ -226,6 +211,7 @@ Accept wildcard characters: False ``` ### -MaxActivityProcesses + Specifies the maximum number of processes that can be created in the session to support workflow activities. The default value is 5. @@ -242,6 +228,7 @@ Accept wildcard characters: False ``` ### -MaxConnectedSessions + Specifies the maximum number of remote sessions that are in an operational state. This quota is applied to sessions connected to all remote nodes (target computers). The default value is 100. @@ -259,6 +246,7 @@ Accept wildcard characters: False ``` ### -MaxDisconnectedSessions + Specifies the maximum number of remote sessions that are in a disconnected state. This quota is applied to sessions connected to all remote nodes (target computers). The default value is 1000. @@ -276,6 +264,7 @@ Accept wildcard characters: False ``` ### -MaxPersistenceStoreSizeGB + Specifies the maximum size, in gigabytes, of the persistence store allocated to workflows that run in the session. When the size is exceeded, the persistence store is expanded to save all persisted data, but a warning is displayed and a message is written to the workflow event log. The default value is 10. @@ -296,6 +285,7 @@ Accept wildcard characters: False ``` ### -MaxRunningWorkflows + Specifies that maximum number of workflows that can run in the session concurrently. The default value is 30. @@ -312,6 +302,7 @@ Accept wildcard characters: False ``` ### -MaxSessionsPerRemoteNode + Specifies the maximum number of sessions that can be connected to each remote node (target computer). The default value is 5 @@ -328,6 +319,7 @@ Accept wildcard characters: False ``` ### -MaxSessionsPerWorkflow + Specifies the maximum number of session that can be created to support each workflow. The default value is 5. @@ -344,6 +336,7 @@ Accept wildcard characters: False ``` ### -OutOfProcessActivity + Determines which allowed activities (specified by the **AllowedActivities** parameter) run out-of-process. The default value is **InlineScript**. @@ -360,6 +353,7 @@ Accept wildcard characters: False ``` ### -PersistWithEncryption + Encrypts the data in the persistence store. Consider using this feature when storing persistence data in a network share. The default value is False. @@ -377,6 +371,7 @@ Accept wildcard characters: False ``` ### -PersistencePath + Specifies the location on disk where workflow state and data are stored. Storing the workflow state and data allows workflows to be suspended and resumed, and to recover from interruptions and network failures. @@ -395,6 +390,7 @@ Accept wildcard characters: False ``` ### -RemoteNodeSessionIdleTimeoutSec + Specifies how long a session that is connected to a remote node (target computer) is maintained if it is idle. Enter a value in seconds. @@ -413,6 +409,7 @@ Accept wildcard characters: False ``` ### -SessionThrottleLimit + Specifies how many operations are created to support all workflows started in the session. The default value is 100. @@ -429,6 +426,7 @@ Accept wildcard characters: False ``` ### -WorkflowShutdownTimeoutMSec + Specifies how long the session is maintained after all workflows in the session are forcibly suspended. When the timeout expires, Windows PowerShell closes the session, even if all workflows are not yet suspended. @@ -448,22 +446,28 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### None + You cannot pipe input to this cmdlet. + ## OUTPUTS ### Microsoft.PowerShell.Commands.PSWorkflowExecutionOption ## NOTES -* When the maximum value set by an option is exceeded, the command to create another instance in the session fails, unless noted in the parameter description. For example, if the value of **MaxConnectedSessions** is 100. The command to create the 101st session to a remote node (target computer) fails. -* The properties of a session configuration object vary with the options set for the session configuration and the values of those options. Also, session configurations that use a session configuration file have additional properties. + +- When the maximum value set by an option is exceeded, the command to create another instance in the session fails, unless noted in the parameter description. For example, if the value of **MaxConnectedSessions** is 100. The command to create the 101st session to a remote node (target computer) fails. +- The properties of a session configuration object vary with the options set for the session configuration and the values of those options. Also, session configurations that use a session configuration file have additional properties. In particular, the properties of session configurations that include a **PSWorkflowExecutionOptions** object vary based on the workflow option values. For example, if the session configuration includes a **PSWorkflowExecutionOptions** object that sets a non-default value for the **SessionThrottleLimit** property, the session configuration has a **SessionThrottleLimit** property. Otherwise, it does not. + ## RELATED LINKS [New-PSWorkflowSession](New-PSWorkflowSession.md) diff --git a/reference/3.0/PSWorkflow/New-PSWorkflowSession.md b/reference/3.0/PSWorkflow/New-PSWorkflowSession.md index 03d6036639b7..4968ef3a95c5 100644 --- a/reference/3.0/PSWorkflow/New-PSWorkflowSession.md +++ b/reference/3.0/PSWorkflow/New-PSWorkflowSession.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,10 +7,12 @@ online version: http://go.microsoft.com/fwlink/?LinkID=238268 external help file: PSWorkflow-help.xml title: New-PSWorkflowSession --- - # New-PSWorkflowSession + ## SYNOPSIS + Creates a workflow session. + ## SYNTAX ``` @@ -21,6 +23,7 @@ New-PSWorkflowSession [[-ComputerName] ] [-Credential ] [-Name ``` ## DESCRIPTION + The **New-PSWorkflowSession** cmdlet creates a user-managed session ("PSSession") that is especially designed for running Windows PowerShell workflows. It uses the Microsoft.PowerShell.Workflow session configuration, which includes scripts, type and formatting files, and options that are required for workflows. @@ -30,18 +33,22 @@ You can also add workflow common parameters to this command. For more information about workflow common parameters, see about_WorkflowCommonParametershttp://technet.microsoft.com/library/jj129719(v=wps.620).aspx. This cmdlet is introduced in Windows PowerShell 3.0. + ## EXAMPLES ### Example 1 -``` -PS C:\> New-PSWorkflowSession -ComputerName ServerNode01 -Name WorkflowTests -SessionOption (New-PSSessionOption -OutputBufferingMode Drop) + +```powershell +New-PSWorkflowSession -ComputerName ServerNode01 -Name WorkflowTests -SessionOption (New-PSSessionOption -OutputBufferingMode Drop) ``` This command creates the WorkflowTests session on the ServerNode01 remote computer. The value of the **SessionOption** parameter is a **New-PSSessionOption** command that sets the output buffering mode in the session to Drop. + ### Example 2 -``` -PS C:\> "ServerNode01", "Server12" | New-PSWorkflowSession -Name WorkflowSession -Credential Domain01\Admin01 -ThrottleLimit 150 + +```powershell +"ServerNode01", "Server12" | New-PSWorkflowSession -Name WorkflowSession -Credential Domain01\Admin01 -ThrottleLimit 150 ``` This command creates workflow sessions on the ServerNode01 and Server12 computers. @@ -49,9 +56,11 @@ The command uses the **Credential** parameter to run with the permissions of the The command uses the **ThrottleLimit** parameter to increase the per-command throttle limit to 150. This value takes precedence over the default throttle limit of 100 that is set in the Microsoft.PowerShell.Workflow session configuration. + ## PARAMETERS ### -ApplicationName + Specifies the application name segment of the connection URI. The default value is the value of the **$PSSessionApplicationName** preference variable on the local computer. @@ -75,6 +84,7 @@ Accept wildcard characters: False ``` ### -Authentication + Specifies the mechanism that is used to authenticate the user's credentials. Valid values are "Default", "Basic", "Credssp", "Digest", "Kerberos", "Negotiate", and "NegotiateWithImplicitCredential". The default value is "Default". @@ -101,6 +111,7 @@ Accept wildcard characters: False ``` ### -CertificateThumbprint + Specifies the digital public key certificate (X509) of a user account that has permission to perform this action. Enter the certificate thumbprint of the certificate. @@ -122,6 +133,7 @@ Accept wildcard characters: False ``` ### -ComputerName + Creates a persistent connection (PSSession) to the specified computer. If you enter multiple computer names, Windows PowerShell creates multiple PSSessions, one for each computer. The default is the local computer. @@ -148,6 +160,7 @@ Accept wildcard characters: False ``` ### -Credential + Specifies a user account that has permission to perform this action. The default is the current user. @@ -168,6 +181,7 @@ Accept wildcard characters: False ``` ### -EnableNetworkAccess + Adds an interactive security token to loopback sessions. The interactive token lets you run commands in the loopback session that get data from other computers. For example, you can run a command in the session that copies XML files from a remote computer to the local computer. @@ -201,6 +215,7 @@ Accept wildcard characters: False ``` ### -Name + Specifies a friendly name for the workflow session. You can use the name to refer to the session when using other cmdlets, such as Get-PSSession and Enter-PSSession. @@ -219,6 +234,7 @@ Accept wildcard characters: False ``` ### -Port + Specifies the network port on the remote computer that is used for this connection. To connect to a remote computer, the remote computer must be listening on the port that the connection uses. The default ports are 5985 (the WinRM port for HTTP) and 5986 (the WinRM port for HTTPS). @@ -249,6 +265,7 @@ Accept wildcard characters: False ``` ### -SessionOption + Sets advanced options for the session. Enter a **SessionOption** object, such as one that you create by using the New-PSSessionOption cmdlet. @@ -275,6 +292,7 @@ Accept wildcard characters: False ``` ### -ThrottleLimit + Specifies the maximum number of concurrent connections that can be established to run this command. If you omit this parameter or enter a value of 0 (zero), the default value for the Microsoft.PowerShellWorkflow session configuration, 100, is used. @@ -293,6 +311,7 @@ Accept wildcard characters: False ``` ### -UseSSL + Uses the Secure Sockets Layer (SSL) protocol to establish a connection to the remote computer. By default, SSL is not used. @@ -314,17 +333,23 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + ## INPUTS ### System.Management.Automation.Runspaces.PSSession[], System.String + You can pipe a session or a computer name to **New-PSWorkflowSession**. + ## OUTPUTS ### System.Management.Automation.Runspaces.PSSession ## NOTES -* A **New-PSWorkflowSession** command is equivalent to the following command: `New-PSSession -ConfigurationName Microsoft.PowerShell.Workflow` + +- A **New-PSWorkflowSession** command is equivalent to the following command: `New-PSSession -ConfigurationName Microsoft.PowerShell.Workflow` + ## RELATED LINKS [New-PSSession](../Microsoft.PowerShell.Core/New-PSSession.md) diff --git a/reference/3.0/PSWorkflow/PSWorkflow.md b/reference/3.0/PSWorkflow/PSWorkflow.md index d4635879d0e8..38149c13a673 100644 --- a/reference/3.0/PSWorkflow/PSWorkflow.md +++ b/reference/3.0/PSWorkflow/PSWorkflow.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -9,15 +9,19 @@ Module Guid: 3b6cc51d-c096-4b38-b78d-0fed6277096a title: PSWorkflow Module Name: PSWorkflow --- - # PSWorkflow Module + ## Description + This section contains the help topics for the cmdlets that are installed with Windows PowerShell PSWorkflow module, which contains cmdlets that support the Windows PowerShell Workflow feature. ## PSWorkflow Cmdlets + ### [New-PSWorkflowExecutionOption](New-PSWorkflowExecutionOption.md) + Creates an object that contains session configuration options for workflow sessions. ### [New-PSWorkflowSession](New-PSWorkflowSession.md) + Creates a workflow session. \ No newline at end of file From 420bbc8d44f36247f96e81f24e157b11e5ef41d2 Mon Sep 17 00:00:00 2001 From: Bobby Reed Date: Wed, 30 May 2018 07:25:15 -0400 Subject: [PATCH 2/8] Running batch automation to fix build errors --- .../About/about_Scheduled_Jobs.md | 117 +++++++----- .../About/about_Scheduled_Jobs_Advanced.md | 95 +++++----- .../About/about_Scheduled_Jobs_Basics.md | 107 ++++++----- .../about_Scheduled_Jobs_Troubleshooting.md | 177 +++++++++++++----- .../3.0/PSScheduledJob/Add-JobTrigger.md | 7 +- .../3.0/PSScheduledJob/Disable-JobTrigger.md | 10 +- .../PSScheduledJob/Disable-ScheduledJob.md | 10 +- .../3.0/PSScheduledJob/Enable-JobTrigger.md | 2 +- .../3.0/PSScheduledJob/Enable-ScheduledJob.md | 2 +- .../3.0/PSScheduledJob/Get-JobTrigger.md | 36 ++-- .../3.0/PSScheduledJob/Get-ScheduledJob.md | 2 +- .../PSScheduledJob/Get-ScheduledJobOption.md | 10 +- .../3.0/PSScheduledJob/New-JobTrigger.md | 29 +-- .../PSScheduledJob/New-ScheduledJobOption.md | 35 ++-- .../3.0/PSScheduledJob/PSScheduledJob.md | 15 -- .../PSScheduledJob/Register-ScheduledJob.md | 57 ++++-- .../3.0/PSScheduledJob/Remove-JobTrigger.md | 2 +- .../3.0/PSScheduledJob/Set-JobTrigger.md | 35 ++-- .../3.0/PSScheduledJob/Set-ScheduledJob.md | 47 +++-- .../PSScheduledJob/Set-ScheduledJobOption.md | 6 +- .../PSScheduledJob/Unregister-ScheduledJob.md | 4 +- .../About/about_ActivityCommonParameters.md | 12 +- .../New-PSWorkflowExecutionOption.md | 21 +-- .../3.0/PSWorkflow/New-PSWorkflowSession.md | 10 +- reference/3.0/PSWorkflow/PSWorkflow.md | 1 - 25 files changed, 495 insertions(+), 354 deletions(-) diff --git a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs.md b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs.md index 20d0fa0198e6..b1b891ea469e 100644 --- a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs.md +++ b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,16 +7,12 @@ title: about_Scheduled_Jobs --- # About Scheduled Jobs -## about_Scheduled_Jobs - - - -# SHORT DESCRIPTION +## SHORT DESCRIPTION Describes scheduled jobs and explains how to use and manage scheduled jobs in Windows PowerShell and in Task Scheduler. -# LONG DESCRIPTION +## LONG DESCRIPTION Windows PowerShell scheduled jobs are a useful hybrid of Windows PowerShell background jobs and Task Scheduler tasks. @@ -53,14 +49,14 @@ see [about_Jobs](../../Microsoft.PowerShell.Core/About/about_Jobs.md). For more information about Task Scheduler, see "Task Scheduler" in the TechNet Library at -http://go.microsoft.com/fwlink/?LinkId=232928. +[Task Scheduler](/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc721871(v=ws.11)). NOTE: You can view and manage Windows PowerShell scheduled jobs in Task Scheduler, but the Windows PowerShell job and Scheduled Job cmdlets work only on scheduled jobs that are created in Windows PowerShell. -# SCHEDULED JOB CMDLETS +### SCHEDULED JOB CMDLETS The PSScheduledJob module contains the following cmdlets. @@ -83,44 +79,55 @@ New-ScheduledJobOption: Creates a job options object. Get-ScheduledJobOption: Gets the job options of a scheduled job. Set-ScheduledJobOption: Changes the job options of a scheduled job. -# QUICK START +### QUICK START The following commands create a scheduled job that starts every day at 3:00 AM and runs the Get-Process cmdlet. The job starts even if the computer is running on batteries. +```powershell $trigger = New-JobTrigger -Daily -At 3AM - $options = New-ScheduledJobOption -StartIfOnBattery - Register-ScheduledJob -Name ProcessJob -ScriptBlock {Get-Process} ` -Trigger $trigger -ScheduledJobOption $options +``` The following command gets the scheduled jobs on the local computer. -PS C:> Get-ScheduledJob +```powershell +Get-ScheduledJob +``` +```output Id Name Triggers Command Enabled -- ---- -------- ------- ------- 7 ProcessJob {1} Get-Process True +``` The following command gets the job triggers of ProcessJob. The input parameters specify the scheduled job, not the trigger, because triggers are saved in a scheduled job. -PS C:> Get-JobTrigger -Name ProcessJob +```powershell +Get-JobTrigger -Name ProcessJob +``` +```output Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 1 Daily 11/5/2011 3:00:00 AM True +``` The following command uses the ContinueIfGoingOnBattery parameter of the Set-ScheduledJob cmdlet to change the StopIfGoingOnBatteries property of ProcessJob to False. -PS C:> Get-ScheduledJob -Name ProcessJob | Set-ScheduledJobOption ` +```powershell +Get-ScheduledJob -Name ProcessJob | Set-ScheduledJobOption ` -ContinueIfGoingOnBattery -Passthru +``` +```output StartIfOnBatteries : True StopIfGoingOnBatteries : False WakeToRun : True @@ -135,14 +142,19 @@ RunWithoutNetwork : True DoNotAllowDemandStart : False MultipleInstancePolicy : IgnoreNew JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition +``` The following command gets the ProcessJob scheduled job. -PS C:> Get-ScheduledJob ProcessJob +```powershell +Get-ScheduledJob ProcessJob +``` +```output Id Name Triggers Command Enabled -- ---- -------- ------- ------- 7 ProcessJob {1} Get-Process True +``` The following command uses the Get-Job cmdlet to get all instances of the ProcessJob scheduled job that have run thus far. The Get-Job @@ -152,8 +164,11 @@ imported into the current session. TIP: Notice that you use the ScheduledJob cmdlets to manage scheduled jobs, but you use the Job cmdlets to manage instances of scheduled jobs. -PS C:> Get-Job -Name ProcessJob +```powershell +Get-Job -Name ProcessJob +``` +```output Id Name PSJobTypeName State HasMoreData Location Command -- ---- ------------ ----- ----------- -------- ------- 45 ProcessJob PSScheduledJob Completed True localhost Get-Process @@ -163,11 +178,14 @@ Id Name PSJobTypeName State HasMoreData Location Command 49 ProcessJob PSScheduledJob Completed True localhost Get-Process 50 ProcessJob PSScheduledJob Completed True localhost Get-Process 51 ProcessJob PSScheduledJob Completed True localhost Get-Process +``` The following command gets the results of the most recent instance of the ProcessJob scheduled job (ID = 51). -Receive-Job -ID 51 +```powershell +Receive-Job -Id 51 +``` Even though the Receive-Job command did not include the Keep parameter, the results of the job are saved on disk until you delete them or the @@ -187,14 +205,18 @@ are not subject to job options or affected by job triggers -- and their output is not saved in the Output directory of the scheduled job directory. -PS C:> Start-Job -DefinitionName ProcessJob +```powershell +Start-Job -DefinitionName ProcessJob +``` The following command deletes the ProcessJob scheduled job and all saved results of its job instances. -PS C:> Remove-ScheduledJob ProcessJob +```powershell +Unregister-ScheduledJob ProcessJob +``` -# SCHEDULED JOBS CONCEPTS +### SCHEDULED JOBS CONCEPTS A "scheduled job" runs commands or a script. A scheduled job can include "job triggers" that start the job and "job options" that @@ -246,30 +268,29 @@ the triggers and options of a scheduled job and to find, script, and display the scheduled job to which any job trigger or job option is associated. -# SEE ALSO - -about_Scheduled_Jobs_Basics -about_Scheduled_Jobs_Advanced -about_Scheduled_Jobs_Troubleshooting -about_jobs -Task Scheduler (http://go.microsoft.com/fwlink/?LinkId=232928) - -Add-JobTrigger -Disable-JobTrigger -Disable-ScheduledJob -Enable-JobTrigger -Enable-ScheduledJob -Get-Job -Get-JobTrigger -Get-ScheduledJob -Get-ScheduledJobOption -New-JobTrigger -New-ScheduledJobOption -Receive-Job -Register-ScheduledJob -Remove-JobTrigger -Set-JobTrigger -Set-ScheduledJob -Set-ScheduledJobOption -Start-Job -Unregister-ScheduledJob \ No newline at end of file +## SEE ALSO + +[about_Scheduled_Jobs_Basics](about_Scheduled_Jobs_Basics.md) +[about_Scheduled_Jobs_Advanced](about_Scheduled_Jobs_Advanced.md) +[about_Scheduled_Jobs_Troubleshooting](about_Scheduled_Jobs_Troubleshooting.md) +[about_jobs](../../Microsoft.PowerShell.Core/About/about_Jobs.md) +[Add-JobTrigger](../Add-JobTrigger.md) +[Disable-JobTrigger](../Disable-JobTrigger.md) +[Disable-ScheduledJob](../Disable-ScheduledJob.md) +[Enable-JobTrigger](../Enable-JobTrigger.md) +[Enable-ScheduledJob](../Enable-ScheduledJob.md) +[Get-Job](../../Microsoft.PowerShell.Core/Get-Job.md) +[Get-JobTrigger](../Get-JobTrigger.md) +[Get-ScheduledJob](../Get-ScheduledJob.md) +[Get-ScheduledJobOption](../Get-ScheduledJobOption.md) +[New-JobTrigger](../New-JobTrigger.md) +[New-ScheduledJobOption](../New-ScheduledJobOption.md) +[Receive-Job](../../Microsoft.PowerShell.Core/Receive-Job.md) +[Register-ScheduledJob](../Register-ScheduledJob.md) +[Remove-JobTrigger](../Remove-JobTrigger.md) +[Set-JobTrigger](../Set-JobTrigger.md) +[Set-ScheduledJob](../Set-ScheduledJob.md) +[Set-ScheduledJobOption](../Set-ScheduledJobOption.md) +[Start-Job](../../Microsoft.PowerShell.Core/Start-Job.md) +[Unregister-ScheduledJob](../Unregister-ScheduledJob.md) +[Task Scheduler](/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc721871(v=ws.11)) diff --git a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Advanced.md b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Advanced.md index 6fc3957660b2..e588d197b057 100644 --- a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Advanced.md +++ b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Advanced.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,16 +7,12 @@ title: about_Scheduled_Jobs_Advanced --- # About Scheduled Jobs Advanced -## about_Scheduled_Jobs_Advanced - - - -# SHORT DESCRIPTION +## SHORT DESCRIPTION Explains advanced scheduled job topics, including the file structure that underlies scheduled jobs. -# LONG DESCRIPTION +## LONG DESCRIPTION This topic includes the following sections: @@ -25,8 +21,7 @@ This topic includes the following sections: -- Start a scheduled job immediately -- Manage execution history -# SCHEDULED JOB DIRECTORIES AND FILES - +### SCHEDULED JOB DIRECTORIES AND FILES Windows PowerShell scheduled jobs are both Windows PowerShell jobs and Task Scheduler tasks. Each scheduled job is registered @@ -41,8 +36,11 @@ as the job name. The following is a sample ScheduledJobs directory. +```powershell PS C:\ps-test> dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs +``` +```output Directory: C:\Users\User01\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs Mode LastWriteTime Length Name @@ -54,12 +52,16 @@ d---- 11/7/2011 10:40 AM ProcessJob d---- 11/2/2011 10:25 AM SecureJob d---- 9/27/2011 1:29 PM Test-HelpFiles d---- 9/26/2011 4:22 PM DeployPackage +``` Each scheduled job has its own directory. The directory contains the scheduled job XML file and an Output subdirectory. -PS C:> dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob +```powershell +dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob +``` +```output Directory: C:\Users\User1\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob @@ -67,6 +69,7 @@ Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 11/1/2011 3:00 PM Output -a--- 11/1/2011 3:43 PM 7281 ScheduledJobDefinition.xml +``` The Output directory for a scheduled job contains its execution history. Each time a job trigger starts a scheduled job, Windows @@ -77,8 +80,11 @@ in a Results.xml file and the job status in a Status.xml file. The following command shows the execution history directories for the ProcessJob scheduled job. -PS C:> dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob\Output +```powershell +dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob\Output +``` +```output Directory: C:\Users\User01\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob\Output Mode LastWriteTime Length Name @@ -90,15 +96,20 @@ d---- 11/5/2011 3:00 AM 20111105-030002-251 d---- 11/6/2011 3:00 AM 20111106-030002-174 d---- 11/7/2011 12:00 AM 20111107-000001-914 d---- 11/7/2011 3:00 AM 20111107-030002-376 +``` -PS C:> dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob\Output\20111102-030002-260 +```powershell +dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob\Output\20111102-030002-260 +``` +```output Directory: C:\Users\juneb\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\testjob\output\20111102-030002-260 Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 11/2/2011 3:00 AM 581106 Results.xml -a--- 11/2/2011 3:00 AM 9451 Status.xml +``` You can open and examine the ScheduledJobDefinition.xml, Results.xml and Status.xml files or use the Select-XML cmdlet to parse the files. @@ -107,8 +118,7 @@ WARNING: Do not edit the XML files. If any XML file contains invalid XML, Windows PowerShell deletes the scheduled job and its execution history, including job results. -# START A SCHEDULED JOB IMMEDIATELY - +### START A SCHEDULED JOB IMMEDIATELY You can start a scheduled job immediately in one of two ways: @@ -137,8 +147,7 @@ To import the PSScheduledJob module, type "Import-Module PSScheduledJob" (without quotation marks) or use any Scheduled Job cmdlet, such as Get-ScheduledJob. -# RENAME A SCHEDULED JOB - +### RENAME A SCHEDULED JOB To rename a scheduled job, use the Name parameter of the Set-ScheduledJob cmdlet. When you rename a scheduled job, @@ -147,7 +156,7 @@ the scheduled job directory. However, it doesn't change the names of instances of the scheduled job that have already run. -# GET START AND END TIMES +### GET START AND END TIMES To get the dates and times that job instances started and ended, use the PSBeginTime and PSEndTime properties of the @@ -159,30 +168,25 @@ properties of each job instance in a table. The command uses a calculated property to display the elapsed time of each job instance. -PS C:> Get-job -Name UpdateHelpJob | Format-Table -Property ID, PSBeginTime, PSEndTime, +```powershell +Get-Job -Name UpdateHelpJob | Format-Table -Property ID, PSBeginTime, PSEndTime, @{Label="Elapsed Time";Expression={$.PsEndTime - $.PSBeginTime}} +``` +```output Id PSBeginTime PSEndTime Elapsed Time -- ----------- --------- ------------ -# 2 11/3/2011 3:00:01 AM 11/3/2011 3:00:39 AM 00:00:38.0053854 - -# 3 11/4/2011 3:00:02 AM 11/4/2011 3:01:01 AM 00:00:59.1188475 - -# 4 11/5/2011 3:00:02 AM 11/5/2011 3:00:50 AM 00:00:48.3692034 - -# 5 11/6/2011 3:00:01 AM 11/6/2011 3:00:54 AM 00:00:52.8013036 - -# 6 11/7/2011 3:00:01 AM 11/7/2011 3:00:38 AM 00:00:37.1930350 - -# 7 11/8/2011 3:00:01 AM 11/8/2011 3:00:57 AM 00:00:56.2570556 - -# 8 11/9/2011 3:00:03 AM 11/9/2011 3:00:55 AM 00:00:51.8142222 - -# 9 11/10/2011 3:00:02 AM 11/10/2011 3:00:42 AM 00:00:40.7195954 - - -# MANAGE EXECUTION HISTORY - +2 11/3/2011 3:00:01 AM 11/3/2011 3:00:39 AM 00:00:38.0053854 +3 11/4/2011 3:00:02 AM 11/4/2011 3:01:01 AM 00:00:59.1188475 +4 11/5/2011 3:00:02 AM 11/5/2011 3:00:50 AM 00:00:48.3692034 +5 11/6/2011 3:00:01 AM 11/6/2011 3:00:54 AM 00:00:52.8013036 +6 11/7/2011 3:00:01 AM 11/7/2011 3:00:38 AM 00:00:37.1930350 +7 11/8/2011 3:00:01 AM 11/8/2011 3:00:57 AM 00:00:56.2570556 +8 11/9/2011 3:00:03 AM 11/9/2011 3:00:55 AM 00:00:51.8142222 +9 11/10/2011 3:00:02 AM 11/10/2011 3:00:42 AM 00:00:40.7195954 +``` + +### MANAGE EXECUTION HISTORY You can determine the number of job instance results that are saved for each schedule job and delete the execution history @@ -211,28 +215,35 @@ creates a scheduled job. The command uses the MaxResultCount parameter with a value of 12 to save only the 12 newest job instance results of the scheduled job. +```powershell Register-ScheduledJob -Name ProcessJob -ScriptBlock {Get-Process} -MaxResultCount 12 +``` The following command uses the MaxResultCount parameter of the Set-ScheduledJob cmdlet to increase the number of saved instance results to 15. +```powershell Get-ScheduledJob ProcessJob | Set-ScheduledJob -MaxResultCount 15 +``` The following command deletes the execution history and all currently saved results of the ProcessJob scheduled job. +```powershell Get-ScheduledJob ProcessJob | Set-ScheduledJob -ClearExecutionHistory +``` The following command gets the values of the name and ExecutionHistoryLength properties of all scheduled jobs on the computer and displays them in a table. +```powershell Get-ScheduledJob | Format-Table -Property Name, ExecutionHistoryLength -AutoSize +``` -# SEE ALSO - +## SEE ALSO -about_Scheduled_Jobs -about_Scheduled_Jobs_Troubleshooting -about_Jobs \ No newline at end of file +[about_Scheduled_Jobs](about_Scheduled_Jobs.md) +[about_Scheduled_Jobs_Troubleshooting](about_Scheduled_Jobs_Troubleshooting.md) +[about_Jobs](../../Microsoft.PowerShell.Core/About/about_Jobs.md) diff --git a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Basics.md b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Basics.md index 88b8bb633ed1..11756f9d219f 100644 --- a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Basics.md +++ b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Basics.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,21 +7,17 @@ title: about_Scheduled_Jobs_Basics --- # About Scheduled Jobs Basics -## about_Scheduled_Jobs_Basics - - - -# SHORT DESCRIPTION +## SHORT DESCRIPTION Explains how to create and manage scheduled jobs. -# LONG DESCRIPTION +## LONG DESCRIPTION This topic shows how to perform basic tasks of creating and managing scheduled jobs. For information about more advanced tasks, see about_Scheduled_Jobs_Advanced. -# HOW TO CREATE A SCHEDULED JOB +### HOW TO CREATE A SCHEDULED JOB To create a scheduled job, use the Register-ScheduledJob cmdlet. The cmdlet requires a name and the commands or @@ -38,14 +34,17 @@ The following command creates the ProcessJob, which runs a Get-Process command. This scheduled job has the default job options and no job trigger. -PS C:> Register-ScheduledJob -Name ProcessJob -ScriptBlock { Get-Process } +```powershell +Register-ScheduledJob -Name ProcessJob -ScriptBlock { Get-Process } +``` +```output Id Name Triggers Command Enabled -- ---- -------- ------- ------- 8 ProcessJob {} Get-Process True +``` -# HOW TO CREATE A JOB TRIGGER - +### HOW TO CREATE A JOB TRIGGER Job triggers start a scheduled job automatically. A job trigger can be one-time or recurring schedule or an event, such as when @@ -57,15 +56,17 @@ following command creates a job trigger that starts a job every Monday and Thursday at 5:00 AM. The command saves the job trigger in the $t variable. + +```powershell $t = New-JobTrigger -Weekly -DaysOfWeek "Monday", "Thursday" -At "5:00 AM" +``` Job triggers are optional. You can start a scheduled job at any time by adding the RunNow parameter to your Register-ScheduledJob command, or by using the Start-Job cmdlets. -# HOW TO ADD A JOB TRIGGER - +### HOW TO ADD A JOB TRIGGER When you add a job trigger to a scheduled job, the job trigger is added to the scheduled job XML file for the scheduled job @@ -83,19 +84,22 @@ The following command uses the Register-ScheduledJob cmdlet to create the process job. It uses the Trigger parameter to specify the job trigger in the $t variable. +```powershell Register-ScheduledJob -Name ProcessJob -ScriptBlock {Get-Command} -Trigger $t +``` You can also add a job trigger to an existing scheduled job at any time. The following command adds the job trigger in the $t variable to the ProcessJob scheduled job. +```powershell Add-JobTrigger -Name ProcessJob -Trigger $t +``` As a result of this command, the job trigger starts the ProcessJob automatically every Monday and Thursday at 5:00 AM. -# HOW TO GET A JOB TRIGGER - +### HOW TO GET A JOB TRIGGER To get the job trigger of a scheduled job, use the Get-JobTrigger cmdlet. Use the Name, ID, and InputObject parameters @@ -103,14 +107,17 @@ to specify the scheduled job (not the job trigger). The following command gets the job trigger of the ProcessJob. -PS C:> Get-JobTrigger -Name ProcessJob +```powershell +Get-JobTrigger -Name ProcessJob +``` +```output Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 1 Weekly 11/7/2011 5:00:00 AM {Monday, Thursday} True +``` -# HOW TO CREATE JOB OPTIONS - +### HOW TO CREATE JOB OPTIONS Job options establish conditions for starting and running the job. Every job has the default job options unless you change @@ -122,7 +129,7 @@ Windows PowerShell uses the same job options that Task Scheduler uses. For detailed information about the job options, see the help topic for the New-ScheduledJobOption cmdlet. Type "Get-Help New-ScheduledJobOption" or see the help topic online at -http://go.microsoft.com/fwlink/?LinkID=223915. +[New-ScheduledJobOption](../Get-JobTrigger.md). Job options are stored in the scheduled job XML file. You can set job options when you create a scheduled job or change them at @@ -134,10 +141,11 @@ option runs the scheduled job even if the computer is in the Sleep or Hibernate state at the scheduled start time. The command saves the job options in the $o variable. +```powershell $o = New-ScheduledJobOption -WakeToRun +``` -# HOW TO GET JOB OPTIONS - +### HOW TO GET JOB OPTIONS To get the job options of a scheduled job, use the Get-ScheduledJobOption cmdlet. Use the Name, ID, and @@ -146,8 +154,11 @@ the job options). The following command gets the job options of the ProcessJob. -PS C:> Get-ScheduledJobOption -Name ProcessJob +```powershell +Get-ScheduledJobOption -Name ProcessJob +``` +```output StartIfOnBatteries : False StopIfGoingOnBatteries : True WakeToRun : False @@ -162,18 +173,20 @@ RunWithoutNetwork : True DoNotAllowDemandStart : False MultipleInstancePolicy : IgnoreNew JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition +``` -# HOW TO CHANGE JOB OPTIONS - +### HOW TO CHANGE JOB OPTIONS You can change the job options of a scheduled job when you create a scheduled job or at any time thereafter. -The following command uses the Register-JobTrigger cmdlet +The following command uses the Add-JobTrigger cmdlet to create the process job. It uses the ScheduledJobOption parameter to specify the job options in the $o variable. -Register-JobTrigger -Name ProcessJob -ScriptBlock {Get-Process} -ScheduledJobOption $o +```powershell +Add-JobTrigger -Name ProcessJob -ScriptBlock {Get-Process} -ScheduledJobOption $o +``` You can also change the job options to an existing scheduled job at any time. The following command uses the @@ -191,10 +204,11 @@ ProcessJob. It uses the Get-ScheduledJobOption cmdlet to get the job options in the ProcessJob and the Set-ScheduledJobOption cmdlet to change the WakeToRun job option in the ProcessJob to True. +```powershell Get-ScheduledJob -Name ProcessJob | Get-ScheduledJobOption | Set-ScheduledJobOption -WakeToRun +``` -# HOW TO GET SCHEDULED JOB INSTANCES - +### HOW TO GET SCHEDULED JOB INSTANCES When a scheduled job is started, Windows PowerShell creates a job instance that is similar to a standard Windows PowerShell @@ -212,15 +226,19 @@ all active standard jobs), use the Get-Job cmdlet. The following command imports the PSScheduledJob module and then gets all jobs on the local computer. -PS C:> Import-Module PSScheduledJob - -PS C:> Get-Job +```powershell +Import-Module PSScheduledJob +Get-Job +``` The following command gets all instances of the ProcessJob on the local computer. -PS C:> Get-Job -Name ProcessJob +```powershell +Get-Job -Name ProcessJob +``` +```output Id Name PSJobTypeName State HasMoreData Location Command -- ---- ------------ ----- ----------- -------- ------- 45 ProcessJob PSScheduledJob Completed True localhost Get-Process @@ -230,6 +248,7 @@ Id Name PSJobTypeName State HasMoreData Location Command 49 ProcessJob PSScheduledJob Completed True localhost Get-Process 50 ProcessJob PSScheduledJob Completed True localhost Get-Process 51 ProcessJob PSScheduledJob Completed True localhost Get-Process +``` The default display does not show the start time, which typically distinguishes instances of the same scheduled job. @@ -237,8 +256,11 @@ distinguishes instances of the same scheduled job. The following command uses the Format-Table cmdlet to display the Name, ID, and BeginTime properties of the scheduled job. -PS C:> Get-Job ProcessJob | Format-Table -Property Name, ID, BeginTime +```powershell +Get-Job ProcessJob | Format-Table -Property Name, ID, BeginTime +``` +```output Name Id BeginTime ---- -- --------- ProcessJob 43 11/2/2011 3:00:02 AM @@ -249,9 +271,9 @@ ProcessJob 47 11/6/2011 3:00:02 AM ProcessJob 48 11/7/2011 12:00:01 AM ProcessJob 49 11/7/2011 3:00:02 AM ProcessJob 50 11/8/2011 3:00:02 AM +``` -# GET SCHEDULED JOB RESULTS - +### GET SCHEDULED JOB RESULTS To get the results of an instance of a scheduled job, use the Receive-Job cmdlet. @@ -265,9 +287,10 @@ as Get-ScheduledJob. The following command gets the results of the newest instance of the ProcessJob scheduled job (ID = 51) -PS C:> Import-Module PSScheduledJob - -PS C:> Receive-Job -ID 51 -Keep +```powershell +Import-Module PSScheduledJob +Receive-Job -Id 51 -Keep +``` The results of scheduled jobs are saved on disk, so the Keep parameter of Receive-Job is not required. However, without the Keep parameter, @@ -275,8 +298,8 @@ you can get the results of a scheduled job only once in each Windows PowerShell session. To start a new Windows PowerShell session, type "PowerShell" or open a new Windows PowerShell window. -# SEE ALSO +## SEE ALSO -about_Scheduled_Jobs -about_Scheduled_Jobs_Advanced -about_Scheduled_Jobs_Troubleshooting \ No newline at end of file +[about_Scheduled_Jobs](about_Scheduled_Jobs.md) +[about_Scheduled_Jobs_Advanced](about_Scheduled_Jobs_Advanced.md) +[about_Scheduled_Jobs_Troubleshooting](about_Scheduled_Jobs_Troubleshooting.md) diff --git a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Troubleshooting.md b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Troubleshooting.md index d5b0b8af63e8..0521c92c4994 100644 --- a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Troubleshooting.md +++ b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Troubleshooting.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -7,15 +7,11 @@ title: about_Scheduled_Jobs_Troubleshooting --- # About Scheduled Jobs Troubleshooting -## about_Scheduled_Jobs_Troubleshooting - - - -# SHORT DESCRIPTION +## SHORT DESCRIPTION Explains how to resolve problems with scheduled jobs -# LONG DESCRIPTION +## LONG DESCRIPTION This section describes some of the problems that you might encounter when using the scheduled job features of Windows PowerShell and it suggests @@ -30,8 +26,7 @@ This topic contains the following sections: -- CANNOT GET SCHEDULED JOB : SCHEDULED JOB IS CORRUPTED -- JOB CMDLETS CANNOT CONSISTENTLY FIND SCHEDULED JOBS -# CANNOT FIND JOB RESULTS - +## CANNOT FIND JOB RESULTS -- Basic method for getting job results in Windows PowerShell @@ -47,9 +42,12 @@ Get-ScheduledJob. To get a list of all instances of a scheduled job, use the Get-Job cmdlet. -PS C:> Import-Module PSScheduledJob -PS C:> Get-Job ProcessJob +```powershell +Import-Module PSScheduledJob +Get-Job ProcessJob +``` +```output Id Name PSJobTypeName State HasMoreData Location -- ---- ------------- ----- ----------- -------- 43 ProcessJob PSScheduledJob Completed False localhost @@ -60,12 +58,16 @@ Id Name PSJobTypeName State HasMoreData Location 48 ProcessJob PSScheduledJob Completed False localhost 49 ProcessJob PSScheduledJob Completed False localhost 50 ProcessJob PSScheduledJob Completed False localhost +``` The following command uses the Format-Table cmdlet to display the Name, ID, and PSBeginTime properties of a scheduled job instance in a table. -PS C:> Get-Job ProcessJob | Format-Table -Property Name, ID, PSBeginTime -Auto +```powershell +Get-Job ProcessJob | Format-Table -Property Name, ID, PSBeginTime -AutoSize +``` +```output Name Id PSBeginTime ---- -- --------- ProcessJob 43 11/2/2011 3:00:02 AM @@ -76,12 +78,15 @@ ProcessJob 47 11/6/2011 3:00:02 AM ProcessJob 48 11/7/2011 12:00:01 AM ProcessJob 49 11/7/2011 3:00:02 AM ProcessJob 50 11/8/2011 3:00:02 AM +``` To get the results of an instance of a scheduled job, use the Receive-Job cmdlet. The following command gets the results of the newest instance of the ProcessJob (ID = 50). -PS C:> Receive-Job -ID 50 +```powershell +Receive-Job -Id 50 +``` -- Basic method for finding job results on disk @@ -106,9 +111,12 @@ C:\Users\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJob For example, the following command gets the on-disk execution history of the ProcessJob scheduled job. -PS C:> dir $home\AppData\Local\Microsoft\Windows\PowerShell +```powershell +dir $home\AppData\Local\Microsoft\Windows\PowerShell \ScheduledJobs\ProcessJob\Output +``` +```output Directory: C:\Users\User01\AppData\Local\Microsoft\Windows\PowerShell \ScheduledJobs\ProcessJob\Output @@ -121,6 +129,7 @@ d---- 11/5/2011 3:00 AM 20111105-030002-251 d---- 11/6/2011 3:00 AM 20111106-030002-174 d---- 11/7/2011 12:00 AM 20111107-000001-914 d---- 11/7/2011 3:00 AM 20111107-030002-376 +``` Each timestamp-named directory represents a job instance. The results of each job instance are saved in a Results.xml file in the @@ -129,11 +138,15 @@ timestamp-named directory. For example, the following command gets the Results.xml files for every saved instance of the ProcessJob scheduled job. -PS C:> dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs +```powershell +dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs \ProcessJob\Output\*\Results.xml +``` +```output Directory: C:\Users\User01\Appdata\Local\Microsoft\Windows\PowerShell \ScheduledJobs\ProcessJob\Output +``` If the Results.xml file is missing, Windows PowerShell cannot return or display the job results. @@ -149,8 +162,9 @@ their results. To import the PSScheduledJob module, type: +```powershell Import-Module PSScheduledJob - +``` -- The Receive-Job cmdlet might already have returned the results in the current session. @@ -169,44 +183,64 @@ To get the job instance results again, start a new Windows PowerShell session (type "PowerShell" without quotation marks), import the PSScheduledJob module, and try the Receive-Job command again. -PS C:> Receive-Job -ID 50 -PS C:> #No results -PS C:> PowerShell +```powershell +Receive-Job -ID 50 +``` + +```output +PS> #No results +``` +```powershell +PowerShell.exe +``` + +```output Windows PowerShell Copyright (C) 2012 Microsoft Corporation. All rights reserved. +``` -PS C:> Import-Module PSScheduledJob -PS C:> Receive-Job -ID 50 +```powershell +Import-Module PSScheduledJob +Receive-Job -Id 50 +``` +```output Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 1213 33 12348 21676 88 25.71 1608 CcmExec 29 4 1168 2920 43 0.02 748 conhost 46 6 2208 4612 45 0.03 1640 conhost - -# ... - +... +``` To get the result of a job instance more than one time in a session, use the Keep parameter of the Receive-Job cmdlet. -PS C:> Import-Module PSScheduledJob -PS C:> Receive-Job -ID 50 -Keep +```powershell +Import-Module PSScheduledJob +Receive-Job -Id 50 -Keep +``` +```output Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 1213 33 12348 21676 88 25.71 1608 CcmExec 29 4 1168 2920 43 0.02 748 conhost 46 6 2208 4612 45 0.03 1640 conhost +``` -PS C:> Receive-Job -ID 50 -Keep +```powershell +Receive-Job -Id 50 -Keep +``` +```output Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 1213 33 12348 21676 88 25.71 1608 CcmExec 29 4 1168 2920 43 0.02 748 conhost 46 6 2208 4612 45 0.03 1640 conhost +``` -- The scheduled job might be corrupted. @@ -216,7 +250,9 @@ results of a corrupted scheduled job. To determine if a scheduled job still exists, use the Get-ScheduledJob cmdlet. -PS C:> Get-ScheduledJob +```powershell +Get-ScheduledJob +``` -- The number of results might have exceeded the ExecutionHistoryLength of the scheduled job. @@ -230,12 +266,16 @@ instance to make room for each new job instance. To get the value of the ExecutionHistoryLength property of a scheduled job, use the following command format: +``` (Get-ScheduledJob ).ExecutionHistoryLength +``` For example, the following command gets the value of the ExecutionHistoryLength property of the ProcessJob scheduled job. -PS C:> (Get-ScheduledJob ProcessJob).ExecutionHistoryLength +```powershell +(Get-ScheduledJob ProcessJob).ExecutionHistoryLength +``` To set or change the value of the ExecutionHistoryLength property, use the MaxResultCount parameter of the Register-ScheduledJob and @@ -244,7 +284,9 @@ Set-ScheduledJob cmdlets. The following command increases the value of the ExecutionHistoryLength property to 50. -PS C:> Get-ScheduledJob ProcessJob | Set-ScheduledJob -MaxResultCount 50 +```powershell +Get-ScheduledJob ProcessJob | Set-ScheduledJob -MaxResultCount 50 +``` -- The job instance results might have been deleted @@ -259,7 +301,9 @@ ClearExecutionHistory parameter of the scheduled job. The following command deletes the execution history of the ProcessJob scheduled job. -PS C:> Get-ScheduledJob ProcessJob | Set-ScheduledJob -ClearExecutionHistory +```powershell +Get-ScheduledJob ProcessJob | Set-ScheduledJob -ClearExecutionHistory +``` Also, the Remove-Job cmdlet deletes job results. When you use Remove-Job to delete a scheduled job, it deletes all instances @@ -283,8 +327,7 @@ they exist only in the session in which they are created. If you delete the job (Remove-Job), close the session or close Windows PowerShell, the job instance and its results are deleted. -# SCHEDULED JOB DOES NOT RUN - +### SCHEDULED JOB DOES NOT RUN -- Scheduled jobs do not run automatically if the job triggers or the scheduled job are disabled. @@ -292,32 +335,49 @@ scheduled job are disabled. Use the Get-ScheduledJob cmdlet to get the scheduled job. Verify that the value of the Enabled property of the scheduled job is True ($true). -PS C:> Get-ScheduledJob ProcessJob +```powershell +Get-ScheduledJob ProcessJob +``` +```output Id Name Triggers Command Enabled -- ---- -------- ------- ------- 4 ProcessJob {1, 2} Get-Process True +``` -PS C:> (Get-ScheduledJob ProcessJob).Enabled +```powershell +(Get-ScheduledJob ProcessJob).Enabled +``` + +```output True +``` Use the Get-JobTrigger cmdlet to get the job triggers of the scheduled job. Verify that the value of the Enabled property of the job trigger is True ($true) -PS C:> Get-ScheduledJob ProcessJob | Get-JobTrigger +```powershell +Get-ScheduledJob ProcessJob | Get-JobTrigger +``` +```output Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 1 Weekly 11/7/2011 5:00:00 AM {Monday, Thursday} True 2 Daily 11/7/2011 3:00:00 PM True +``` -PS C:> Get-ScheduledJob ProcessJob | Get-JobTrigger | Format-Table ID, Enabled -Auto +```powershell +Get-ScheduledJob ProcessJob | Get-JobTrigger | Format-Table ID, Enabled -AutoSize +``` +```output Id Enabled -- ------- 1 True 2 True +``` -- Scheduled jobs do not run automatically if the job triggers are invalid. @@ -340,8 +400,11 @@ IdleDuration or a brief IdleTimeout might never run. Use the Get-ScheduledJobOption cmdlet to examine the job options and their values. -PS C:> Get-ScheduledJob -Name ProcessJob +```powershell +Get-ScheduledJob -Name ProcessJob +``` +```output StartIfOnBatteries : False StopIfGoingOnBatteries : True WakeToRun : True @@ -356,9 +419,10 @@ RunWithoutNetwork : True DoNotAllowDemandStart : False MultipleInstancePolicy : IgnoreNew JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition +``` For descriptions of the scheduled job options, see the help topic for -the New-ScheduledJobOption cmdlet (http://go.microsoft.com/fwlink/?LinkID=223919). +[New-ScheduledJobOption](../New-ScheduledJobOption.md). -- The scheduled job instance might have failed. @@ -373,7 +437,9 @@ Use the following methods to detect and correct job failures. use Event Viewer or a Windows PowerShell command such as the following: -Get-WinEvent -LogName Microsoft-Windows-TaskScheduler/Operational | Where {$_.Message -like "fail"} +```powershell +Get-WinEvent -LogName Microsoft-Windows-TaskScheduler/Operational | Where-Object {$_.Message -like "fail"} +``` -- Check the job record in Task Scheduler. Windows PowerShell scheduled jobs are stored in the following Task Scheduled folder: @@ -389,8 +455,7 @@ parameter in the Register-ScheduledJob or Set-ScheduledJob command. If that user does not have permission to run the commands or scripts, the job fails. -# CANNOT GET SCHEDULED JOB : SCHEDULED JOB IS CORRUPTED - +### CANNOT GET SCHEDULED JOB : SCHEDULED JOB IS CORRUPTED On rare occasions, scheduled jobs can become corrupted or contain internal contradictions that cannot be resolved. Typically, this @@ -436,8 +501,11 @@ automatically when you get or use any cmdlet in the module. When the PSScheduledJob cmdlet is not in the current session, the following command sequence is possible. -PS C:> Get-Job ProcessJob +```powershell +Get-Job ProcessJob +``` +```output Get-Job : The command cannot find the job because the job name ProcessJob was not found. Verify the value of the Name parameter, and then try the command again. @@ -445,16 +513,24 @@ Verify the value of the Name parameter, and then try the command again. PSArgumentException + FullyQualifiedErrorId : JobWithSpecifiedNameNotFound,Microsoft.PowerShell. Commands.GetJobCommand +``` -PS C:> Get-Job -PS C:> Get-ScheduledJob ProcessJob +```powershell +Get-Job +Get-ScheduledJob ProcessJob +``` +```output Id Name Triggers Command Enabled -- ---- -------- ------- ------- 4 ProcessJob {1} Get-Process True +``` -PS C:> Get-Job ProcessJob +```powershell +Get-Job ProcessJob +``` +```output Id Name PSJobTypeName State HasMoreData Location -- ---- ------------- ----- ----------- -------- 43 ProcessJob PSScheduledJob Completed True localhost @@ -465,12 +541,13 @@ Id Name PSJobTypeName State HasMoreData Location 48 ProcessJob PSScheduledJob Completed True localhost 49 ProcessJob PSScheduledJob Completed True localhost 50 ProcessJob PSScheduledJob Completed True localhost +``` This behavior occurs because the Get-ScheduledJob command automatically imports the PSScheduledJob module, and then runs the command. -# SEE ALSO +## SEE ALSO -about_Scheduled_Jobs -about_Scheduled_Jobs_Basics -about_Scheduled_Jobs_Advanced \ No newline at end of file +[about_Scheduled_Jobs](about_Scheduled_Jobs.md) +[about_Scheduled_Jobs_Basics](about_Scheduled_Jobs_Basics.md) +[about_Scheduled_Jobs_Advanced](about_Scheduled_Jobs_Advanced.md) diff --git a/reference/3.0/PSScheduledJob/Add-JobTrigger.md b/reference/3.0/PSScheduledJob/Add-JobTrigger.md index 21fb422745a2..7685fe72cecc 100644 --- a/reference/3.0/PSScheduledJob/Add-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/Add-JobTrigger.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -84,7 +84,6 @@ The value of the **Trigger** parameter is a New-JobTrigger command that creates ```powershell $t = Get-JobTrigger -Name BackupArchives - Add-JobTrigger -Name TestBackup, BackupLogs -Trigger $t ``` @@ -174,7 +173,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md). ## INPUTS @@ -224,4 +223,4 @@ This cmdlet does not return any output. [Set-ScheduledJobOption](Set-ScheduledJobOption.md) -[Unregister-ScheduledJob](Unregister-ScheduledJob.md) \ No newline at end of file +[Unregister-ScheduledJob](Unregister-ScheduledJob.md) diff --git a/reference/3.0/PSScheduledJob/Disable-JobTrigger.md b/reference/3.0/PSScheduledJob/Disable-JobTrigger.md index a96484f8b6a3..4d7206946778 100644 --- a/reference/3.0/PSScheduledJob/Disable-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/Disable-JobTrigger.md @@ -55,14 +55,10 @@ A pipeline operator sends the job trigger to the **Disable-JobTrigger** cmdlet, ### Example 2: Disable all job triggers -The first command uses the Get-ScheduledJob cmdlet to get the Backup-Archives and Inventory scheduled jobs. A pipeline operator (|) sends the scheduled jobs to the Get-JobTrigger cmdlet, which gets all job triggers of the scheduled jobs. Another pipeline operator sends the job triggers to the **Disable-JobTrigger** cmdlet, which disables them.The first command uses the **Get-ScheduledJob** cmdlet to get the jobs, because its **Name** parameter takes multiple names. - ```powershell Get-ScheduledJob -Name Backup-Archives, Inventory | Get-JobTrigger | Disable-JobTrigger ``` -The second command displays the results. The command repeats the **Get-ScheduledJob** and **Get-JobTrigger** command. A pipeline operator sends the job triggers to the Format-Table cmdlet, which displays the job triggers in a table. The **Format-Table** command adds a **JobName** property that displays the value of the **Name** property of the scheduled job in the **JobDefinition** property of the job trigger object. - ```powershell Get-ScheduledJob -Name Backup-Archives, Inventory | Get-JobTrigger | Format-Table -Property ID, Frequency, At, DaysOfWeek, Enabled, @{Label="JobName";Expression={$_.JobDefinition.Name}} -AutoSize ``` @@ -78,6 +74,10 @@ Id Frequency At DaysOfWeek Enabled JobName These commands disable all job triggers on two scheduled jobs and display the results. +The first command uses the Get-ScheduledJob cmdlet to get the Backup-Archives and Inventory scheduled jobs. A pipeline operator (|) sends the scheduled jobs to the Get-JobTrigger cmdlet, which gets all job triggers of the scheduled jobs. Another pipeline operator sends the job triggers to the **Disable-JobTrigger** cmdlet, which disables them.The first command uses the **Get-ScheduledJob** cmdlet to get the jobs, because its **Name** parameter takes multiple names. + +The second command displays the results. The command repeats the **Get-ScheduledJob** and **Get-JobTrigger** command. A pipeline operator sends the job triggers to the Format-Table cmdlet, which displays the job triggers in a table. The **Format-Table** command adds a **JobName** property that displays the value of the **Name** property of the scheduled job in the **JobDefinition** property of the job trigger object. + ### Example 3: Disable job trigger of a scheduled job on a remote computer. ```powershell @@ -146,7 +146,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSScheduledJob/Disable-ScheduledJob.md b/reference/3.0/PSScheduledJob/Disable-ScheduledJob.md index 82d999d325e4..fb76c0a40683 100644 --- a/reference/3.0/PSScheduledJob/Disable-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Disable-ScheduledJob.md @@ -116,8 +116,6 @@ The command uses the **Name** parameter of **Disable-ScheduledJob** to select th ### Example 5: Disable a scheduled job by its global ID -The first command demonstrates one way of finding the GlobalID of a scheduled job. The command uses the Get-ScheduledJob cmdlet to get the scheduled jobs on the computer. A pipeline operator (|) sends the scheduled jobs to the Format-Table cmdlet which displays the **Name**, **GlobalID**, and **Command** properties of each job in a table. - ```powershell Get-ScheduledJob | Format-Table -Property Name, GlobalID, Command -Autosize ``` @@ -132,8 +130,6 @@ Test-HelpFiles d77020ca-f20d-42be-86c8-fc64df97db90 .\Test-HelpFiles.ps1 Test-HelpFiles 2f1606d2-c6cf-4bef-8b1c-ae36a9cc9934 .\Test-DomainHelpFiles.ps1 ``` -The second command uses the Get-ScheduledJob cmdlet to get the scheduled jobs on the computer. A pipeline operator (|) sends the scheduled jobs to the Where-Object cmdlet, which selects the scheduled job with the specified global ID. Another pipeline operator sends the job to the Disable-ScheduledJob cmdlet, which disables it. - ```powershell Get-ScheduledJob | Where-Object {$_.GlobalID = d77020ca-f20d-42be-86c8-fc64df97db90} | Disable-ScheduledJob ``` @@ -142,6 +138,10 @@ This examples shows how to disable a scheduled job by using its global identifie The value of the GlobalID property of a scheduled job is a unique identifier (GUID). Use the GlobalID value when precision is required, such as when you are disabling scheduled jobs on multiple computers. +The first command demonstrates one way of finding the GlobalID of a scheduled job. The command uses the Get-ScheduledJob cmdlet to get the scheduled jobs on the computer. A pipeline operator (|) sends the scheduled jobs to the Format-Table cmdlet which displays the **Name**, **GlobalID**, and **Command** properties of each job in a table. + +The second command uses the Get-ScheduledJob cmdlet to get the scheduled jobs on the computer. A pipeline operator (|) sends the scheduled jobs to the Where-Object cmdlet, which selects the scheduled job with the specified global ID. Another pipeline operator sends the job to the Disable-ScheduledJob cmdlet, which disables it. + ## PARAMETERS ### -Id @@ -249,7 +249,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSScheduledJob/Enable-JobTrigger.md b/reference/3.0/PSScheduledJob/Enable-JobTrigger.md index bc8e7f627b97..1fc9359be142 100644 --- a/reference/3.0/PSScheduledJob/Enable-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/Enable-JobTrigger.md @@ -152,7 +152,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSScheduledJob/Enable-ScheduledJob.md b/reference/3.0/PSScheduledJob/Enable-ScheduledJob.md index 0baf0b381578..ec78cfa769f9 100644 --- a/reference/3.0/PSScheduledJob/Enable-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Enable-ScheduledJob.md @@ -219,7 +219,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSScheduledJob/Get-JobTrigger.md b/reference/3.0/PSScheduledJob/Get-JobTrigger.md index b151bb8190d0..e0e2525cbf73 100644 --- a/reference/3.0/PSScheduledJob/Get-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/Get-JobTrigger.md @@ -64,8 +64,6 @@ The command uses the **Name** parameter of Get-JobTrigger to get the job trigger ### Example 2: Get a job trigger by ID -The first command uses the Get-ScheduledJob cmdlet to display the scheduled jobs on the local computer. The display includes the IDs of the scheduled jobs. - ```powershell Get-ScheduledJob ``` @@ -79,13 +77,19 @@ Id Name Triggers Command 4 TestJob {} \\Server\Share\Run-AllTests.ps1 True ``` -The second command uses the **Get-JobTrigger** cmdlet to get the job trigger for the Test-HelpFiles job (ID = 3) - ```powershell Get-JobTrigger -Id 3 ``` -The example uses the **ID** parameter of Get-JobTrigger to get the job triggers of a scheduled job. +```output +Id Name Triggers Command Enabled +-- ---- -------- ------- ------- +3 Test-HelpFiles {1} \\Server\Share\Test-HelpFiles.ps1 True +``` + +The first command uses the Get-ScheduledJob cmdlet to display the scheduled jobs on the local computer. The display includes the IDs of the scheduled jobs. + +The second command uses the **Get-JobTrigger** cmdlet to get the job trigger for the Test-HelpFiles job (ID = 3) ### Example 3: Get job triggers by piping a job @@ -129,14 +133,10 @@ In addition to the job trigger properties that are displayed by default, the com ### Example 6: Get the job trigger property of a scheduled job -The command uses the Get-ScheduledJob cmdlet to get the Test-HelpFiles scheduled job. Then it uses the dot method (.) to get the **JobTriggers** property of the Test-HelpFiles scheduled job. - ```powershell (Get-ScheduledJob Test-HelpFiles).JobTriggers ``` -The second command uses the Get-ScheduledJob cmdlet to get all scheduled jobs on the local computer. It uses the Foreach-Object cmdlet to get the value of the JobTrigger property of each scheduled job. - ```powershell Get-ScheduledJob | ForEach-Object {$_.JobTriggers} ``` @@ -145,9 +145,11 @@ The job triggers of a scheduled job are stored in the **JobTriggers** property o This example shows alternatives to using the Get-JobTrigger cmdlet to get job triggers. The results are identical to using the **Get-JobTrigger** cmdlet and the techniques can be used interchangeably. -### Example 7: Compare job triggers +The first command uses the Get-ScheduledJob cmdlet to get the Test-HelpFiles scheduled job. Then it uses the dot method (.) to get the **JobTriggers** property of the Test-HelpFiles scheduled job. -The first command gets the job trigger of the ArchiveProjects scheduled job. The command pipes the job trigger to the Tee-Object cmdlet, which saves the job trigger in the $t1 variable and displays it at the command line. +The second command uses the Get-ScheduledJob cmdlet to get all scheduled jobs on the local computer. It uses the Foreach-Object cmdlet to get the value of the JobTrigger property of each scheduled job. + +### Example 7: Compare job triggers ```powershell Get-ScheduledJob -Name ArchiveProjects | Get-JobTrigger | Tee-Object -Variable t1 @@ -159,8 +161,6 @@ Id Frequency Time DaysOfWeek Enable 0 Daily 9/26/2011 3:00:00 AM True ``` -The second command gets the job trigger of the Test-HelpFiles scheduled job. The command pipes the job trigger to the Tee-Object cmdlet, which saves the job trigger in the $t2 variable and displays it at the command line. - ```powershell Get-ScheduledJob -Name Test-HelpFiles | Get-JobTrigger | Tee-Object -Variable t2 ``` @@ -171,8 +171,6 @@ Id Frequency Time DaysOfWeek Enable 0 Daily 9/26/2011 3:00:00 AM True ``` -The third command compares the job triggers in the $t1 and $t2 variables. It uses the Get-Member cmdlet to get the properties of the job trigger in the $t1 variable. It pipes the properties to the ForEach-Object cmdlet, which compares each property to the properties of the job trigger in the $t2 variable by name. The command then pipes the differing properties to the Format-List cmdlet, which displays them in a list.The output indicates that, although the job triggers appear to be the same, the HelpFiles job trigger includes a random delay of three (3) minutes. - ```powershell $t1 | Get-Member -MemberType property | ForEach-Object { Compare-Object $t1 $t2 -Property $_.Name} ``` @@ -186,6 +184,12 @@ RandomDelay SideIndicator This example shows how to compare the job triggers of two scheduled jobs. +The first command gets the job trigger of the ArchiveProjects scheduled job. The command pipes the job trigger to the Tee-Object cmdlet, which saves the job trigger in the $t1 variable and displays it at the command line. + +The second command gets the job trigger of the Test-HelpFiles scheduled job. The command pipes the job trigger to the Tee-Object cmdlet, which saves the job trigger in the $t2 variable and displays it at the command line. + +The third command compares the job triggers in the $t1 and $t2 variables. It uses the Get-Member cmdlet to get the properties of the job trigger in the $t1 variable. It pipes the properties to the ForEach-Object cmdlet, which compares each property to the properties of the job trigger in the $t2 variable by name. The command then pipes the differing properties to the Format-List cmdlet, which displays them in a list.The output indicates that, although the job triggers appear to be the same, the HelpFiles job trigger includes a random delay of three (3) minutes. + ## PARAMETERS ### -Id @@ -265,7 +269,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSScheduledJob/Get-ScheduledJob.md b/reference/3.0/PSScheduledJob/Get-ScheduledJob.md index 3540674c3a8a..9e2523ea0906 100644 --- a/reference/3.0/PSScheduledJob/Get-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Get-ScheduledJob.md @@ -123,7 +123,7 @@ Accept wildcard characters: True ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSScheduledJob/Get-ScheduledJobOption.md b/reference/3.0/PSScheduledJob/Get-ScheduledJobOption.md index 173daa02befe..0b34224c0fa0 100644 --- a/reference/3.0/PSScheduledJob/Get-ScheduledJobOption.md +++ b/reference/3.0/PSScheduledJob/Get-ScheduledJobOption.md @@ -105,8 +105,6 @@ A pipeline operator (|) sends the scheduled jobs to the **Get-ScheduledJobOption ### Example 3: Get selected job options -The first command gets job options in which the **RunElevated** property has a value of "True" ($true) and the **RunWithoutNetwork** property has a value of "False" ($false) The output shows the job options object that was selected. - ```powershell Get-ScheduledJob | Get-ScheduledJobOption | Where-Object {$_.RunElevated -and !$_.WaketoRun} ``` @@ -141,8 +139,6 @@ MultipleInstancePolicy : Ignore NewJobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition ``` -The second command shows how to find to which scheduled job the job options belong. This command uses a pipeline operator (|) to send the selected job options to the ForEach-Object cmdlet which gets the **JobDefinition** property of each options object. The **JobDefinition** property contains the originating job object. The results show that the selected options came from the "DeployPkg" scheduled job. - ```powershell Get-ScheduledJob | Get-ScheduledJobOption | Where-Object {$_.RunElevated -and !$_.WaketoRun} | ForEach-Object {$_.JobDefinition} ``` @@ -155,6 +151,10 @@ Id Name Triggers Command This example shows how to find job options object with particular values. +The first command gets job options in which the **RunElevated** property has a value of "True" ($true) and the **RunWithoutNetwork** property has a value of "False" ($false) The output shows the job options object that was selected. + +The second command shows how to find to which scheduled job the job options belong. This command uses a pipeline operator (|) to send the selected job options to the ForEach-Object cmdlet which gets the **JobDefinition** property of each options object. The **JobDefinition** property contains the originating job object. The results show that the selected options came from the "DeployPkg" scheduled job. + ### Example 4: Use job options to create a new job ```powershell @@ -240,7 +240,7 @@ Accept wildcard characters: True ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSScheduledJob/New-JobTrigger.md b/reference/3.0/PSScheduledJob/New-JobTrigger.md index 5e7816eb19df..25517d7ab496 100644 --- a/reference/3.0/PSScheduledJob/New-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/New-JobTrigger.md @@ -133,20 +133,17 @@ When setting the delay value, review the effective and default values of the New ### Example 6: Create a Job Trigger for a New Scheduled Job -The first command uses the **New-JobTrigger** cmdlet to create a job trigger that starts a job every Monday, Wednesday, and Friday at 12:01 a.m. The command saves the job trigger in the $t variable. - ```powershell $t = New-JobTrigger -Weekly -DaysOfWeek 1,3,5 -At 12:01AM -``` - -The second command uses the Register-ScheduledJob cmdlet to create a scheduled job that starts a job every Monday, Wednesday, and Friday at 12:01 a.m. The value of the **Trigger** parameter is the trigger that is stored in the $t variable. - -```powershell Register-ScheduledJob -Name Test-HelpFiles -FilePath C:\Scripts\Test-HelpFiles.ps1 -Trigger $t ``` These commands use a job trigger to create a new scheduled job. +The first command uses the **New-JobTrigger** cmdlet to create a job trigger that starts a job every Monday, Wednesday, and Friday at 12:01 a.m. The command saves the job trigger in the $t variable. + +The second command uses the Register-ScheduledJob cmdlet to create a scheduled job that starts a job every Monday, Wednesday, and Friday at 12:01 a.m. The value of the **Trigger** parameter is the trigger that is stored in the $t variable. + ### Example 7: Add a Job Trigger to a Scheduled Job ```powershell @@ -185,7 +182,7 @@ To prevent the job from repeating, the command uses the Get-JobTrigger to get th New-JobTrigger -Once -At "9/21/2012 0am" -RepetitionInterval (New-TimeSpan -Hours 12) -RepetitionDuration ([TimeSpan]::MaxValue) ``` -The following command creates a job trigger that runs a scheduled job once every 12 hours for an indefinite period of time. +The previous command creates a job trigger that runs a scheduled job once every 12 hours for an indefinite period of time. The schedule begins tomorrow (9/21/2012) at midnight (0:00 AM). ## PARAMETERS @@ -444,7 +441,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS @@ -464,12 +461,16 @@ You cannot pipe input to this cmdlet. To submit a hash table, use the following keys. - @{Frequency="Once" (or Daily, Weekly, AtStartup, AtLogon);At="3am" (or any valid time string); -DaysOfWeek="Monday", "Wednesday" (or any combination of day names); -Interval=2 (or any valid frequency interval); -RandomDelay="30minutes" (or any valid timespan string); -User="Domain1\User01 (or any valid user; used only with the AtLogon frequency value) +```powershell +@{ + Frequency="Once" # (or Daily, Weekly, AtStartup, AtLogon) + At="3am" # (or any valid time string) + DaysOfWeek="Monday", "Wednesday" # (or any combination of day names) + Interval=2 # (or any valid frequency interval) + RandomDelay="30minutes" # (or any valid timespan string) + User="Domain1\User01" #(or any valid user. used only with the AtLogon frequency value) } +``` ## RELATED LINKS diff --git a/reference/3.0/PSScheduledJob/New-ScheduledJobOption.md b/reference/3.0/PSScheduledJob/New-ScheduledJobOption.md index 457c20df07d3..8d7d7bf552c7 100644 --- a/reference/3.0/PSScheduledJob/New-ScheduledJobOption.md +++ b/reference/3.0/PSScheduledJob/New-ScheduledJobOption.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -98,21 +98,9 @@ The output shows that the **RequireNetwork** parameter changed the value of the ### Example 3: Set options for a new scheduled job -The first command creates a **ScheduledJobOptions** object with the **RunElevated** parameter. It saves the object in the $RunAsAdmin variable. - ```powershell $RunAsAdmin = New-ScheduledJobOption -RunElevated -``` - -The second command uses the Register-ScheduledJob cmdlet to create a new scheduled job. The value of the **ScheduledJobOption** parameter is the option object in the value of the $RunAsAdmin variable. - -```powershell Register-ScheduledJob -Name Backup -FilePath D:\Scripts\Backup.ps1 -Trigger $Mondays -ScheduledJobOption $RunAsAdmin -``` - -The third command uses the Get-ScheduledJobOption cmdlet to get the job options of the Backup scheduled job.The cmdlet output shows that the **RunElevated** property is set to True and the **JobDefinition** property of the job option object is now populated with the scheduled job object for the Backup scheduled job. - -```powershell Get-ScheduledJobOption -Name Backup ``` @@ -134,6 +122,12 @@ JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinitio This example shows how to use the **ScheduledJobOptions** object that **New-ScheduledJobOption** returns to set the options for a new scheduled job. +The first command creates a **ScheduledJobOptions** object with the **RunElevated** parameter. It saves the object in the $RunAsAdmin variable. + +The second command uses the Register-ScheduledJob cmdlet to create a new scheduled job. The value of the **ScheduledJobOption** parameter is the option object in the value of the $RunAsAdmin variable. + +The third command uses the Get-ScheduledJobOption cmdlet to get the job options of the Backup scheduled job.The cmdlet output shows that the **RunElevated** property is set to True and the **JobDefinition** property of the job option object is now populated with the scheduled job object for the Backup scheduled job. + ### Example 4: Sort the properties of a scheduled job option object ```powershell @@ -450,7 +444,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS @@ -466,9 +460,16 @@ You cannot pipe input to this cmdlet. - You can use the **ScheduledJobOptions** object that **New-ScheduledJobOption** creates as the value of the **ScheduledJobOption** parameter of the Register-ScheduledJob cmdlet. However, the **ScheduledJobOption** parameter can also take a hash table value that specifies the properties of the ScheduledJobOptions object and their values, such as: - `@{ShowInTaskScheduler=$False; RunElevated=$True; IdleDuration="00:05"}` - For more information, see Register-ScheduledJob. +```powershell + @{ + ShowInTaskScheduler=$False + RunElevated=$True + IdleDuration="00:05" + } +``` + + For more information, see [Register-ScheduledJob](Register-ScheduledJob.md) ## RELATED LINKS @@ -504,4 +505,4 @@ You cannot pipe input to this cmdlet. [Set-ScheduledJobOption](Set-ScheduledJobOption.md) -[Unregister-ScheduledJob](Unregister-ScheduledJob.md) \ No newline at end of file +[Unregister-ScheduledJob](Unregister-ScheduledJob.md) diff --git a/reference/3.0/PSScheduledJob/PSScheduledJob.md b/reference/3.0/PSScheduledJob/PSScheduledJob.md index 74ecc77ab036..814d0b89ae71 100644 --- a/reference/3.0/PSScheduledJob/PSScheduledJob.md +++ b/reference/3.0/PSScheduledJob/PSScheduledJob.md @@ -21,77 +21,62 @@ This section contains the help topics for the cmdlets that are installed with Wi Adds job triggers to scheduled jobs - ### [Disable-JobTrigger](Disable-JobTrigger.md) Disables the job triggers of scheduled jobs - ### [Disable-ScheduledJob](Disable-ScheduledJob.md) Disables a scheduled job - ### [Enable-JobTrigger](Enable-JobTrigger.md) Enables the job triggers of scheduled jobs - ### [Enable-ScheduledJob](Enable-ScheduledJob.md) Enables a scheduled job - ### [Get-JobTrigger](Get-JobTrigger.md) Gets the job triggers of scheduled jobs. - ### [Get-ScheduledJobOption](Get-ScheduledJobOption.md) Gets the job options of scheduled jobs. - ### [Get-ScheduledJob](Get-ScheduledJob.md) Gets scheduled jobs on the local computer. - ### [New-JobTrigger](New-JobTrigger.md) Creates a job trigger for a scheduled job - ### [New-ScheduledJobOption](New-ScheduledJobOption.md) Creates an object that contains advanced options for a scheduled job. - ### [Register-ScheduledJob](Register-ScheduledJob.md) Creates a new scheduled job. - ### [Remove-JobTrigger](Remove-JobTrigger.md) Delete job triggers from scheduled jobs - ### [Set-JobTrigger](Set-JobTrigger.md) Changes the job trigger of a scheduled job. - ### [Set-ScheduledJobOption](Set-ScheduledJobOption.md) Changes the job options of a scheduled job. - ### [Set-ScheduledJob](Set-ScheduledJob.md) Changes scheduled jobs - ### [Unregister-ScheduledJob](Unregister-ScheduledJob.md) Deletes scheduled jobs on the local computer. \ No newline at end of file diff --git a/reference/3.0/PSScheduledJob/Register-ScheduledJob.md b/reference/3.0/PSScheduledJob/Register-ScheduledJob.md index d1a2ef121e83..d15c03fe4271 100644 --- a/reference/3.0/PSScheduledJob/Register-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Register-ScheduledJob.md @@ -79,26 +79,20 @@ You can use add job triggers later, use the Start-Job cmdlet to start the job on ### Example 2: Create a scheduled job with triggers and custom options -The first command uses the New-ScheduledJobOption cmdlet to create a job option object, which it saves in the $o parameter. The options start the scheduled job even if the computer is not idle, wake the computer to run the job, if necessary, and allows multiple instances of the job to run in a series. - ```powershell $o = New-ScheduledJobOption -WakeToRun -StartIfNotIdle -MultipleInstancesPolicy Queue -``` - -The second command uses the New-JobTrigger cmdlet to create job trigger that starts a job every other Monday at 9:00 p.m. - -```powershell $t = New-JobTrigger -Weekly -At "9:00 PM" -DaysOfWeek Monday -WeeksInterval 2 -``` - -This command creates the UpdateVersion scheduled job, which runs the UpdateVersion.ps1 script every Monday at 9:00 p.m. The command uses the **FilePath** parameter to specify the script that the job runs. It uses the **Trigger** parameter to specify the job triggers in the $t variable and the **ScheduledJobOption** parameter to specify the option object in the $o variable. - -```powershell Register-ScheduledJob -Name UpdateVersion -FilePath \\Srv01\Scripts\UpdateVersion.ps1 -Trigger $t -ScheduledJobOption $o ``` This example shows how to create a scheduled job that has a job trigger and custom job options. +The first command uses the New-ScheduledJobOption cmdlet to create a job option object, which it saves in the $o parameter. The options start the scheduled job even if the computer is not idle, wake the computer to run the job, if necessary, and allows multiple instances of the job to run in a series. + +The second command uses the New-JobTrigger cmdlet to create job trigger that starts a job every other Monday at 9:00 p.m. + +The third command creates the UpdateVersion scheduled job, which runs the UpdateVersion.ps1 script every Monday at 9:00 p.m. The command uses the **FilePath** parameter to specify the script that the job runs. It uses the **Trigger** parameter to specify the job triggers in the $t variable and the **ScheduledJobOption** parameter to specify the option object in the $o variable. + ### Example 3: Use hash tables to specify a trigger and job options ```powershell @@ -318,7 +312,28 @@ For a description of the scheduled job options, including the default values, se To submit a hash table, use the following keys. In the following hash table, the keys are shown with their default values. -@{StartIfOnBattery=$False; StopIfGoingOnBattery=$True; WakeToRun=$False; StartIfNotIdle=$False; IdleDuration="00:10:00"; IdleTimeout="01:00:00"; StopIfGoingOffIdle=$True; RestartOnIdleResume=$False; ShowInTaskScheduler=$True; RunElevated=$False; RunWithoutNetwork=$False; DoNotAllowDemandStart=$False; MultipleInstancePolicy=IgnoreNew} +```powershell +@{ + # Power Settings + StartIfOnBattery=$False + StopIfGoingOnBattery=$True + WakeToRun=$False + # Idle Settings + StartIfNotIdle=$False + IdleDuration="00:10:00" + IdleTimeout="01:00:00" + StopIfGoingOffIdle=$True + RestartOnIdleResume=$False + # Security settings + ShowInTaskScheduler=$True + RunElevated=$False + # Misc + RunWithoutNetwork=$False + DoNotAllowDemandStart=$False + # Can be IgnoreNew, Parallel, Queue, StopExisting + MultipleInstancePolicy=IgnoreNew +} +``` ```yaml Type: ScheduledJobOptions @@ -366,12 +381,16 @@ You can also create and maintain a scheduled job without a trigger that is used To submit a hash table, use the following keys. -@{Frequency="Once" (or Daily, Weekly, AtStartup, AtLogon);At="3am" (or any valid time string); -DaysOfWeek="Monday", "Wednesday" (or any combination of day names); -Interval=2 (or any valid frequency interval); -RandomDelay="30minutes" (or any valid timespan string); -User="Domain1\User01 (or any valid user; used only with the AtLogon frequency value) +```powershell +@{ + Frequency="Once" # (or Daily, Weekly, AtStartup, AtLogon) + At="3am" # (or any valid time string) + DaysOfWeek="Monday", "Wednesday" # (or any combination of day names) + Interval=2 # (or any valid frequency interval) + RandomDelay="30minutes" # (or any valid timespan string) + User="Domain1\User01" #(or any valid user. used only with the AtLogon frequency value) } +``` ```yaml Type: ScheduledJobTrigger[] @@ -420,7 +439,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSScheduledJob/Remove-JobTrigger.md b/reference/3.0/PSScheduledJob/Remove-JobTrigger.md index 83f44b60338a..739d64b90c3e 100644 --- a/reference/3.0/PSScheduledJob/Remove-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/Remove-JobTrigger.md @@ -187,7 +187,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSScheduledJob/Set-JobTrigger.md b/reference/3.0/PSScheduledJob/Set-JobTrigger.md index 0a051188e966..5d70317cefd1 100644 --- a/reference/3.0/PSScheduledJob/Set-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/Set-JobTrigger.md @@ -49,8 +49,6 @@ This cmdlet is introduced in Windows PowerShell 3.0. ### Example 1: Change the days in a job trigger -The first command uses the Get-JobTrigger cmdlet to get the job trigger of the DeployPackage scheduled job. The output shows that the trigger starts the job at midnight on Wednesdays and Saturdays.This command is not required; it is included only to show the effect of the trigger change. - ```powershell Get-JobTrigger -Name DeployPackage ``` @@ -61,8 +59,6 @@ Id Frequency Time DaysOfWeek Enable 1 Weekly 9/29/2011 12:00:00 AM {Wednesday, Saturday} True ``` -The second command uses the Get-JobTrigger cmdlet to get the job trigger of the DeployPackage scheduled job. A pipeline operator (|) sends the trigger to the **Set-JobTrigger** cmdlet which changes the job trigger so that it starts the DeployPackage job on Wednesdays and Sundays. The command uses the **Passthru** parameter to return the trigger after the change. - ```powershell Get-JobTrigger -Name DeployPackage | Set-JobTrigger -DaysOfWeek "Wednesday", "Sunday" -Passthru ``` @@ -73,11 +69,11 @@ Id Frequency Time DaysOfWeek Enable 1 Weekly 9/29/2011 12:00:00 AM {Wednesday, Sunday} True ``` -This example shows how to change the days in a weekly job trigger. +The first command uses the Get-JobTrigger cmdlet to get the job trigger of the DeployPackage scheduled job. The output shows that the trigger starts the job at midnight on Wednesdays and Saturdays.This command is not required; it is included only to show the effect of the trigger change. -### Example 2: Change the job trigger type +The second command uses the Get-JobTrigger cmdlet to get the job trigger of the DeployPackage scheduled job. A pipeline operator (|) sends the trigger to the **Set-JobTrigger** cmdlet which changes the job trigger so that it starts the DeployPackage job on Wednesdays and Sundays. The command uses the **Passthru** parameter to return the trigger after the change. -The first command uses the Get-JobTrigger cmdlet to get the job trigger of the Inventory scheduled job. The output shows that the job has two triggers a daily trigger and an AtStartup trigger.This command is not required; it is included only to show the effect of the trigger change. +### Example 2: Change the job trigger type ```powershell Get-JobTrigger -Name Inventory @@ -90,8 +86,6 @@ Id Frequency Time DaysOfWeek Enable 2 AtStartup True ``` -The second command uses the Get-JobTrigger cmdlet to get the AtStartup job trigger of the Inventory job. The command uses the TriggerID parameter to identify the job trigger. A pipeline operator (|) sends the job trigger to the **Set-JobTrigger** cmdlet which changes it to a weekly job trigger that runs every four weeks on Monday at midnight. The command uses the **Passthru** parameter to return the trigger after the change. - ```powershell Get-JobTrigger -Name Inventory -TriggerId 2 | Set-JobTrigger -Weekly -WeeksInterval 4 -DaysOfWeek Monday -At "12:00 AM" ``` @@ -103,8 +97,9 @@ Id Frequency Time DaysOfWeek Enable 2 Weekly 10/31/2011 12:00:00 AM {Monday} True ``` -This example shows how to change the type of job trigger that starts a job. -The commands in this example replace an AtStartup job trigger with a weekly trigger. +The first command uses the Get-JobTrigger cmdlet to get the job trigger of the Inventory scheduled job. The output shows that the job has two triggers a daily trigger and an AtStartup trigger.This command is not required; it is included only to show the effect of the trigger change. + +The second command uses the Get-JobTrigger cmdlet to get the AtStartup job trigger of the Inventory job. The command uses the TriggerID parameter to identify the job trigger. A pipeline operator (|) sends the job trigger to the **Set-JobTrigger** cmdlet which changes it to a weekly job trigger that runs every four weeks on Monday at midnight. The command uses the **Passthru** parameter to return the trigger after the change. ### Example 3: Change the user on a remote job trigger @@ -125,9 +120,8 @@ The selected job triggers are piped to the **Set-JobTrigger** cmdlet, which chan ### Example 4: Change one of many job triggers -The first command uses the **Get-JobTrigger** cmdlet to get all job triggers of the SecurityCheck scheduled job. The output, which displays the IDs of the job triggers, reveals that the **Once** job trigger has an ID of 3. - ```powershell +# Get all job triggers on the SecurityCheck scheduled job. Get-JobTrigger -Name SecurityCheck ``` @@ -139,9 +133,9 @@ Id Frequency Time DaysOfWeek Enable 3 Once 4/24/2013 4:00:00 PM True ``` -The second command uses the **TriggerID** parameter of the **Get-JobTrigger** cmdlet to get the **Once** trigger of the SecurityCheck scheduled job. The command pipes the trigger to the Format-List cmdlet, which displays all of the properties of the **Once** job trigger.The output shows that the trigger starts the job once every hour (RepetitionInterval = 1 hour) for one day (RepetitionDuration = 1 day). - ```powershell +# View all the properties of the job triggers. +# Note: (RepetitionInterval = 1 hour) for one day (RepetitionDuration = 1 day) Get-JobTrigger -Name SecurityCheck -TriggerId 3 | Format-List -Property * ``` @@ -159,15 +153,10 @@ Enabled : True JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition ``` -The third command changes the repetition interval of the job trigger from one hour to 90 minutes. The command does not return any output. - ```powershell +# Change the repetition interval of the job trigger from one hour to 90 minutes. The command does not return any output. Get-JobTrigger -Name SecurityCheck -TriggerId 3 | Set-JobTrigger -RepetitionInterval (New-TimeSpan -Minutes 90) -``` - -The fourth command displays the effect of the change.The output shows that the trigger starts the job once every 90 minutes (RepetitionInterval = 1 hour, 30 minutes) for one day (RepetitionDuration = 1 day). - -```powershell +# Display the effect of the above change. Get-JobTrigger -Name SecurityCheck -TriggerId 3 | Format-List -Property * ``` @@ -484,7 +473,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSScheduledJob/Set-ScheduledJob.md b/reference/3.0/PSScheduledJob/Set-ScheduledJob.md index dde062ee137c..59284659a14f 100644 --- a/reference/3.0/PSScheduledJob/Set-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Set-ScheduledJob.md @@ -65,8 +65,6 @@ This cmdlet is introduced in Windows PowerShell 3.0. ### Example 1: Change the script that a job runs -The first command uses the Get-ScheduledJob cmdlet to get the Inventory scheduled job. The output shows that the job runs the Get-Inventory.ps1 script.This command is not required; it is included only to show the effect of the script change. - ```powershell Get-ScheduledJob -Name Inventory ``` @@ -77,8 +75,6 @@ Id Name Triggers Command 1 Inventory {1} C:\Scripts\Get-Inventory.ps1 True ``` -The second command uses the Get-ScheduledJob cmdlet to get the Inventory scheduled job. A pipeline operator (|) sends the scheduled job to the **Set-ScheduledJob** cmdlet. The Set-ScheduledJob command uses the Script parameter to specify a new script, Get-FullInventory.ps1. The command uses the **Passthru** parameter to return the scheduled job after the change. - ```powershell Get-ScheduledJob -Name Inventory | Set-ScheduledJob -FilePath C:\Scripts\Get-FullInventory.ps1 -Passthru ``` @@ -91,6 +87,10 @@ Id Name Triggers Command This example shows how to change the script that is run in a scheduled job. +The first command uses the Get-ScheduledJob cmdlet to get the Inventory scheduled job. The output shows that the job runs the Get-Inventory.ps1 script.This command is not required; it is included only to show the effect of the script change. + +The second command uses the Get-ScheduledJob cmdlet to get the Inventory scheduled job. A pipeline operator (|) sends the scheduled job to the **Set-ScheduledJob** cmdlet. The Set-ScheduledJob command uses the Script parameter to specify a new script, Get-FullInventory.ps1. The command uses the **Passthru** parameter to return the scheduled job after the change. + ### Example 2: Delete the execution history of a scheduled job ```powershell @@ -361,7 +361,28 @@ For a description of the scheduled job options, including the default values, se To submit a hash table, use the following keys. In the following hash table, the keys are shown with their default values. -@{# Power SettingsStartIfOnBattery=$False;StopIfGoingOnBattery=$True; WakeToRun=$False; # Idle SettingsStartIfNotIdle=$False; IdleDuration="00:10:00"; IdleTimeout="01:00:00"; StopIfGoingOffIdle=$True; RestartOnIdleResume=$False;# Security settingsShowInTaskScheduler=$TrueRunElevated=$False;# MiscRunWithoutNetwork=$False;DoNotAllowDemandStart=$False;MultipleInstancePolicy=IgnoreNew# Can be IgnoreNew, Parallel, Queue, StopExisting} +```powershell +@{ + # Power Settings + StartIfOnBattery=$False + StopIfGoingOnBattery=$True + WakeToRun=$False + # Idle Settings + StartIfNotIdle=$False + IdleDuration="00:10:00" + IdleTimeout="01:00:00" + StopIfGoingOffIdle=$True + RestartOnIdleResume=$False + # Security settings + ShowInTaskScheduler=$True + RunElevated=$False + # Misc + RunWithoutNetwork=$False + DoNotAllowDemandStart=$False + # Can be IgnoreNew, Parallel, Queue, StopExisting + MultipleInstancePolicy=IgnoreNew +} +``` ```yaml Type: ScheduledJobOptions @@ -408,12 +429,16 @@ You can also create and maintain a scheduled job that has no job triggers. To submit a hash table, use the following keys. -@{Frequency="Once" (or Daily, Weekly, AtStartup, AtLogon);At="3am" (or any valid time string); -DaysOfWeek="Monday", "Wednesday" (or any combination of day names); -Interval=2 (or any valid frequency interval); -RandomDelay="30minutes" (or any valid timespan string); -User="Domain1\User01 (or any valid user; used only with the AtLogon frequency value) +```powershell +@{ + Frequency="Once" # (or Daily, Weekly, AtStartup, AtLogon) + At="3am" # (or any valid time string) + DaysOfWeek="Monday", "Wednesday" # (or any combination of day names) + Interval=2 # (or any valid frequency interval) + RandomDelay="30minutes" # (or any valid timespan string) + User="Domain1\User01" #(or any valid user. used only with the AtLogon frequency value) } +``` ```yaml Type: ScheduledJobTrigger[] @@ -429,7 +454,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSScheduledJob/Set-ScheduledJobOption.md b/reference/3.0/PSScheduledJob/Set-ScheduledJobOption.md index 8defb3b911ec..c1bca3ad803e 100644 --- a/reference/3.0/PSScheduledJob/Set-ScheduledJobOption.md +++ b/reference/3.0/PSScheduledJob/Set-ScheduledJobOption.md @@ -50,8 +50,6 @@ This cmdlet is introduced in Windows PowerShell 3.0. ### Example 1: Change job options -The first command uses the Get-ScheduledJobOption cmdlet to get the job options of the DeployPackage scheduled job. The output shows that the WakeToRun and RunElevated properties are set to False.This command is not required; it is included only to show the effect of the option change. - ```powershell Get-ScheduledJobOption -Name DeployPackage ``` @@ -73,8 +71,6 @@ MultipleInstancePolicy : IgnoreNew JobDefinition : ``` -The second command uses the **Set-ScheduledJobOpton** cmdlet to change the job options so the values of the **WakeToRun** and **RunWithoutNetwork** properties are True. The command uses the **Passthru** parameter to return the trigger after the change. - ```powershell Get-ScheduledJobOption -Name DeployPackage | Set-ScheduledJobOption -WakeToRun -RequireNetwork:$False -Passthru ``` @@ -428,7 +424,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSScheduledJob/Unregister-ScheduledJob.md b/reference/3.0/PSScheduledJob/Unregister-ScheduledJob.md index cfd951abd995..2ff229eaff09 100644 --- a/reference/3.0/PSScheduledJob/Unregister-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Unregister-ScheduledJob.md @@ -67,8 +67,6 @@ This command deletes the TestJob scheduled job on the local computer. ```powershell Get-ScheduledJob | Unregister-ScheduledJob -Force - - Unregister-ScheduledJob -Name * -Force ``` @@ -197,7 +195,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/reference/3.0/PSWorkflow/About/about_ActivityCommonParameters.md b/reference/3.0/PSWorkflow/About/about_ActivityCommonParameters.md index ad51875d36e2..86a8b641e9a7 100644 --- a/reference/3.0/PSWorkflow/About/about_ActivityCommonParameters.md +++ b/reference/3.0/PSWorkflow/About/about_ActivityCommonParameters.md @@ -9,8 +9,6 @@ title: about_ActivityCommonParameters ## about_ActivityCommonParameters - - # SHORT DESCRIPTION Describes the parameters that Windows PowerShell @@ -644,11 +642,11 @@ if ($Log) ... # KEYWORDS -about_Activity_Common_Parameters -about_Activity_Parameters -about_ActivityParameters +[about_Activity_Common_Parameters](about_Activity_Common_Parameters.md) + + # SEE ALSO -about_Workflows -about_WorkflowCommonParameters \ No newline at end of file +[about_Workflows](about_workflows.md) +[about_WorkflowCommonParameters](about_WorkflowCommonParameters.md) \ No newline at end of file diff --git a/reference/3.0/PSWorkflow/New-PSWorkflowExecutionOption.md b/reference/3.0/PSWorkflow/New-PSWorkflowExecutionOption.md index 187ad2985662..6804850262a8 100644 --- a/reference/3.0/PSWorkflow/New-PSWorkflowExecutionOption.md +++ b/reference/3.0/PSWorkflow/New-PSWorkflowExecutionOption.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -74,15 +74,10 @@ The output shows the object that the cmdlet returns. ### Example 2: Using a Workflow Options Object -The first command uses the **New-PSWorkflowExecutionOption** cmdlet to create a workflow options object. The command saves the object in the $wo variable. - ```powershell +# Create a Workflow Options object and save it in a variable $wo = New-PSWorkflowExecutionOption -MaxSessionsPerWorkflow 10 -MaxDisconnectedSessions 200 -``` - -The second command uses the Register-PSSessionConfiguration cmdlet to create the ITWorkflows session configuration. To set the workflow options in the session configuration, the command uses the **SessionTypeOption** parameter. The value of the **SessionTypeOption** parameter is the workflow options object in the $wo variable. The command also uses the **Force** parameter to suppress confirmations prompts. - -```powershell +# Create the ITWorkflow session configuration Register-PSSessionConfiguration -Name ITWorkflows -SessionTypeOption $wo -Force ``` @@ -94,8 +89,6 @@ Type Keys Name Container {Name=ITWorkflows} ITWorkflows ``` -The third command shows the workflow options in the session configuration. The command uses the Get-PSSessionConfiguration cmdlet to the get the ITWorkflows session configuration and the Format-List to display all properties of the session configuration in a list.The output shows that the workflow options in the session configuration. Specifically, the session configuration has a **MaxSessionsPerWorkflow** property with a value of 10 and a **MaxDisconnectedSessions** property with a value of 200. - ```powershell Get-PSSessionConfiguration ITWorkflows | Format-List -Property * ``` @@ -147,7 +140,9 @@ MaxShellsPerUser : 25 Permission : ``` -This example shows how to use a workflow options object to establish or change the workflow options in a session configuration. +The first two commands create a new session configuration object and registers it. + +The third command uses the Get-PSSessionConfiguration cmdlet to the get the ITWorkflows session configuration and the Format-List to display all properties of the session configuration in a list.The output shows that the workflow options in the session configuration. Specifically, the session configuration has a **MaxSessionsPerWorkflow** property with a value of 10 and a **MaxDisconnectedSessions** property with a value of 200. ## PARAMETERS @@ -447,7 +442,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS @@ -478,4 +473,4 @@ Otherwise, it does not. [PSWorkflow Module](PSWorkflow.md) -[PSWorkflowUtility Module](../PSWorkflowUtility/PSWorkflowUtility.md) \ No newline at end of file +[PSWorkflowUtility Module](../PSWorkflowUtility/PSWorkflowUtility.md) diff --git a/reference/3.0/PSWorkflow/New-PSWorkflowSession.md b/reference/3.0/PSWorkflow/New-PSWorkflowSession.md index 4968ef3a95c5..6f9cf550cdf5 100644 --- a/reference/3.0/PSWorkflow/New-PSWorkflowSession.md +++ b/reference/3.0/PSWorkflow/New-PSWorkflowSession.md @@ -1,4 +1,4 @@ ---- +--- ms.date: 06/09/2017 schema: 2.0.0 locale: en-us @@ -36,7 +36,7 @@ This cmdlet is introduced in Windows PowerShell 3.0. ## EXAMPLES -### Example 1 +### Example 1: Create a new workflow session ```powershell New-PSWorkflowSession -ComputerName ServerNode01 -Name WorkflowTests -SessionOption (New-PSSessionOption -OutputBufferingMode Drop) @@ -45,7 +45,7 @@ New-PSWorkflowSession -ComputerName ServerNode01 -Name WorkflowTests -SessionOpt This command creates the WorkflowTests session on the ServerNode01 remote computer. The value of the **SessionOption** parameter is a **New-PSSessionOption** command that sets the output buffering mode in the session to Drop. -### Example 2 +### Example 2: Create workflow sessions on remote computers ```powershell "ServerNode01", "Server12" | New-PSWorkflowSession -Name WorkflowSession -Credential Domain01\Admin01 -ThrottleLimit 150 @@ -334,7 +334,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS @@ -368,4 +368,4 @@ You can pipe a session or a computer name to **New-PSWorkflowSession**. [PSWorkflow Module](PSWorkflow.md) -[PSWorkflowUtility Module](../PSWorkflowUtility/PSWorkflowUtility.md) \ No newline at end of file +[PSWorkflowUtility Module](../PSWorkflowUtility/PSWorkflowUtility.md) diff --git a/reference/3.0/PSWorkflow/PSWorkflow.md b/reference/3.0/PSWorkflow/PSWorkflow.md index 38149c13a673..d46d9a3889da 100644 --- a/reference/3.0/PSWorkflow/PSWorkflow.md +++ b/reference/3.0/PSWorkflow/PSWorkflow.md @@ -21,7 +21,6 @@ This section contains the help topics for the cmdlets that are installed with Wi Creates an object that contains session configuration options for workflow sessions. - ### [New-PSWorkflowSession](New-PSWorkflowSession.md) Creates a workflow session. \ No newline at end of file From a1e413851d1fbf8a21a12e237fccb64835b17680 Mon Sep 17 00:00:00 2001 From: Bobby Reed Date: Wed, 30 May 2018 08:09:12 -0400 Subject: [PATCH 3/8] Running batch automation to fix build errors --- reference/3.0/PSScheduledJob/New-JobTrigger.md | 5 ++--- reference/3.0/PSScheduledJob/Register-ScheduledJob.md | 4 ++++ reference/3.0/PSScheduledJob/Set-ScheduledJob.md | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/reference/3.0/PSScheduledJob/New-JobTrigger.md b/reference/3.0/PSScheduledJob/New-JobTrigger.md index 25517d7ab496..45675bab9acc 100644 --- a/reference/3.0/PSScheduledJob/New-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/New-JobTrigger.md @@ -458,10 +458,9 @@ You cannot pipe input to this cmdlet. - Job triggers are not saved to disk. However, scheduled jobs are saved to disk, and you can use the Get-JobTrigger to get the job trigger of any scheduled job. - **New-JobTrigger** does not prevent you from creating a job trigger that will not run a scheduled job, such as one-time trigger for a date in the past. - The Register-ScheduledJob cmdlet accepts a ScheduledJobTrigger object, such as one returned by the **New-JobTrigger** or Get-JobTrigger cmdlets, or a hash table with trigger values. - To submit a hash table, use the following keys. -```powershell + ## RELATED LINKS diff --git a/reference/3.0/PSScheduledJob/Register-ScheduledJob.md b/reference/3.0/PSScheduledJob/Register-ScheduledJob.md index d15c03fe4271..ddcb18838172 100644 --- a/reference/3.0/PSScheduledJob/Register-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Register-ScheduledJob.md @@ -312,6 +312,7 @@ For a description of the scheduled job options, including the default values, se To submit a hash table, use the following keys. In the following hash table, the keys are shown with their default values. + ```yaml Type: ScheduledJobOptions @@ -381,6 +383,7 @@ You can also create and maintain a scheduled job without a trigger that is used To submit a hash table, use the following keys. + ```yaml Type: ScheduledJobTrigger[] diff --git a/reference/3.0/PSScheduledJob/Set-ScheduledJob.md b/reference/3.0/PSScheduledJob/Set-ScheduledJob.md index 59284659a14f..c53b3e3f7cb5 100644 --- a/reference/3.0/PSScheduledJob/Set-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Set-ScheduledJob.md @@ -361,6 +361,7 @@ For a description of the scheduled job options, including the default values, se To submit a hash table, use the following keys. In the following hash table, the keys are shown with their default values. + ```yaml Type: ScheduledJobOptions @@ -429,6 +431,7 @@ You can also create and maintain a scheduled job that has no job triggers. To submit a hash table, use the following keys. + ```yaml Type: ScheduledJobTrigger[] From 7d15a7b5030cb038dc5a994766280bf3a9f5cac8 Mon Sep 17 00:00:00 2001 From: Bobby Reed Date: Wed, 30 May 2018 09:24:20 -0400 Subject: [PATCH 4/8] Running batch automation to fix build errors --- reference/3.0/PSScheduledJob/New-JobTrigger.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/reference/3.0/PSScheduledJob/New-JobTrigger.md b/reference/3.0/PSScheduledJob/New-JobTrigger.md index 45675bab9acc..56c85b265252 100644 --- a/reference/3.0/PSScheduledJob/New-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/New-JobTrigger.md @@ -460,17 +460,6 @@ You cannot pipe input to this cmdlet. - The Register-ScheduledJob cmdlet accepts a ScheduledJobTrigger object, such as one returned by the **New-JobTrigger** or Get-JobTrigger cmdlets, or a hash table with trigger values. To submit a hash table, use the following keys. - - ## RELATED LINKS [about_Scheduled_Jobs](About/about_Scheduled_Jobs.md) From da81583b89171dcb1367034ff47030b684f30efe Mon Sep 17 00:00:00 2001 From: Bobby Reed Date: Wed, 30 May 2018 09:33:01 -0400 Subject: [PATCH 5/8] Removing commented out code fences to fix Build errors. --- .../3.0/PSScheduledJob/New-JobTrigger.md | 1 - .../PSScheduledJob/Register-ScheduledJob.md | 40 ------------------- .../3.0/PSScheduledJob/Set-ScheduledJob.md | 38 ------------------ 3 files changed, 79 deletions(-) diff --git a/reference/3.0/PSScheduledJob/New-JobTrigger.md b/reference/3.0/PSScheduledJob/New-JobTrigger.md index 56c85b265252..0b6798bcecd3 100644 --- a/reference/3.0/PSScheduledJob/New-JobTrigger.md +++ b/reference/3.0/PSScheduledJob/New-JobTrigger.md @@ -458,7 +458,6 @@ You cannot pipe input to this cmdlet. - Job triggers are not saved to disk. However, scheduled jobs are saved to disk, and you can use the Get-JobTrigger to get the job trigger of any scheduled job. - **New-JobTrigger** does not prevent you from creating a job trigger that will not run a scheduled job, such as one-time trigger for a date in the past. - The Register-ScheduledJob cmdlet accepts a ScheduledJobTrigger object, such as one returned by the **New-JobTrigger** or Get-JobTrigger cmdlets, or a hash table with trigger values. - To submit a hash table, use the following keys. ## RELATED LINKS diff --git a/reference/3.0/PSScheduledJob/Register-ScheduledJob.md b/reference/3.0/PSScheduledJob/Register-ScheduledJob.md index ddcb18838172..595dbb5f8696 100644 --- a/reference/3.0/PSScheduledJob/Register-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Register-ScheduledJob.md @@ -312,31 +312,6 @@ For a description of the scheduled job options, including the default values, se To submit a hash table, use the following keys. In the following hash table, the keys are shown with their default values. - - ```yaml Type: ScheduledJobOptions Parameter Sets: (All) @@ -381,21 +356,6 @@ The **Trigger** parameter is optional. You can add a trigger when you create the scheduled job, use the Add-JobTrigger, Set-JobTrigger, or Set-ScheduledJob cmdlets to add or change job triggers later, or use the Start-Job cmdlet to start the scheduled job immediately. You can also create and maintain a scheduled job without a trigger that is used as a template. -To submit a hash table, use the following keys. - - - ```yaml Type: ScheduledJobTrigger[] Parameter Sets: (All) diff --git a/reference/3.0/PSScheduledJob/Set-ScheduledJob.md b/reference/3.0/PSScheduledJob/Set-ScheduledJob.md index c53b3e3f7cb5..775ca32ef871 100644 --- a/reference/3.0/PSScheduledJob/Set-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Set-ScheduledJob.md @@ -361,31 +361,6 @@ For a description of the scheduled job options, including the default values, se To submit a hash table, use the following keys. In the following hash table, the keys are shown with their default values. - - ```yaml Type: ScheduledJobOptions Parameter Sets: ScriptBlock, FilePath @@ -431,19 +406,6 @@ You can also create and maintain a scheduled job that has no job triggers. To submit a hash table, use the following keys. - - ```yaml Type: ScheduledJobTrigger[] Parameter Sets: ScriptBlock, FilePath From fa054aab6b73956a82696572b1862de776438571 Mon Sep 17 00:00:00 2001 From: Bobby Reed Date: Wed, 30 May 2018 09:37:54 -0400 Subject: [PATCH 6/8] Removing commented out code fences to fix Build errors. --- reference/3.0/PSScheduledJob/New-ScheduledJobOption.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/reference/3.0/PSScheduledJob/New-ScheduledJobOption.md b/reference/3.0/PSScheduledJob/New-ScheduledJobOption.md index 8d7d7bf552c7..f73e5e5e13d6 100644 --- a/reference/3.0/PSScheduledJob/New-ScheduledJobOption.md +++ b/reference/3.0/PSScheduledJob/New-ScheduledJobOption.md @@ -460,15 +460,6 @@ You cannot pipe input to this cmdlet. - You can use the **ScheduledJobOptions** object that **New-ScheduledJobOption** creates as the value of the **ScheduledJobOption** parameter of the Register-ScheduledJob cmdlet. However, the **ScheduledJobOption** parameter can also take a hash table value that specifies the properties of the ScheduledJobOptions object and their values, such as: - -```powershell - @{ - ShowInTaskScheduler=$False - RunElevated=$True - IdleDuration="00:05" - } -``` - For more information, see [Register-ScheduledJob](Register-ScheduledJob.md) ## RELATED LINKS From c7681bf9c606b412063204d534b474cfb1c5a4f9 Mon Sep 17 00:00:00 2001 From: Bobby Reed Date: Wed, 30 May 2018 10:54:01 -0400 Subject: [PATCH 7/8] Removing commented out code fences to fix Build errors. --- .../PSScheduledJob/Register-ScheduledJob.md | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/reference/3.0/PSScheduledJob/Register-ScheduledJob.md b/reference/3.0/PSScheduledJob/Register-ScheduledJob.md index 595dbb5f8696..bfefc9c6c97e 100644 --- a/reference/3.0/PSScheduledJob/Register-ScheduledJob.md +++ b/reference/3.0/PSScheduledJob/Register-ScheduledJob.md @@ -100,6 +100,42 @@ Register-ScheduledJob -FilePath \\Srv01\Scripts\Update-Version.ps1 -Trigger @{Fr MultipleInstancesPolicy="Queue"} ``` +```powershell +# Here are the default hashtables for -Trigger and -ScheduledJobOption + +# -Trigger +@{ + Frequency="Once" # (or Daily, Weekly, AtStartup, AtLogon) + At="3am" # (or any valid time string) + DaysOfWeek="Monday", "Wednesday" # (or any combination of day names) + Interval=2 # (or any valid frequency interval) + RandomDelay="30minutes" # (or any valid timespan string) + User="Domain1\User01" #(or any valid user. used only with the AtLogon frequency value) +} + +# -ScheduledJobOption +@{ + # Power Settings + StartIfOnBattery=$False + StopIfGoingOnBattery=$True + WakeToRun=$False + # Idle Settings + StartIfNotIdle=$False + IdleDuration="00:10:00" + IdleTimeout="01:00:00" + StopIfGoingOffIdle=$True + RestartOnIdleResume=$False + # Security settings + ShowInTaskScheduler=$True + RunElevated=$False + # Misc + RunWithoutNetwork=$False + DoNotAllowDemandStart=$False + # Can be IgnoreNew, Parallel, Queue, StopExisting + MultipleInstancePolicy=IgnoreNew +} +``` + This command is has the same effect as the command in Example 2. It creates a scheduled job, but it uses hash tables to specify the values of the **Trigger** and **ScheduledJobOption** parameters. From b187c1d3c2d86961cc7a2e78e50956a969808b71 Mon Sep 17 00:00:00 2001 From: Bobby Reed Date: Thu, 31 May 2018 06:06:14 -0400 Subject: [PATCH 8/8] Cleaning up new about files from PSWorkflow and ScheduledJobs --- .../About/about_Scheduled_Jobs.md | 324 +++--- .../About/about_Scheduled_Jobs_Advanced.md | 211 ++-- .../About/about_Scheduled_Jobs_Basics.md | 253 +++-- .../about_Scheduled_Jobs_Troubleshooting.md | 419 ++++---- .../About/about_ActivityCommonParameters.md | 999 +++++++++--------- 5 files changed, 1079 insertions(+), 1127 deletions(-) diff --git a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs.md b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs.md index b1b891ea469e..ca4ecc09958d 100644 --- a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs.md +++ b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs.md @@ -9,81 +9,77 @@ title: about_Scheduled_Jobs ## SHORT DESCRIPTION -Describes scheduled jobs and explains how to use and manage -scheduled jobs in Windows PowerShell and in Task Scheduler. +Describes scheduled jobs and explains how to use and manage scheduled jobs in +Windows PowerShell and in Task Scheduler. ## LONG DESCRIPTION -Windows PowerShell scheduled jobs are a useful hybrid of -Windows PowerShell background jobs and Task Scheduler tasks. - -Like Windows PowerShell background jobs, scheduled jobs -run asynchronously in the background. Instances of scheduled -jobs that have run can be managed by using the job cmdlets, -such as Start-Job, Get-Job, Stop-Job, and Receive-Job. - -Like Task Scheduler tasks, scheduled jobs are saved to disk. -You can view and manage the jobs in Task Scheduler, enable -and disable them as needed, run them or use them as templates, -establish a one-time or recurring schedules for starting the -jobs, or set conditions under which the jobs start. - -In addition, the results of scheduled job instances are saved -to disk in an easily accessible format, providing a running -log of job output. Scheduled jobs come with a customized set -of cmdlets for managing them. The cmdlets let you create, edit, -manage, disable, and re-enable scheduled jobs, job triggers -and job options. - -This comprehensive and flexible set of tools make scheduled -jobs an essential component of many professional Windows -PowerShell IT solutions. - -The scheduled job cmdlets are included in the PSScheduledJob -module that is installed with Windows PowerShell. This module -was introduced in Windows PowerShell 3.0 and works in Windows -PowerShell 3.0 and later versions of Windows PowerShell. - -For more information about Windows PowerShell background jobs, -see [about_Jobs](../../Microsoft.PowerShell.Core/About/about_Jobs.md). - -For more information about Task Scheduler, see "Task Scheduler" -in the TechNet Library at -[Task Scheduler](/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc721871(v=ws.11)). - -NOTE: You can view and manage Windows PowerShell scheduled jobs -in Task Scheduler, but the Windows PowerShell job and Scheduled -Job cmdlets work only on scheduled jobs that are created in +Windows PowerShell scheduled jobs are a useful hybrid of Windows PowerShell +background jobs and Task Scheduler tasks. + +Like Windows PowerShell background jobs, scheduled jobs run asynchronously in +the background. Instances of scheduled jobs that have run can be managed by +using the job cmdlets, such as `Start-Job`, `Get-Job`, `Stop-Job`, and +`Receive-Job`. + +Like Task Scheduler tasks, scheduled jobs are saved to disk. You can view and +manage the jobs in Task Scheduler, enable and disable them as needed, run them +or use them as templates, establish a one-time or recurring schedules for +starting the jobs, or set conditions under which the jobs start. + +In addition, the results of scheduled job instances are saved to disk in an +easily accessible format, providing a running log of job output. Scheduled jobs +come with a customized set of cmdlets for managing them. The cmdlets let you +create, edit, manage, disable, and re-enable scheduled jobs, job triggers and +job options. + +This comprehensive and flexible set of tools make scheduled jobs an essential +component of many professional Windows PowerShell IT solutions. + +The scheduled job cmdlets are included in the PSScheduledJob module that is +installed with Windows PowerShell. This module was introduced in Windows +PowerShell 3.0 and works in Windows PowerShell 3.0 and later versions of Windows PowerShell. +For more information about Windows PowerShell background jobs, see [about_Jobs](../../Microsoft.PowerShell.Core/About/about_Jobs.md). + +For more information about Task Scheduler, see "Task Scheduler" in the TechNet +Library at [TaskScheduler](/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc721871(v=ws.11)). + +> [!NOTE] +> You can view and manage Windows PowerShell scheduled jobs +> in Task Scheduler, but the Windows PowerShell job and Scheduled +> Job cmdlets work only on scheduled jobs that are created in +> Windows PowerShell. + ### SCHEDULED JOB CMDLETS The PSScheduledJob module contains the following cmdlets. -Register-ScheduledJob: Creates a scheduled job. -Get-ScheduledJob: Gets a scheduled job. -Set-ScheduledJob: Changes the properties of a scheduled job -Disable-ScheduledJob: Temporarily disables a scheduled job. -Enable-ScheduledJob: Re-enables a scheduled job. -Unregister-ScheduledJob Deletes a scheduled job and its saved results. - -New-JobTrigger: Creates a job trigger. -Get-JobTrigger: Gets a job trigger. -Add-JobTrigger: Adds a job trigger to a scheduled job. -Set-JobTrigger: Changes a job trigger. -Disable-JobTrigger: Temporarily disables a job trigger. -Enable-JobTrigger: Re-enables a job trigger. -Remove-JobTrigger: Deletes a job trigger. - -New-ScheduledJobOption: Creates a job options object. -Get-ScheduledJobOption: Gets the job options of a scheduled job. -Set-ScheduledJobOption: Changes the job options of a scheduled job. +|Cmdlet |Description | +|----------------------------|-----------------------------------------------| +|`Register-ScheduledJob` | Creates a scheduled job | +|`Get-ScheduledJob` | Gets a scheduled job | +|`Set-ScheduledJob` | Changes the properties of a scheduled job | +|`Disable-ScheduledJob` | Temporarily disables a scheduled job | +|`Enable-ScheduledJob` | Re-enables a scheduled job | +|`Unregister-ScheduledJob` | Deletes a scheduled job and its saved results| +|`New-JobTrigger` | Creates a job trigger | +|`Get-JobTrigger` | Gets a job trigger | +|`Add-JobTrigger` | Adds a job trigger to a scheduled job | +|`Set-JobTrigger` | Changes a job trigger | +|`Disable-JobTrigger` | Temporarily disables a job trigger | +|`Enable-JobTrigger` | Re-enables a job trigger | +|`Remove-JobTrigger` | Deletes a job trigger | +|`New-ScheduledJobOption` | Creates a job options object | +|`Get-ScheduledJobOption` | Gets the job options of a scheduled job | +|`Set-ScheduledJobOption` | Changes the job options of a scheduled job | ### QUICK START -The following commands create a scheduled job that starts -every day at 3:00 AM and runs the Get-Process cmdlet. The job -starts even if the computer is running on batteries. +The following commands create a scheduled job that starts every day at 3:00 AM +and runs the `Get-Process` cmdlet. The job starts even if the computer is running +on batteries. ```powershell $trigger = New-JobTrigger -Daily -At 3AM @@ -104,9 +100,9 @@ Id Name Triggers Command Enabled 7 ProcessJob {1} Get-Process True ``` -The following command gets the job triggers of ProcessJob. The -input parameters specify the scheduled job, not the trigger, -because triggers are saved in a scheduled job. +The following command gets the job triggers of ProcessJob. The input parameters +specify the scheduled job, not the trigger, because triggers are saved in a +scheduled job. ```powershell Get-JobTrigger -Name ProcessJob @@ -118,9 +114,9 @@ Id Frequency Time DaysOfWeek Enable 1 Daily 11/5/2011 3:00:00 AM True ``` -The following command uses the ContinueIfGoingOnBattery parameter of -the Set-ScheduledJob cmdlet to change the StopIfGoingOnBatteries property -of ProcessJob to False. +The following command uses the ContinueIfGoingOnBattery parameter of the +`Set-ScheduledJob` cmdlet to change the StopIfGoingOnBatteries property of +ProcessJob to False. ```powershell Get-ScheduledJob -Name ProcessJob | Set-ScheduledJobOption ` @@ -141,7 +137,7 @@ RunElevated : False RunWithoutNetwork : True DoNotAllowDemandStart : False MultipleInstancePolicy : IgnoreNew -JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition +JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition ``` The following command gets the ProcessJob scheduled job. @@ -156,61 +152,61 @@ Id Name Triggers Command Enabled 7 ProcessJob {1} Get-Process True ``` -The following command uses the Get-Job cmdlet to get all instances -of the ProcessJob scheduled job that have run thus far. The Get-Job -cmdlet gets scheduled jobs only when the PSScheduledJob module is -imported into the current session. +The following command uses the `Get-Job` cmdlet to get all instances of the +ProcessJob scheduled job that have run thus far. The `Get-Job` cmdlet gets +scheduled jobs only when the PSScheduledJob module is imported into the current +session. -TIP: Notice that you use the ScheduledJob cmdlets to manage scheduled -jobs, but you use the Job cmdlets to manage instances of scheduled jobs. +> [!TIP] +> Notice that you use the ScheduledJob cmdlets to manage scheduled jobs, but +> you use the Job cmdlets to manage instances of scheduled jobs. ```powershell Get-Job -Name ProcessJob ``` ```output -Id Name PSJobTypeName State HasMoreData Location Command --- ---- ------------ ----- ----------- -------- ------- -45 ProcessJob PSScheduledJob Completed True localhost Get-Process -46 ProcessJob PSScheduledJob Completed True localhost Get-Process -47 ProcessJob PSScheduledJob Completed True localhost Get-Process -48 ProcessJob PSScheduledJob Completed True localhost Get-Process -49 ProcessJob PSScheduledJob Completed True localhost Get-Process -50 ProcessJob PSScheduledJob Completed True localhost Get-Process -51 ProcessJob PSScheduledJob Completed True localhost Get-Process +Id Name PSJobTypeName State HasMoreData Location Command +-- ---- ------------ ----- ----------- -------- ------- +45 ProcessJob PSScheduledJob Completed True localhost Get-Process +46 ProcessJob PSScheduledJob Completed True localhost Get-Process +47 ProcessJob PSScheduledJob Completed True localhost Get-Process +48 ProcessJob PSScheduledJob Completed True localhost Get-Process +49 ProcessJob PSScheduledJob Completed True localhost Get-Process +50 ProcessJob PSScheduledJob Completed True localhost Get-Process +51 ProcessJob PSScheduledJob Completed True localhost Get-Process ``` -The following command gets the results of the most recent instance -of the ProcessJob scheduled job (ID = 51). +The following command gets the results of the most recent instance of the +ProcessJob scheduled job (ID = 51). ```powershell Receive-Job -Id 51 ``` -Even though the Receive-Job command did not include the Keep parameter, -the results of the job are saved on disk until you delete them or the -maximum number of results are exceeded. +Even though the `Receive-Job` command did not include the Keep parameter, the +results of the job are saved on disk until you delete them or the maximum +number of results are exceeded. -The job results are no longer available in this session, but if you -start a new session or open a new Windows Powershell window, the -results of the job are available again. +The job results are no longer available in this session, but if you start a new +session or open a new Windows Powershell window, the results of the job are +available again. -The following command uses the DefinitionName parameter of the -Start-Job cmdlet to start the ProcessJob scheduled job. +The following command uses the DefinitionName parameter of the `Start-Job` +cmdlet to start the ProcessJob scheduled job. -Jobs that are started by using the Start-Job cmdlet are standard -Windows PowerShell background jobs, not instances of the scheduled -job. Like all background jobs, these jobs start immediately -- they -are not subject to job options or affected by job triggers -- and -their output is not saved in the Output directory of the scheduled -job directory. +Jobs that are started by using the `Start-Job` cmdlet are standard Windows +PowerShell background jobs, not instances of the scheduled job. Like all +background jobs, these jobs start immediately, they are not subject to job +options or affected by job triggers, and their output is not saved in the +Output directory of the scheduled job directory. ```powershell Start-Job -DefinitionName ProcessJob ``` -The following command deletes the ProcessJob scheduled job and all -saved results of its job instances. +The following command deletes the ProcessJob scheduled job and all saved +results of its job instances. ```powershell Unregister-ScheduledJob ProcessJob @@ -218,79 +214,97 @@ Unregister-ScheduledJob ProcessJob ### SCHEDULED JOBS CONCEPTS -A "scheduled job" runs commands or a script. A scheduled job can -include "job triggers" that start the job and "job options" that -set conditions for running the job. +A "scheduled job" runs commands or a script. A scheduled job can include "job +triggers" that start the job and "job options" that set conditions for running +the job. -A "job trigger" starts a scheduled job automatically. A job trigger -can include a one-time or recurring schedule or specify an event, -such as when a user logs on or Windows starts. A scheduled job can -have one or more job triggers, and you can create, add, enable, -disable, and get job triggers. +A "job trigger" starts a scheduled job automatically. A job trigger can include +a one-time or recurring schedule or specify an event, such as when a user logs +on or Windows starts. A scheduled job can have one or more job triggers, and +you can create, add, enable, disable, and get job triggers. -Job triggers are optional. You can start also scheduled jobs -immediately by using the Start-Job cmdlet, or by adding the RunNow -parameter to your Register-ScheduledJob command. +Job triggers are optional. You can start also scheduled jobs immediately by +using the `Start-Job cmdlet`, or by adding the RunNow parameter to your +`Register-ScheduledJob` command. -"Job options" set the conditions for running a scheduled job. -Every scheduled job has one job options object. You can create -and edit job options objects and add them to one or more scheduled -jobs. +"Job options" set the conditions for running a scheduled job. Every scheduled +job has one job options object. You can create and edit job options objects and +add them to one or more scheduled jobs. -Each time a scheduled job starts, a "job instance" is created. -Use the Windows PowerShell Job cmdlets to view and manage the job -instance. +Each time a scheduled job starts, a "job instance" is created. Use the Windows +PowerShell Job cmdlets to view and manage the job instance. -Scheduled jobs are saved to disk (hence the cmdlet verb, Register, -instead of New) in XML files in the -$home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs -directory on the local computer. +Scheduled jobs are saved to disk (hence the cmdlet verb, Register, instead of +New) in XML files in the +\$home\\AppData\\Local\\Microsoft\\Windows\\PowerShell\\ScheduledJobs directory +on the local computer. -Windows PowerShell creates a directory for each scheduled job and -saves the job commands, job triggers, job options and job results -in the scheduled job directory. Job triggers and job options are not -saved to disk independently. They are saved in the scheduled job -XML of each scheduled job with which they are associated. +Windows PowerShell creates a directory for each scheduled job and saves the job +commands, job triggers, job options and job results in the scheduled job +directory. Job triggers and job options are not saved to disk independently. +They are saved in the scheduled job XML of each scheduled job with which they +are associated. -Scheduled jobs, job triggers, and job options appear in Windows -PowerShell as objects. The objects are interlinked, which makes -them easy to discover and use in commands and scripts. +Scheduled jobs, job triggers, and job options appear in Windows PowerShell as +objects. The objects are interlinked, which makes them easy to discover and use +in commands and scripts. Scheduled jobs appear as ScheduledJobDefinition objects. The -ScheduledJobDefinition object has a JobTriggers property that -contains the job triggers of the scheduled job and an Options -property that contains the job options. The ScheduledJobTriggers -and ScheduledJobOptions objects that represent job -triggers and job options, respectively, each have a JobDefinition -property that contains the scheduled job with which they are -associated. This recursive interconnection makes it easy to find -the triggers and options of a scheduled job and to find, script, -and display the scheduled job to which any job trigger or job option -is associated. +ScheduledJobDefinition object has a JobTriggers property that contains the job +triggers of the scheduled job and an Options property that contains the job +options. The ScheduledJobTriggers and ScheduledJobOptions objects that +represent job triggers and job options, respectively, each have a JobDefinition +property that contains the scheduled job with which they are associated. This +recursive interconnection makes it easy to find the triggers and options of a +scheduled job and to find, script, and display the scheduled job to which any +job trigger or job option is associated. ## SEE ALSO [about_Scheduled_Jobs_Basics](about_Scheduled_Jobs_Basics.md) + [about_Scheduled_Jobs_Advanced](about_Scheduled_Jobs_Advanced.md) + [about_Scheduled_Jobs_Troubleshooting](about_Scheduled_Jobs_Troubleshooting.md) + [about_jobs](../../Microsoft.PowerShell.Core/About/about_Jobs.md) + +[New-JobTrigger](../New-JobTrigger.md) + [Add-JobTrigger](../Add-JobTrigger.md) + +[Remove-JobTrigger](../Remove-JobTrigger.md) + +[Get-JobTrigger](../Get-JobTrigger.md) + +[Set-JobTrigger](../Set-JobTrigger.md) + [Disable-JobTrigger](../Disable-JobTrigger.md) -[Disable-ScheduledJob](../Disable-ScheduledJob.md) + [Enable-JobTrigger](../Enable-JobTrigger.md) + +[Disable-ScheduledJob](../Disable-ScheduledJob.md) + [Enable-ScheduledJob](../Enable-ScheduledJob.md) + +[Register-ScheduledJob](../Register-ScheduledJob.md) + +[Unregister-ScheduledJob](../Unregister-ScheduledJob.md) + [Get-Job](../../Microsoft.PowerShell.Core/Get-Job.md) -[Get-JobTrigger](../Get-JobTrigger.md) -[Get-ScheduledJob](../Get-ScheduledJob.md) -[Get-ScheduledJobOption](../Get-ScheduledJobOption.md) -[New-JobTrigger](../New-JobTrigger.md) -[New-ScheduledJobOption](../New-ScheduledJobOption.md) + [Receive-Job](../../Microsoft.PowerShell.Core/Receive-Job.md) -[Register-ScheduledJob](../Register-ScheduledJob.md) -[Remove-JobTrigger](../Remove-JobTrigger.md) -[Set-JobTrigger](../Set-JobTrigger.md) -[Set-ScheduledJob](../Set-ScheduledJob.md) -[Set-ScheduledJobOption](../Set-ScheduledJobOption.md) + [Start-Job](../../Microsoft.PowerShell.Core/Start-Job.md) -[Unregister-ScheduledJob](../Unregister-ScheduledJob.md) + +[New-ScheduledJobOption](../New-ScheduledJobOption.md) + +[Get-ScheduledJobOption](../Get-ScheduledJobOption.md) + +[Set-ScheduledJobOption](../Set-ScheduledJobOption.md) + +[Get-ScheduledJob](../Get-ScheduledJob.md) + +[Set-ScheduledJob](../Set-ScheduledJob.md) + [Task Scheduler](/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc721871(v=ws.11)) diff --git a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Advanced.md b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Advanced.md index e588d197b057..994e669f9f9a 100644 --- a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Advanced.md +++ b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Advanced.md @@ -9,39 +9,31 @@ title: about_Scheduled_Jobs_Advanced ## SHORT DESCRIPTION -Explains advanced scheduled job topics, including the file structure -that underlies scheduled jobs. +Explains advanced scheduled job topics, including the file structure that +underlies scheduled jobs. ## LONG DESCRIPTION -This topic includes the following sections: - --- Scheduled job directories and files --- Rename a scheduled job --- Start a scheduled job immediately --- Manage execution history - ### SCHEDULED JOB DIRECTORIES AND FILES -Windows PowerShell scheduled jobs are both Windows PowerShell -jobs and Task Scheduler tasks. Each scheduled job is registered -in Task Scheduler and saved on disk in Microsoft .Net Framework -Serialization XML format. +Windows PowerShell scheduled jobs are both Windows PowerShell jobs and Task +Scheduler tasks. Each scheduled job is registered in Task Scheduler and saved +on disk in Microsoft .Net Framework Serialization XML format. -When you create a scheduled job, Windows Powershell creates a -directory for the scheduled job in the -$home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs -directory on the local computer. The directory name is the same -as the job name. +When you create a scheduled job, Windows Powershell creates a directory for the +scheduled job in the +\$home\\AppData\\Local\\Microsoft\\Windows\\PowerShell\\ScheduledJobs directory +on the local computer. The directory name is the same as the job name. The following is a sample ScheduledJobs directory. ```powershell -PS C:\ps-test> dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs +dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs ``` ```output -Directory: C:\Users\User01\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs +Directory: C:\Users\User01\AppData\Local + \Microsoft\Windows\PowerShell\ScheduledJobs Mode LastWriteTime Length Name ---- ------------- ------ ---- @@ -54,16 +46,18 @@ d---- 9/27/2011 1:29 PM Test-HelpFiles d---- 9/26/2011 4:22 PM DeployPackage ``` -Each scheduled job has its own directory. The directory contains -the scheduled job XML file and an Output subdirectory. +Each scheduled job has its own directory. The directory contains the scheduled +job XML file and an Output subdirectory. ```powershell -dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob +dir $home\AppData\Local\Microsoft + \Windows\PowerShell\ScheduledJobs\ProcessJob ``` ```output Directory: -C:\Users\User1\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob +C:\Users\User1\AppData\Local\Microsoft + \Windows\PowerShell\ScheduledJobs\ProcessJob Mode LastWriteTime Length Name ---- ------------- ------ ---- @@ -71,21 +65,24 @@ d---- 11/1/2011 3:00 PM Output -a--- 11/1/2011 3:43 PM 7281 ScheduledJobDefinition.xml ``` -The Output directory for a scheduled job contains its execution -history. Each time a job trigger starts a scheduled job, Windows -PowerShell creates a timestamp-named directory in the Output -directory. The timestamp directory contains the results of the job -in a Results.xml file and the job status in a Status.xml file. +The Output directory for a scheduled job contains its execution history. Each +time a job trigger starts a scheduled job, Windows PowerShell creates a +timestamp-named directory in the Output directory. The timestamp directory +contains the results of the job in a Results.xml file and the job status in a +Status.xml file. -The following command shows the execution history directories for -the ProcessJob scheduled job. +The following command shows the execution history directories for the +ProcessJob scheduled job. ```powershell -dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob\Output +$path = "$home\AppData\Local\Microsoft" +$path += "\Windows\PowerShell\ScheduledJobs\ProcessJob\Output" +dir $path ``` ```output -Directory: C:\Users\User01\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob\Output +Directory: C:\Users\User01\AppData\Local\Microsoft + \Windows\PowerShell\ScheduledJobs\ProcessJob\Output Mode LastWriteTime Length Name ---- ------------- ------ ---- @@ -99,11 +96,14 @@ d---- 11/7/2011 3:00 AM 20111107-030002-376 ``` ```powershell -dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\ProcessJob\Output\20111102-030002-260 +$path = "$home\AppData\Local\Microsoft\Windows\PowerShell\" +$path += "ScheduledJobs\ProcessJob\Output\20111102-030002-260" +dir += $path ``` ```output -Directory: C:\Users\juneb\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\testjob\output\20111102-030002-260 +Directory: C:\Users\juneb\AppData\Local\Microsoft + \Windows\PowerShell\ScheduledJobs\testjob\output\20111102-030002-260 Mode LastWriteTime Length Name ---- ------------- ------ ---- @@ -111,62 +111,63 @@ Mode LastWriteTime Length Name -a--- 11/2/2011 3:00 AM 9451 Status.xml ``` -You can open and examine the ScheduledJobDefinition.xml, Results.xml -and Status.xml files or use the Select-XML cmdlet to parse the files. +You can open and examine the ScheduledJobDefinition.xml, Results.xml and +Status.xml files or use the `Select-XML` cmdlet to parse the files. -WARNING: Do not edit the XML files. If any XML file contains invalid -XML, Windows PowerShell deletes the scheduled job and its -execution history, including job results. +> [!WARNING] +> Do not edit the XML files. If any XML file contains invalid +> XML, Windows PowerShell deletes the scheduled job and its +> execution history, including job results. ### START A SCHEDULED JOB IMMEDIATELY You can start a scheduled job immediately in one of two ways: --- Run the Start-Job cmdlet to start any scheduled job --- Add the RunNow parameter to your Register-ScheduledJob -command to start the job as soon as the command is run +- Run the Start-Job cmdlet to start any scheduled job + +- Add the RunNow parameter to your Register-ScheduledJob command to start the + job as soon as the command is run -Jobs that are started by using the Start-Job cmdlet are standard -Windows PowerShell background jobs, not instances of the scheduled -job. Like all background jobs, these jobs start immediately -- -they are not subject to job options or affected by job triggers --- and their output is not saved in the Output directory of the -scheduled job directory. +Jobs that are started by using the Start-Job cmdlet are standard Windows +PowerShell background jobs, not instances of the scheduled job. Like all +background jobs, these jobs start immediately, they are not subject to job +options or affected by job triggers, and their output is not saved in the +Output directory of the scheduled job directory. -The following command uses the DefinitionName parameter of the -Start-Job cmdlet to start the ProcessJob scheduled job. +The following command uses the DefinitionName parameter of the `Start-Job` +cmdlet to start the ProcessJob scheduled job. +```powershell Start-Job -DefinitionName ProcessJob +``` -To manage the job and get the job results, use the Job cmdlets. -For more information about the Job cmdlets, see [about_Jobs](../../Microsoft.PowerShell.Core/About/about_Jobs.md). +To manage the job and get the job results, use the Job cmdlets. For more +information about the Job cmdlets, see [about_Jobs](../../Microsoft.PowerShell.Core/About/about_Jobs.md). -NOTE: To use the Job cmdlets on instances of scheduled jobs, the -PSScheduledJob module must be imported into the session. -To import the PSScheduledJob module, type -"Import-Module PSScheduledJob" (without quotation marks) or -use any Scheduled Job cmdlet, such as Get-ScheduledJob. +> [!NOTE] +> To use the Job cmdlets on instances of scheduled jobs, the +> PSScheduledJob module must be imported into the session. +> To import the PSScheduledJob module, type +> `Import-Module PSScheduledJob` (without quotation marks) or +> use any Scheduled Job cmdlet, such as `Get-ScheduledJob`. ### RENAME A SCHEDULED JOB -To rename a scheduled job, use the Name parameter of the -Set-ScheduledJob cmdlet. When you rename a scheduled job, -Windows PowerShell changes the name of the scheduled job and -the scheduled job directory. However, it doesn't change the -names of instances of the scheduled job that have already -run. +To rename a scheduled job, use the Name parameter of the `Set-ScheduledJob` +cmdlet. When you rename a scheduled job, Windows PowerShell changes the name of +the scheduled job and the scheduled job directory. However, it doesn't change +the names of instances of the scheduled job that have already run. ### GET START AND END TIMES -To get the dates and times that job instances started and -ended, use the PSBeginTime and PSEndTime properties of the -ScheduledJob object that Get-Job returns for scheduled jobs. +To get the dates and times that job instances started and ended, use the +PSBeginTime and PSEndTime properties of the ScheduledJob object that `Get-Job` +returns for scheduled jobs. -The following example uses the Property parameter of the -Format-Table cmdlet to display the PSBeginTime and PSEndTime -properties of each job instance in a table. The command uses -a calculated property to display the elapsed time of each job -instance. +The following example uses the Property parameter of the `Format-Table` cmdlet to +display the PSBeginTime and PSEndTime properties of each job instance in a +table. The command uses a calculated property to display the elapsed time of +each job instance. ```powershell Get-Job -Name UpdateHelpJob | Format-Table -Property ID, PSBeginTime, PSEndTime, @@ -188,55 +189,49 @@ Id PSBeginTime PSEndTime Elapsed Time ### MANAGE EXECUTION HISTORY -You can determine the number of job instance results that are -saved for each schedule job and delete the execution history -and saved job results of any scheduled job at any time. - -The ExecutionHistoryLength property of a scheduled job determines -how many job instance results are saved for the scheduled job. -When the number of saved results exceeds the value of the -ExecutionHistoryLength property, Windows PowerShell deletes the -results of the oldest instance to make room for the results of -the newest instance. - -By default, Windows PowerShell saves the execution history and -results of 32 instances of each scheduled job. To change that -value, use the MaxResultCount parameters of the Register-ScheduledJob -or Set-ScheduledJob cmdlets. - -To delete the execution history and all results for a scheduled -job, use the ClearExecutionHistory parameter of the Set-ScheduledJob -cmdlet. Deleting this execution history does not prevent Windows -PowerShell from saving the results of new instances of the scheduled -job. - -The following command uses the Register-ScheduledJob cmdlet to -creates a scheduled job. The command uses the MaxResultCount parameter -with a value of 12 to save only the 12 newest job instance results -of the scheduled job. +You can determine the number of job instance results that are saved for each +schedule job and delete the execution history and saved job results of any +scheduled job at any time. + +The ExecutionHistoryLength property of a scheduled job determines how many job +instance results are saved for the scheduled job. When the number of saved +results exceeds the value of the ExecutionHistoryLength property, Windows +PowerShell deletes the results of the oldest instance to make room for the +results of the newest instance. + +By default, Windows PowerShell saves the execution history and results of 32 +instances of each scheduled job. To change that value, use the MaxResultCount +parameters of the `Register-ScheduledJob` or `Set-ScheduledJob` cmdlets. + +To delete the execution history and all results for a scheduled job, use the +ClearExecutionHistory parameter of the Set-ScheduledJob cmdlet. Deleting this +execution history does not prevent Windows PowerShell from saving the results +of new instances of the scheduled job. + +The following command uses the `Register-ScheduledJob` cmdlet to creates a +scheduled job. The command uses the MaxResultCount parameter with a value of 12 +to save only the 12 newest job instance results of the scheduled job. ```powershell Register-ScheduledJob -Name ProcessJob -ScriptBlock {Get-Process} -MaxResultCount 12 ``` -The following command uses the MaxResultCount parameter of the -Set-ScheduledJob cmdlet to increase the number of saved instance -results to 15. +The following command uses the MaxResultCount parameter of the Set-ScheduledJob +cmdlet to increase the number of saved instance results to 15. ```powershell Get-ScheduledJob ProcessJob | Set-ScheduledJob -MaxResultCount 15 ``` -The following command deletes the execution history and all -currently saved results of the ProcessJob scheduled job. +The following command deletes the execution history and all currently saved +results of the ProcessJob scheduled job. ```powershell Get-ScheduledJob ProcessJob | Set-ScheduledJob -ClearExecutionHistory ``` -The following command gets the values of the name and -ExecutionHistoryLength properties of all scheduled jobs on the -computer and displays them in a table. +The following command gets the values of the name and ExecutionHistoryLength +properties of all scheduled jobs on the computer and displays them in a table. ```powershell Get-ScheduledJob | Format-Table -Property Name, ExecutionHistoryLength -AutoSize @@ -245,5 +240,7 @@ Get-ScheduledJob | Format-Table -Property Name, ExecutionHistoryLength -AutoSize ## SEE ALSO [about_Scheduled_Jobs](about_Scheduled_Jobs.md) + [about_Scheduled_Jobs_Troubleshooting](about_Scheduled_Jobs_Troubleshooting.md) -[about_Jobs](../../Microsoft.PowerShell.Core/About/about_Jobs.md) + +[about_Jobs](../../Microsoft.PowerShell.Core/About/about_Jobs.md) \ No newline at end of file diff --git a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Basics.md b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Basics.md index 11756f9d219f..53cc90a79c28 100644 --- a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Basics.md +++ b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Basics.md @@ -13,26 +13,23 @@ Explains how to create and manage scheduled jobs. ## LONG DESCRIPTION -This topic shows how to perform basic tasks of creating and -managing scheduled jobs. For information about more advanced -tasks, see about_Scheduled_Jobs_Advanced. +This topic shows how to perform basic tasks of creating and managing scheduled +jobs. For information about more advanced tasks, see +about_Scheduled_Jobs_Advanced. ### HOW TO CREATE A SCHEDULED JOB -To create a scheduled job, use the Register-ScheduledJob -cmdlet. The cmdlet requires a name and the commands or -script that the job runs. You can either run the job -immediately by adding the RunNow parameter, or create a -job trigger and set job options when you create the job -or at a later time. +To create a scheduled job, use the `Register-ScheduledJob` cmdlet. The cmdlet +requires a name and the commands or script that the job runs. You can either +run the job immediately by adding the RunNow parameter, or create a job trigger +and set job options when you create the job or at a later time. -To create a job that runs a script, use the FilePath -parameter to specify the path to the script file. To create -a job that runs commands, use the ScriptBlock parameter. +To create a job that runs a script, use the FilePath parameter to specify the +path to the script file. To create a job that runs commands, use the +ScriptBlock parameter. -The following command creates the ProcessJob, which runs a -Get-Process command. This scheduled job has the default job -options and no job trigger. +The following command creates the ProcessJob, which runs a `Get-Process` +command. This scheduled job has the default job options and no job trigger. ```powershell Register-ScheduledJob -Name ProcessJob -ScriptBlock { Get-Process } @@ -46,64 +43,61 @@ Id Name Triggers Command Enabled ### HOW TO CREATE A JOB TRIGGER -Job triggers start a scheduled job automatically. A job trigger -can be one-time or recurring schedule or an event, such as when -a user logs on or Windows starts. Each job can have zero, one, -or multiple job triggers. - -To create a job trigger, use the New-JobTrigger cmdlet. The -following command creates a job trigger that starts a job every -Monday and Thursday at 5:00 AM. The command saves the job -trigger in the $t variable. +Job triggers start a scheduled job automatically. A job trigger can be one-time +or recurring schedule or an event, such as when a user logs on or Windows +starts. Each job can have zero, one, or multiple job triggers. +To create a job trigger, use the `New-JobTrigger` cmdlet. The following command +creates a job trigger that starts a job every Monday and Thursday at 5:00 AM. +The command saves the job trigger in the `$t` variable. ```powershell $t = New-JobTrigger -Weekly -DaysOfWeek "Monday", "Thursday" -At "5:00 AM" ``` -Job triggers are optional. You can start a scheduled job at -any time by adding the RunNow parameter to your -Register-ScheduledJob command, or by using the Start-Job -cmdlets. +Job triggers are optional. You can start a scheduled job at any time by adding +the RunNow parameter to your `Register-ScheduledJob` command, or by using the +`Start-Job` cmdlets. ### HOW TO ADD A JOB TRIGGER -When you add a job trigger to a scheduled job, the job trigger -is added to the scheduled job XML file for the scheduled job -and becomes part of the scheduled job. +When you add a job trigger to a scheduled job, the job trigger is added to the +scheduled job XML file for the scheduled job and becomes part of the scheduled +job. -You can add a job trigger to a scheduled job when you create -the scheduled job or at a later time and you can change the -job trigger of a scheduled job at any time. +You can add a job trigger to a scheduled job when you create the scheduled job +or at a later time and you can change the job trigger of a scheduled job at any +time. -Windows PowerShell uses some of the same job triggers that Task -Scheduler uses. For detailed information about job triggers, -see the help topic for the New-JobTrigger cmdlet. +Windows PowerShell uses some of the same job triggers that Task Scheduler uses. +For detailed information about job triggers, see the help topic for the +`New-JobTrigger` cmdlet. -The following command uses the Register-ScheduledJob cmdlet -to create the process job. It uses the Trigger parameter to -specify the job trigger in the $t variable. +The following command uses the `Register-ScheduledJob` cmdlet to create the +process job. It uses the Trigger parameter to specify the job trigger in the $t +variable. ```powershell -Register-ScheduledJob -Name ProcessJob -ScriptBlock {Get-Command} -Trigger $t +Register-ScheduledJob -Name ProcessJob ` + -ScriptBlock {Get-Command} -Trigger $t ``` -You can also add a job trigger to an existing scheduled job -at any time. The following command adds the job trigger in the -$t variable to the ProcessJob scheduled job. +You can also add a job trigger to an existing scheduled job at any time. The +following command adds the job trigger in the `$t` variable to the ProcessJob +scheduled job. ```powershell Add-JobTrigger -Name ProcessJob -Trigger $t ``` -As a result of this command, the job trigger starts the -ProcessJob automatically every Monday and Thursday at 5:00 AM. +As a result of this command, the job trigger starts the ProcessJob +automatically every Monday and Thursday at 5:00 AM. ### HOW TO GET A JOB TRIGGER -To get the job trigger of a scheduled job, use the -Get-JobTrigger cmdlet. Use the Name, ID, and InputObject parameters -to specify the scheduled job (not the job trigger). +To get the job trigger of a scheduled job, use the `Get-JobTrigger` cmdlet. Use +the Name, ID, and InputObject parameters to specify the scheduled job (not the +job trigger). The following command gets the job trigger of the ProcessJob. @@ -119,27 +113,23 @@ Id Frequency Time DaysOfWeek Enabled ### HOW TO CREATE JOB OPTIONS -Job options establish conditions for starting and running the -job. Every job has the default job options unless you change -them. Because job options can prevent a job from running at the -scheduled time, it is important to understand the job options -and use them carefully. +Job options establish conditions for starting and running the job. Every job +has the default job options unless you change them. Because job options can +prevent a job from running at the scheduled time, it is important to understand +the job options and use them carefully. -Windows PowerShell uses the same job options that Task Scheduler -uses. For detailed information about the job options, see the -help topic for the New-ScheduledJobOption cmdlet. Type "Get-Help -New-ScheduledJobOption" or see the help topic online at -[New-ScheduledJobOption](../Get-JobTrigger.md). +Windows PowerShell uses the same job options that Task Scheduler uses. For +detailed information about the job options, see the help topic for the +`New-ScheduledJobOption` cmdlet. Type `Get-Help New-ScheduledJobOption` +or see the help topic online at [New-ScheduledJobOption](../Get-JobTrigger.md). -Job options are stored in the scheduled job XML file. You can -set job options when you create a scheduled job or change them at -any time. +Job options are stored in the scheduled job XML file. You can set job options +when you create a scheduled job or change them at any time. -The following command creates a scheduled job option in which -the WakeToRun scheduled job option is set to True. The WakeToRun -option runs the scheduled job even if the computer is in the Sleep -or Hibernate state at the scheduled start time. The command saves -the job options in the $o variable. +The following command creates a scheduled job option in which the WakeToRun +scheduled job option is set to True. The WakeToRun option runs the scheduled +job even if the computer is in the Sleep or Hibernate state at the scheduled +start time. The command saves the job options in the $o variable. ```powershell $o = New-ScheduledJobOption -WakeToRun @@ -147,10 +137,9 @@ $o = New-ScheduledJobOption -WakeToRun ### HOW TO GET JOB OPTIONS -To get the job options of a scheduled job, use the -Get-ScheduledJobOption cmdlet. Use the Name, ID, and -InputObject parameters to specify the scheduled job (not -the job options). +To get the job options of a scheduled job, use the `Get-ScheduledJobOption` +cmdlet. Use the Name, ID, and InputObject parameters to specify the scheduled +job (not the job options). The following command gets the job options of the ProcessJob. @@ -172,89 +161,86 @@ RunElevated : False RunWithoutNetwork : True DoNotAllowDemandStart : False MultipleInstancePolicy : IgnoreNew -JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition +JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition ``` ### HOW TO CHANGE JOB OPTIONS -You can change the job options of a scheduled job when you -create a scheduled job or at any time thereafter. +You can change the job options of a scheduled job when you create a scheduled +job or at any time thereafter. -The following command uses the Add-JobTrigger cmdlet -to create the process job. It uses the ScheduledJobOption -parameter to specify the job options in the $o variable. +The following command uses the `Add-JobTrigger` cmdlet to create the process job. +It uses the ScheduledJobOption parameter to specify the job options in the $o +variable. ```powershell -Add-JobTrigger -Name ProcessJob -ScriptBlock {Get-Process} -ScheduledJobOption $o +Add-JobTrigger -Name ProcessJob -ScriptBlock {Get-Process}` + -ScheduledJobOption $o ``` -You can also change the job options to an existing scheduled -job at any time. The following command uses the -Set-ScheduledJobOption cmdlet to change the value of the -WakeToRun option of the ProcessJob scheduledJob to True. +You can also change the job options to an existing scheduled job at any time. +The following command uses the `Set-ScheduledJobOption` cmdlet to change the +value of the WakeToRun option of the ProcessJob scheduledJob to True. Like all of the Set cmdlets in the PSScheduledJob module, -Set-ScheduledJobOption cmdlet does not have Name or ID parameters. -You can use the InputObject parameter to specify the scheduled -job options or pipe a scheduled job from Get-ScheduledJobOption -cmdlet to Set-ScheduledJobOption. +`Set-ScheduledJobOption` cmdlet does not have Name or ID parameters. You can use +the InputObject parameter to specify the scheduled job options or pipe a +scheduled job from `Get-ScheduledJobOption` cmdlet to `Set-ScheduledJobOption`. -The following command uses the Get-ScheduledJob cmdlet to get the -ProcessJob. It uses the Get-ScheduledJobOption cmdlet to get the -job options in the ProcessJob and the Set-ScheduledJobOption cmdlet -to change the WakeToRun job option in the ProcessJob to True. +The following command uses the `Get-ScheduledJob` cmdlet to get the ProcessJob. +It uses the `Get-ScheduledJobOption` cmdlet to get the job options in the +ProcessJob and the `Set-ScheduledJobOption` cmdlet to change the WakeToRun job +option in the ProcessJob to True. ```powershell -Get-ScheduledJob -Name ProcessJob | Get-ScheduledJobOption | Set-ScheduledJobOption -WakeToRun +Get-ScheduledJob -Name ProcessJob | Get-ScheduledJobOption ` +| Set-ScheduledJobOption -WakeToRun ``` ### HOW TO GET SCHEDULED JOB INSTANCES -When a scheduled job is started, Windows PowerShell creates a -job instance that is similar to a standard Windows PowerShell -background job. You can use the Job cmdlets, such as Get-Job, -Stop-Job and Receive-Job to manage the job instances. +When a scheduled job is started, Windows PowerShell creates a job instance that +is similar to a standard Windows PowerShell background job. You can use the Job +cmdlets, such as Get-Job, Stop-Job and Receive-Job to manage the job instances. -NOTE: To use the Job cmdlets on instances of scheduled jobs, the -PSScheduledJob module must be imported into the session. To -import the PSScheduledJob module, type "Import-Module PSScheduledJob" -(without quotation marks) or use any Scheduled Job cmdlet, such -as Get-ScheduledJob. +NOTE: To use the Job cmdlets on instances of scheduled jobs, the PSScheduledJob +module must be imported into the session. To import the PSScheduledJob module, +type `Import-Module PSScheduledJob` or use any Scheduled Job cmdlet, such as +`Get-ScheduledJob`. -To get all instances of Windows PowerShell scheduled jobs (and -all active standard jobs), use the Get-Job cmdlet. The following -command imports the PSScheduledJob module and then gets all jobs on -the local computer. +To get all instances of Windows PowerShell scheduled jobs (and all active +standard jobs), use the Get-Job cmdlet. The following command imports the +PSScheduledJob module and then gets all jobs on the local computer. ```powershell Import-Module PSScheduledJob Get-Job ``` -The following command gets all instances of the ProcessJob on -the local computer. +The following command gets all instances of the ProcessJob on the local +computer. ```powershell Get-Job -Name ProcessJob ``` ```output -Id Name PSJobTypeName State HasMoreData Location Command --- ---- ------------ ----- ----------- -------- ------- -45 ProcessJob PSScheduledJob Completed True localhost Get-Process -46 ProcessJob PSScheduledJob Completed True localhost Get-Process -47 ProcessJob PSScheduledJob Completed True localhost Get-Process -48 ProcessJob PSScheduledJob Completed True localhost Get-Process -49 ProcessJob PSScheduledJob Completed True localhost Get-Process -50 ProcessJob PSScheduledJob Completed True localhost Get-Process -51 ProcessJob PSScheduledJob Completed True localhost Get-Process +Id Name PSJobTypeName State HasMoreData Location Command +-- ---- ------------ ----- ----------- -------- ------- +45 ProcessJob PSScheduledJob Completed True localhost Get-Process +46 ProcessJob PSScheduledJob Completed True localhost Get-Process +47 ProcessJob PSScheduledJob Completed True localhost Get-Process +48 ProcessJob PSScheduledJob Completed True localhost Get-Process +49 ProcessJob PSScheduledJob Completed True localhost Get-Process +50 ProcessJob PSScheduledJob Completed True localhost Get-Process +51 ProcessJob PSScheduledJob Completed True localhost Get-Process ``` -The default display does not show the start time, which typically -distinguishes instances of the same scheduled job. +The default display does not show the start time, which typically distinguishes +instances of the same scheduled job. -The following command uses the Format-Table cmdlet to display the Name, -ID, and BeginTime properties of the scheduled job. +The following command uses the `Format-Table` cmdlet to display the Name, ID, and +BeginTime properties of the scheduled job. ```powershell Get-Job ProcessJob | Format-Table -Property Name, ID, BeginTime @@ -275,31 +261,32 @@ ProcessJob 50 11/8/2011 3:00:02 AM ### GET SCHEDULED JOB RESULTS -To get the results of an instance of a scheduled job, use the -Receive-Job cmdlet. +To get the results of an instance of a scheduled job, use the Receive-Job +cmdlet. -NOTE: To use the Job cmdlets on instances of scheduled jobs, the -PSScheduledJob module must be imported into the session. To -import the PSScheduledJob module, type "Import-Module PSScheduledJob" -(without quotation marks) or use any Scheduled Job cmdlet, such -as Get-ScheduledJob. +NOTE: To use the Job cmdlets on instances of scheduled jobs, the PSScheduledJob +module must be imported into the session. To import the PSScheduledJob module, +type `Import-Module PSScheduledJob` or use any +Scheduled Job cmdlet, such as `Get-ScheduledJob`. -The following command gets the results of the newest instance of -the ProcessJob scheduled job (ID = 51) +The following command gets the results of the newest instance of the ProcessJob +scheduled job (ID = 51) ```powershell Import-Module PSScheduledJob Receive-Job -Id 51 -Keep ``` -The results of scheduled jobs are saved on disk, so the Keep parameter -of Receive-Job is not required. However, without the Keep parameter, -you can get the results of a scheduled job only once in each Windows -PowerShell session. To start a new Windows PowerShell session, type -"PowerShell" or open a new Windows PowerShell window. +The results of scheduled jobs are saved on disk, so the Keep parameter of +Receive-Job is not required. However, without the Keep parameter, you can get +the results of a scheduled job only once in each Windows PowerShell session. To +start a new Windows PowerShell session, type "PowerShell" or open a new Windows +PowerShell window. ## SEE ALSO [about_Scheduled_Jobs](about_Scheduled_Jobs.md) + [about_Scheduled_Jobs_Advanced](about_Scheduled_Jobs_Advanced.md) + [about_Scheduled_Jobs_Troubleshooting](about_Scheduled_Jobs_Troubleshooting.md) diff --git a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Troubleshooting.md b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Troubleshooting.md index 0521c92c4994..9df974557b09 100644 --- a/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Troubleshooting.md +++ b/reference/3.0/PSScheduledJob/About/about_Scheduled_Jobs_Troubleshooting.md @@ -13,34 +13,27 @@ Explains how to resolve problems with scheduled jobs ## LONG DESCRIPTION -This section describes some of the problems that you might encounter when -using the scheduled job features of Windows PowerShell and it suggests -solutions to these problems. +This section describes some of the problems that you might encounter when using +the scheduled job features of Windows PowerShell and it suggests solutions to +these problems. -Before using Windows PowerShell scheduled jobs, see about_Scheduled_Jobs -and the related scheduled jobs about topics. +Before using Windows PowerShell scheduled jobs, see `about_Scheduled_Jobs` and +the related scheduled jobs about topics. -This topic contains the following sections: --- CANNOT FIND JOB RESULTS --- SCHEDULED JOB DOES NOT RUN --- CANNOT GET SCHEDULED JOB : SCHEDULED JOB IS CORRUPTED --- JOB CMDLETS CANNOT CONSISTENTLY FIND SCHEDULED JOBS +### CANNOT FIND JOB RESULTS -## CANNOT FIND JOB RESULTS +#### Basic method for getting job results in Windows PowerShell --- Basic method for getting job results in Windows PowerShell +When a scheduled job runs, it creates an "instance" of the scheduled job. To +view, manage, and get the results of scheduled job instances, use the Job +cmdlets. -When a scheduled job runs, it creates an "instance" of the scheduled job. -To view, manage, and get the results of scheduled job instances, use the -Job cmdlets. - -NOTE: To use the Job cmdlets on instances of scheduled jobs, the -PSScheduledJob module must be imported into the session. To import -the PSScheduledJob module, type "Import-Module PSScheduledJob" -(without quotation marks) or use any Scheduled Job cmdlet, such as -Get-ScheduledJob. - -To get a list of all instances of a scheduled job, use the Get-Job cmdlet. +> [!NOTE] +> To use the Job cmdlets on instances of scheduled jobs, the PSScheduledJob +> module must be imported into the session. To import the PSScheduledJob module, +> type `Import-Module PSScheduledJob` or use any Scheduled Job cmdlet, such as +> `Get-ScheduledJob`. To get a list of all instances of a scheduled job, use the +> `Get-Job` cmdlet. ```powershell Import-Module PSScheduledJob @@ -80,40 +73,42 @@ ProcessJob 49 11/7/2011 3:00:02 AM ProcessJob 50 11/8/2011 3:00:02 AM ``` -To get the results of an instance of a scheduled job, use the -Receive-Job cmdlet. The following command gets the results of the -newest instance of the ProcessJob (ID = 50). +To get the results of an instance of a scheduled job, use the `Receive-Job` +cmdlet. The following command gets the results of the newest instance of the +ProcessJob (ID = 50). ```powershell Receive-Job -Id 50 ``` --- Basic method for finding job results on disk +#### Basic method for finding job results on disk -To manage scheduled jobs, use the Job cmdlets, such as Get-Job and -Receive-Job. +To manage scheduled jobs, use the Job cmdlets, such as `Get-Job` and +`Receive-Job`. -If Get-Job does not get the job instance or Receive-Job does not get -the job results, you can search the execution history files for the -job on disk. The execution history contains a record of all triggered -job instances. +If `Get-Job` does not get the job instance or `Receive-Job` does not get the +job results, you can search the execution history files for the job on disk. +The execution history contains a record of all triggered job instances. -Verify that there is a timestamp-named directory in the directory -for a scheduled job in the following path: +Verify that there is a timestamp-named directory in the directory for a +scheduled job in the following path: +``` $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJob \Output +``` Typically: -C:\Users\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJob -\Output + C:\\Users\\AppData\\Local\\Microsoft\Windows\\PowerShell + \\ScheduledJob\\\\Output For example, the following command gets the on-disk execution history of the ProcessJob scheduled job. ```powershell -dir $home\AppData\Local\Microsoft\Windows\PowerShell -\ScheduledJobs\ProcessJob\Output +$path = '$home\AppData\Local\Microsoft\Windows\PowerShell' +$path += '\ScheduledJobs\ProcessJob\Output' +dir $path ``` ```output @@ -131,16 +126,16 @@ d---- 11/7/2011 12:00 AM 20111107-000001-914 d---- 11/7/2011 3:00 AM 20111107-030002-376 ``` -Each timestamp-named directory represents a job instance. The results -of each job instance are saved in a Results.xml file in the -timestamp-named directory. +Each timestamp-named directory represents a job instance. The results of each +job instance are saved in a Results.xml file in the timestamp-named directory. -For example, the following command gets the Results.xml files for -every saved instance of the ProcessJob scheduled job. +For example, the following command gets the Results.xml files for every saved +instance of the ProcessJob scheduled job. ```powershell -dir $home\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs -\ProcessJob\Output\*\Results.xml +$path = '$home\AppData\Local\Microsoft\Windows\PowerShell' +$path += '\ScheduledJobs\ProcessJob\Output\*\Results.xml' +dir $path ``` ```output @@ -148,40 +143,40 @@ Directory: C:\Users\User01\Appdata\Local\Microsoft\Windows\PowerShell \ScheduledJobs\ProcessJob\Output ``` -If the Results.xml file is missing, Windows PowerShell cannot return -or display the job results. +If the Results.xml file is missing, Windows PowerShell cannot return or display +the job results. --- The Job cmdlet might not be able to get scheduled job instances or -their results because the PSScheduledJob module is not imported into -the session. +- The Job cmdlet might not be able to get scheduled job instances or their + results because the PSScheduledJob module is not imported into the session. -NOTE: Before using a Job cmdlet on scheduled job instances, verify that -the PSScheduledJob module is included in the session. Without the -module, the Job cmdlets cannot get scheduled job instances or -their results. +> [!NOTE] +> Before using a Job cmdlet on scheduled job instances, verify that the +> PSScheduledJob module is included in the session. Without the module, the Job +> cmdlets cannot get scheduled job instances or their results. To import the PSScheduledJob module, type: ```powershell Import-Module PSScheduledJob ``` --- The Receive-Job cmdlet might already have returned the results in the -current session. -If Receive-Job does not return job instance results, it might be -because a Receive-Job command has been run for that job instance -in the current session without the Keep parameter. +> [!NOTE] +> The `Receive-Job` cmdlet might already have returned the results in the +> current session. -When you use Receive-Job without the Keep parameter, Receive-Job -returns the job results and sets the HasMoreData property of the job -instance to False to indicate that it returned all of the results -for the job instance and has no more results to return. This setting -is appropriate for standard background jobs, but not for instances -of scheduled jobs, which are saved to disk. +If `Receive-Job` does not return job instance results, it might be because a +`Receive-Job` command has been run for that job instance in the current session +without the Keep parameter. -To get the job instance results again, start a new Windows PowerShell -session (type "PowerShell" without quotation marks), import the -PSScheduledJob module, and try the Receive-Job command again. +When you use `Receive-Job` without the Keep parameter, `Receive-Job` returns +the job results and sets the HasMoreData property of the job instance to False +to indicate that it returned all of the results for the job instance and has no +more results to return. This setting is appropriate for standard background +jobs, but not for instances of scheduled jobs, which are saved to disk. + +To get the job instance results again, start a new Windows PowerShell session +`PowerShell.exe`, import the PSScheduledJob module, and try the `Receive-Job` +command again. ```powershell Receive-Job -ID 50 @@ -206,16 +201,16 @@ Receive-Job -Id 50 ``` ```output -Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName -------- ------ ----- ----- ----- ------ -- ----------- -1213 33 12348 21676 88 25.71 1608 CcmExec -29 4 1168 2920 43 0.02 748 conhost -46 6 2208 4612 45 0.03 1640 conhost +Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName +------- ------ ----- ----- ----- ------ -- ----------- +1213 33 12348 21676 88 25.71 1608 CcmExec +29 4 1168 2920 43 0.02 748 conhost +46 6 2208 4612 45 0.03 1640 conhost ... ``` -To get the result of a job instance more than one time in a session, -use the Keep parameter of the Receive-Job cmdlet. +To get the result of a job instance more than one time in a session, use the +Keep parameter of the Receive-Job cmdlet. ```powershell Import-Module PSScheduledJob @@ -223,11 +218,11 @@ Receive-Job -Id 50 -Keep ``` ```output -Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName -------- ------ ----- ----- ----- ------ -- ----------- -1213 33 12348 21676 88 25.71 1608 CcmExec -29 4 1168 2920 43 0.02 748 conhost -46 6 2208 4612 45 0.03 1640 conhost +Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName +------- ------ ----- ----- ----- ------ ---- ----------- +1213 33 12348 21676 88 25.71 1608 CcmExec +29 4 1168 2920 43 0.02 748 conhost +46 6 2208 4612 45 0.03 1640 conhost ``` ```powershell @@ -235,51 +230,50 @@ Receive-Job -Id 50 -Keep ``` ```output -Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName -------- ------ ----- ----- ----- ------ -- ----------- -1213 33 12348 21676 88 25.71 1608 CcmExec -29 4 1168 2920 43 0.02 748 conhost -46 6 2208 4612 45 0.03 1640 conhost +Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName +------- ------ ----- ----- ----- ------ ---- ----------- +1213 33 12348 21676 88 25.71 1608 CcmExec +29 4 1168 2920 43 0.02 748 conhost +46 6 2208 4612 45 0.03 1640 conhost ``` --- The scheduled job might be corrupted. +#### The scheduled job might be corrupted -If a scheduled job becomes corrupted, Windows PowerShell deletes -the corrupted scheduled job and its results. You cannot recover the -results of a corrupted scheduled job. +If a scheduled job becomes corrupted, Windows PowerShell deletes the corrupted +scheduled job and its results. You cannot recover the results of a corrupted +scheduled job. -To determine if a scheduled job still exists, use the Get-ScheduledJob cmdlet. +To determine if a scheduled job still exists, use the `Get-ScheduledJob` cmdlet. ```powershell Get-ScheduledJob ``` --- The number of results might have exceeded the ExecutionHistoryLength -of the scheduled job. +#### Results are greater than the ExecutionHistoryLength of the scheduled job -The ExecutionHistoryLength property of a scheduled job determines -how many job instances, and their results, are saved to disk. The -default value is 32. When the number of instances of a scheduled -job exceeds this value, Windows PowerShell deletes the oldest job -instance to make room for each new job instance. +The ExecutionHistoryLength property of a scheduled job determines how many job +instances, and their results, are saved to disk. The default value is 32. When +the number of instances of a scheduled job exceeds this value, Windows +PowerShell deletes the oldest job instance to make room for each new job +instance. -To get the value of the ExecutionHistoryLength property of a -scheduled job, use the following command format: +To get the value of the ExecutionHistoryLength property of a scheduled job, use +the following command format: ``` (Get-ScheduledJob ).ExecutionHistoryLength ``` -For example, the following command gets the value of the -ExecutionHistoryLength property of the ProcessJob scheduled job. +For example, the following command gets the value of the ExecutionHistoryLength +property of the ProcessJob scheduled job. ```powershell (Get-ScheduledJob ProcessJob).ExecutionHistoryLength ``` -To set or change the value of the ExecutionHistoryLength property, -use the MaxResultCount parameter of the Register-ScheduledJob and -Set-ScheduledJob cmdlets. +To set or change the value of the ExecutionHistoryLength property, use the +MaxResultCount parameter of the `Register-ScheduledJob` and `Set-ScheduledJob` +cmdlets. The following command increases the value of the ExecutionHistoryLength property to 50. @@ -288,52 +282,51 @@ property to 50. Get-ScheduledJob ProcessJob | Set-ScheduledJob -MaxResultCount 50 ``` --- The job instance results might have been deleted +#### The job instance results might have been deleted -The ClearExecutionHistory parameter of the Set-ScheduledJob cmdlet -deletes the execution history of a job. You can use this feature to -free up disk space or delete results that are not needed, or already -used, analyzed or saved in a different location. +The ClearExecutionHistory parameter of the `Set-ScheduledJob` cmdlet deletes +the execution history of a job. You can use this feature to free up disk space +or delete results that are not needed, or already used, analyzed or saved in a +different location. To delete the execution history of a scheduled job, use the ClearExecutionHistory parameter of the scheduled job. -The following command deletes the execution history of the -ProcessJob scheduled job. +The following command deletes the execution history of the ProcessJob scheduled +job. ```powershell Get-ScheduledJob ProcessJob | Set-ScheduledJob -ClearExecutionHistory ``` -Also, the Remove-Job cmdlet deletes job results. When you use -Remove-Job to delete a scheduled job, it deletes all instances -of the job on disk, including the execution history and all job -results. +Also, the `Remove-Job` cmdlet deletes job results. When you use Remove-Job to +delete a scheduled job, it deletes all instances of the job on disk, including +the execution history and all job results. --- Jobs started by using the Start-Job cmdlet are not saved to disk. +> [!NOTE] +> Jobs started by using the `Start-Job` cmdlet are not saved to disk. -When you use Start-Job to start a scheduled job, instead of -using a job trigger, Start-Job starts a standard background job. -The background job and its results are not stored in the -execution history of the job on disk. +When you use `Start-Job` to start a scheduled job, instead of using a job +trigger, `Start-Job` starts a standard background job. The background job and +its results are not stored in the execution history of the job on disk. -You can use the Get-Job cmdlet to get the job and the Receive-Job -cmdlet to get the job results, but the results are available only -until you receive them, unless you use the Keep parameter of the -Receive-Job cmdlet. +You can use the `Get-Job` cmdlet to get the job and the `Receive-Job` cmdlet to +get the job results, but the results are available only until you receive them, +unless you use the Keep parameter of the `Receive-Job` cmdlet. -Also, background jobs and their results are session-specific; -they exist only in the session in which they are created. If -you delete the job (Remove-Job), close the session or close -Windows PowerShell, the job instance and its results are deleted. +Also, background jobs and their results are session-specific; they exist only +in the session in which they are created. If you delete the job (`Remove-Job`), +close the session or close Windows PowerShell, the job instance and its results +are deleted. -### SCHEDULED JOB DOES NOT RUN +### Scheduled job does not run --- Scheduled jobs do not run automatically if the job triggers or the -scheduled job are disabled. +> [!NOTE] +> Scheduled jobs do not run automatically if the job triggers or the scheduled +> job are disabled. -Use the Get-ScheduledJob cmdlet to get the scheduled job. Verify that the -value of the Enabled property of the scheduled job is True ($true). +Use the `Get-ScheduledJob` cmdlet to get the scheduled job. Verify that the +value of the Enabled property of the scheduled job is True (`$true`). ```powershell Get-ScheduledJob ProcessJob @@ -353,23 +346,23 @@ Id Name Triggers Command Enabled True ``` -Use the Get-JobTrigger cmdlet to get the job triggers of the scheduled -job. Verify that the value of the Enabled property of the job trigger -is True ($true) +Use the `Get-JobTrigger` cmdlet to get the job triggers of the scheduled job. +Verify that the value of the Enabled property of the job trigger is `$True` ```powershell Get-ScheduledJob ProcessJob | Get-JobTrigger ``` ```output -Id Frequency Time DaysOfWeek Enabled --- --------- ---- ---------- ------- -1 Weekly 11/7/2011 5:00:00 AM {Monday, Thursday} True -2 Daily 11/7/2011 3:00:00 PM True +Id Frequency Time DaysOfWeek Enabled +-- --------- ---- ---------- ------- +1 Weekly 11/7/2011 5:00:00 AM {Monday, Thursday} True +2 Daily 11/7/2011 3:00:00 PM True ``` ```powershell -Get-ScheduledJob ProcessJob | Get-JobTrigger | Format-Table ID, Enabled -AutoSize +Get-ScheduledJob ProcessJob | Get-JobTrigger ` +| Format-Table ID, Enabled -AutoSize ``` ```output @@ -379,26 +372,23 @@ Id Enabled 2 True ``` --- Scheduled jobs do not run automatically if the job triggers are -invalid. - -For example, a job trigger might specify a date in the past or a date -that does not occur, such as the 5th Monday of the month. +- Scheduled jobs do not run automatically if the job triggers are invalid. + - For example, a job trigger might specify a date in the past or a date that + does not occur, such as the 5th Monday of the month. --- Scheduled jobs do not run automatically if the conditions of the job -trigger or the job options are not satisfied. +- Scheduled jobs do not run automatically if the conditions of the job trigger + or the job options are not satisfied. + - For example, a scheduled job that runs only when a particular user logs on + to the computer will not run if that user does not log on or only connects + remotely. -For example, a scheduled job that runs only when a particular user -logs on to the computer will not run if that user does not log on -or only connects remotely. +Examine the options of the scheduled job and make sure that they are satisfied. +For example, a scheduled job that requires that the computer be idle or +requires a network connection, or has a long IdleDuration or a brief +IdleTimeout might never run. -Examine the options of the scheduled job and make sure that they -are satisfied. For example, a scheduled job that requires that the -computer be idle or requires a network connection, or has a long -IdleDuration or a brief IdleTimeout might never run. - -Use the Get-ScheduledJobOption cmdlet to examine the job options -and their values. +Use the `Get-ScheduledJobOption` cmdlet to examine the job options and their +values. ```powershell Get-ScheduledJob -Name ProcessJob @@ -418,88 +408,83 @@ RunElevated : False RunWithoutNetwork : True DoNotAllowDemandStart : False MultipleInstancePolicy : IgnoreNew -JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition +JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition ``` For descriptions of the scheduled job options, see the help topic for [New-ScheduledJobOption](../New-ScheduledJobOption.md). --- The scheduled job instance might have failed. +The scheduled job instance might have failed. -If a scheduled job command fails, Windows PowerShell reports it -immediately by generating an error message. However, if the job fails -when Task Scheduler tries to run it, the error is not available to -Windows PowerShell. +- If a scheduled job command fails, Windows PowerShell reports it immediately + by generating an error message. However, if the job fails when + Task Scheduler tries to run it, the error is not available to + Windows PowerShell. Use the following methods to detect and correct job failures. --- Check the Task Scheduler event log for errors. To check the log, -use Event Viewer or a Windows PowerShell command such as the -following: +- Check the Task Scheduler event log for errors. To check the log, use Event + Viewer or a Windows PowerShell command such as the following: ```powershell -Get-WinEvent -LogName Microsoft-Windows-TaskScheduler/Operational | Where-Object {$_.Message -like "fail"} +Get-WinEvent -LogName Microsoft-Windows-TaskScheduler/Operational ` +| Where-Object {$_.Message -like "fail"} ``` --- Check the job record in Task Scheduler. Windows PowerShell -scheduled jobs are stored in the following Task Scheduled folder: - -Task Scheduler Library\Microsoft\Windows\PowerShell\ScheduledJobs - --- The scheduled job might not run because of insuffienct permission. - -Scheduled jobs run with the permissions of the user who created the -job or the permissions of the user who is specified by the Credential -parameter in the Register-ScheduledJob or Set-ScheduledJob command. +- Check the job record in Task Scheduler. Windows PowerShell scheduled jobs are + stored in the following Task Scheduled folder: + Task Scheduler + Library\\Microsoft\\Windows\\PowerShell\\ScheduledJobs -If that user does not have permission to run the commands or scripts, -the job fails. +- The scheduled job might not run because of insufficient permission. -### CANNOT GET SCHEDULED JOB : SCHEDULED JOB IS CORRUPTED +Scheduled jobs run with the permissions of the user who created the job or the +permissions of the user who is specified by the Credential parameter in the +`Register-ScheduledJob` or `Set-ScheduledJob` command. -On rare occasions, scheduled jobs can become corrupted or contain -internal contradictions that cannot be resolved. Typically, this -happens when the XML files for the scheduled job are manually edited, -resulting in invalid XML. +If that user does not have permission to run the commands or scripts, the job +fails. -When a scheduled job is corrupted, Windows PowerShell attempts to -delete the scheduled job, its execution history, and its results -from disk. +### Cannot get Scheduled Job: ScheduledJob is Corrupted -If it cannot remove the scheduled job, you will get a corrupted job -error message each time you run the Get-ScheduledJob cmdlet. +On rare occasions, scheduled jobs can become corrupted or contain internal +contradictions that cannot be resolved. Typically, this happens when the XML +files for the scheduled job are manually edited, resulting in invalid XML. -To remove a corrupted scheduled job, use either one of the following -methods. +When a scheduled job is corrupted, Windows PowerShell attempts to delete the +scheduled job, its execution history, and its results from disk. --- Delete the directory for the scheduled job. -Do not delete the ScheduledJob directory. +If it cannot remove the scheduled job, you will get a corrupted job error +message each time you run the `Get-ScheduledJob` cmdlet. -The directory is located at $env:UserProfile\AppData\Local\Microsoft\Windows\PowerShell -\ScheduledJobs +To remove a corrupted scheduled job, use either one of the following methods. -Typically: -C:\Users\AppData\Local\Microsoft\Windows\PowerShell -\ScheduledJobs. - --- Use Task Scheduler to delete the scheduled job. Windows PowerShell -scheduled tasks appear in the following Task Scheduler path: +- Delete the \ directory for the scheduled job. Do not delete + the ScheduledJob directory. + - The directory is located at: + `$env:UserProfile\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs` + Followed by the \ + - Typically: + C:\\Users\\AppData\\Local\\Microsoft\\Windows\\PowerShell + \\ScheduledJobs\\. -Task Scheduler Library\Microsoft\Windows\PowerShell\ScheduledJobs +- Use Task Scheduler to delete the scheduled job. Windows PowerShell scheduled + tasks appear in the following Task Scheduler path: + - Task Scheduler Library\\Microsoft\\Windows\\PowerShell + \\ScheduledJobs\\\ --- JOB CMDLETS CANNOT CONSISTENTLY FIND SCHEDULED JOBS +### Job Cmdlets cannot consistently find ScheduledJobs -When the PSScheduledJob module is not in the current session, the -Job cmdlets cannot get scheduled jobs, start them, or get their -results. +When the PSScheduledJob module is not in the current session, the Job cmdlets +cannot get scheduled jobs, start them, or get their results. -To import the PSScheduledJob module, type "Import-Module PSScheduledJob" -or run or get any cmdlet in the module, such as the Get-ScheduledJob -cmdlet. Beginning in Windows PowerShell 3.0, modules are imported -automatically when you get or use any cmdlet in the module. +To import the PSScheduledJob module, type `Import-Module PSScheduledJob` or run +or get any cmdlet in the module, such as the `Get-ScheduledJob` cmdlet. +Beginning in Windows PowerShell 3.0, modules are imported automatically when +you get or use any cmdlet in the module. -When the PSScheduledJob cmdlet is not in the current session, the -following command sequence is possible. +When the PSScheduledJob cmdlet is not in the current session, the following +command sequence is possible. ```powershell Get-Job ProcessJob @@ -543,11 +528,13 @@ Id Name PSJobTypeName State HasMoreData Location 50 ProcessJob PSScheduledJob Completed True localhost ``` -This behavior occurs because the Get-ScheduledJob command automatically +This behavior occurs because the `Get-ScheduledJob` command automatically imports the PSScheduledJob module, and then runs the command. ## SEE ALSO [about_Scheduled_Jobs](about_Scheduled_Jobs.md) + [about_Scheduled_Jobs_Basics](about_Scheduled_Jobs_Basics.md) -[about_Scheduled_Jobs_Advanced](about_Scheduled_Jobs_Advanced.md) + +[about_Scheduled_Jobs_Advanced](about_Scheduled_Jobs_Advanced.md) \ No newline at end of file diff --git a/reference/3.0/PSWorkflow/About/about_ActivityCommonParameters.md b/reference/3.0/PSWorkflow/About/about_ActivityCommonParameters.md index 86a8b641e9a7..3b657a380be5 100644 --- a/reference/3.0/PSWorkflow/About/about_ActivityCommonParameters.md +++ b/reference/3.0/PSWorkflow/About/about_ActivityCommonParameters.md @@ -7,44 +7,34 @@ title: about_ActivityCommonParameters --- # About ActivityCommonParameters -## about_ActivityCommonParameters +## SHORT DESCRIPTION -# SHORT DESCRIPTION +Describes the parameters that Windows PowerShell Workflow adds to activities. -Describes the parameters that Windows PowerShell -Workflow adds to activities. +## LONG DESCRIPTION -# LONG DESCRIPTION +Windows PowerShell Workflow adds the activity common parameters to activities +that are derived from the PSActivity base class. This category includes the +InlineScript activity and Windows PowerShell cmdlets that are implemented as +activities, such as Get-Process and Get-WinEvent. -Windows PowerShell Workflow adds the activity common -parameters to activities that are derived from the -PSActivity base class. This category includes the -InlineScript activity and Windows PowerShell cmdlets -that are implemented as activities, such as Get-Process -and Get-WinEvent. +The activity common parameters are not valid on the Suspend-Workflow and +Checkpoint-Workflow activities and they are not added to cmdlets or expressions +that Windows PowerShell Workflow automatically runs in an InlineScript script +block or similar activity. The activity common parameters are available on the +InlineScript activity, but not on commands in the InlineScript script block. -The activity common parameters are not valid on the -Suspend-Workflow and Checkpoint-Workflow activities -and they are not added to cmdlets or expressions that -Windows PowerShell Workflow automatically runs in an -InlineScript script block or similar activity. The -activity common parameters are available on the -InlineScript activity, but not on commands in the -InlineScript script block. +Several of the activity common parameters are also workflow common parameters +or Windows PowerShell common parameters. Other activity common parameters are +unique to activities. -Several of the activity common parameters are also -workflow common parameters or Windows PowerShell -common parameters. Other activity common parameters -are unique to activities. - -For information about the workflow common parameters, -see about_WorkflowCommonParameters. For information -about the Windows PowerShell common parameters, see -about_CommonParameters. - -# LIST OF ACTIVITY COMMON PARAMETERS +For information about the workflow common parameters, see +about_WorkflowCommonParameters. For information about the Windows PowerShell +common parameters, see about_CommonParameters. +### LIST OF ACTIVITY COMMON PARAMETERS +``` AppendOutput PSDebug Debug PSDisableSerialization DisplayName PSDisableSerializationPreference @@ -63,590 +53,567 @@ PSConnectionRetryCount Result PSConnectionRetryIntervalSec UseDefaultInput PSConnectionURI Verbose PSCredential WarningAction +``` -# PARAMETER DESCRIPTIONS +### PARAMETER DESCRIPTIONS This section describes the activity common parameters. --AppendOutput -A value of $True adds the output of the activity to the value of -the variable. A value of $False has no effect. By default, assigning -a value to a variable replaces the variable value. +#### AppendOutput \ -For example, the following commands add a process object to the -service object in the $x variable. +A value of `$True` adds the output of the activity to the value of the variable. +A value of `$False` has no effect. By default, assigning a value to a variable +replaces the variable value. -workflow Test-Workflow +For example, the following commands add a process object to the service object +in the `$x` variable. + +```powershell +Workflow Test-Workflow { -$x = Get-Service -$x = Get-Process -AppendOutput $true + $x = Get-Service + $x = Get-Process -AppendOutput $true } +``` -This parameter is designed for XAML-based workflows. In script -workflows, you can also use the += assignment operator to add -output to the value of a variable, as shown in the following -example. +This parameter is designed for XAML-based workflows. In script workflows, you +can also use the += assignment operator to add output to the value of a +variable, as shown in the following example. -workflow Test-Workflow +```powershell +Workflow Test-Workflow { -$x = Get-Service -$x += Get-Process + $x = Get-Service + $x += Get-Process } +``` --Debug -Displays programmer-level detail about the operation -performed by the command. The Debug parameter -overrides the value of the $DebugPreference variable -for the current command. This parameter works only -when the command generates debugging messages. This -parameter is also a Windows PowerShell common parameter. - --DisplayName -Specifies a friendly name for the activity. The -DisplayName value appears in the progress bar while -the workflow runs and in the value of the Progress -property of the workflow job. When the PSProgressMessage -parameter is also included in the command, the progress -bar content appears in : -format. - --ErrorAction -Determines how the activity responds to a non-terminating -error from the command. It has no effect on termination -errors. This parameter works only when the command -generates a non-terminating error, such as those from the -Write-Error cmdlet. The ErrorAction parameter overrides -the value of the $ErrorActionPreference variable for the -current command. This parameter is also a Windows PowerShell -common parameter. +#### Debug \ -Valid values: -Continue. Displays the error message and continues -executing the command. "Continue" is the default value. - -Ignore. Suppresses the error message and continues -executing the command. Unlike SilentlyContinue, Ignore -does not add the error message to the $Error automatic -variable. The Ignore value is introduced in Windows -PowerShell 3.0. - -Inquire. Displays the error message and prompts you for -confirmation before continuing execution. This value is -rarely used. - -Suspend. Automatically suspends a workflow job to allow for further -investigation. After investigation, the workflow can be resumed. - -SilentlyContinue. Suppresses the error message and -continues executing the command. - -Stop. Displays the error message and stops executing -the command. - --Input -Submits a collection of objects to an activity. This is an -alternative to piping objects to the activity one at a time. - --MergeErrorToOutput -A value of $True adds errors to the output stream. A value of -$False has not effect. Use this parameter with the Parallel and -ForEach -Parallel keywords to collect errors and output from -multiple parallel commands in a single collection. - --PSActionRetryCount -Tries repeatedly to run the activity if the first attempt -fails. The default value, 0, does not retry. - --PSActionRetryIntervalSec -Determines the interval between action retries in seconds. -The default value, 0, retries the action immediately. This -parameter is valid only when the PSActionRetryCount -parameter is also used in the command. - --PSActionRunningTimeoutSec -Determines how long the activity can run on each target -computer. If the activity does not complete before the -timeout expires, Windows PowerShell Workflow generates a -terminating error and stops processing the workflow on -the affected target computer. - --PSAllowRedirection -A value of $True allows redirection of the connection -to the target computers. A value of $False has no effect. -This activity common parameter is also a workflow common +Displays programmer-level detail about the operation performed by the command. +The Debug parameter overrides the value of the $DebugPreference variable for +the current command. This parameter works only when the command generates +debugging messages. This parameter is also a Windows PowerShell common parameter. -When you use the PSConnectionURI parameter, the remote -destination can return an instruction to redirect to a -different URI. By default, Windows PowerShell does not -redirect connections, but you can use the PSAllowRedirection -parameter with a value of $True to allow redirection of -the connection to the target computer. - -You can also limit the number of times that the connection -is redirected by setting the MaximumConnectionRedirectionCount -property of the $PSSessionOption preference variable, or -the MaximumConnectionRedirectionCount property of the value -of the SSessionOption parameter of cmdlets that create a -session. The default value is 5. - --PSApplicationName -Specifies the application name segment of the connection -URI that is used to connect to the target computers. Use -this parameter to specify the application name when you -are not using the ConnectionURI parameter in the command. -This activity common parameter is also a workflow common -parameter. +#### DisplayName \ -The default value is the value of the $PSSessionApplicationName -preference variable on the target computer. If this preference -variable is not defined, the default value is WSMAN. This value -is appropriate for most uses. For more information, see -[about_Preference_Variables](../../Microsoft.PowerShell.Core/About/about_Preference_Variables.md). +Specifies a friendly name for the activity. The DisplayName value appears in +the progress bar while the workflow runs and in the value of the Progress +property of the workflow job. When the PSProgressMessage parameter is also +included in the command, the progress bar content appears in +\:\ format. + +#### ErrorAction \ + +Determines how the activity responds to a non-terminating error from the +command. It has no effect on termination errors. This parameter works only when +the command generates a non-terminating error, such as those from the +Write-Error cmdlet. The ErrorAction parameter overrides the value of the +$ErrorActionPreference variable for the current command. This parameter is also +a Windows PowerShell common parameter. + +Valid values: + +- Continue. Displays the error message and continues executing + the command. "Continue" is the default value. + +- Ignore. Suppresses the error message and continues executing the command. + Unlike SilentlyContinue, Ignore does not add the error message to the $Error + automatic variable. The Ignore value is introduced in Windows PowerShell 3.0. + +- Inquire. Displays the error message and prompts you for confirmation before + continuing execution. This value is rarely used. + +- Suspend. Automatically suspends a workflow job to allow for further + investigation. After investigation, the workflow can be resumed. + +- SilentlyContinue. Suppresses the error message and continues executing the + command. + +- Stop. Displays the error message and stops executing the command. + +#### Input \ + +Submits a collection of objects to an activity. This is an alternative to +piping objects to the activity one at a time. + +#### MergeErrorToOutput \ + +A value of `$True` adds errors to the output stream. A value of `$False` has +not effect. Use this parameter with the Parallel and `ForEach -Parallel` +keywords to collect errors and output from multiple parallel commands +in a single collection. + +#### PSActionRetryCount \ + +Tries repeatedly to run the activity if the first attempt fails. The default +value, 0, does not retry. + +#### PSActionRetryIntervalSec \ + +Determines the interval between action retries in seconds. The default value, +0, retries the action immediately. This parameter is valid only when the +PSActionRetryCount parameter is also used in the command. -The WinRM service uses the application name to select a -listener to service the connection request. The value of -this parameter should match the value of the URLPrefix -property of a listener on the remote computer. - --PSAuthentication -Specifies the mechanism that is used to authenticate the -user's credentials when connecting to the target computers. -Valid values are Default, Basic, Credssp, Digest, Kerberos, -Negotiate, and NegotiateWithImplicitCredential. The default -value is Default. This activity common parameter is also a +#### PSActionRunningTimeoutSec \ + +Determines how long the activity can run on each target computer. If the +activity does not complete before the timeout expires, Windows PowerShell +Workflow generates a terminating error and stops processing the workflow on the +affected target computer. + +#### PSAllowRedirection \ + +A value of $True allows redirection of the connection to the target computers. +A value of $False has no effect. This activity common parameter is also a workflow common parameter. -For information about the values of this parameter, see the -description of the -System.Management.Automation.Runspaces.AuthenticationMechanism -enumeration in MSDN. - -CAUTION: Credential Security Service 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. - --PSCertificateThumbprint -Specifies the digital public key certificate (X509) of a -user account that has permission to perform this action. Enter -the certificate thumbprint of the certificate. This activity -common parameter is also a workflow common parameter. +When you use the PSConnectionURI parameter, the remote destination can return +an instruction to redirect to a different URI. By default, Windows PowerShell +does not redirect connections, but you can use the PSAllowRedirection parameter +with a value of $True to allow redirection of the connection to the target +computer. + +You can also limit the number of times that the connection is redirected by +setting the MaximumConnectionRedirectionCount property of the `$PSSessionOption` +preference variable, or the MaximumConnectionRedirectionCount property of the +value of the SSessionOption parameter of cmdlets that create a session. The +default value is 5. + +#### PSApplicationName \ + +Specifies the application name segment of the connection URI that is used to +connect to the target computers. Use this parameter to specify the application +name when you are not using the ConnectionURI parameter in the command. This +activity common parameter is also a workflow common parameter. + +The default value is the value of the `$PSSessionApplicationName` preference +variable on the target computer. If this preference variable is not defined, +the default value is WSMAN. This value is appropriate for most uses. For more +information, see +[about_Preference_Variables](../../Microsoft.PowerShell.Core/About/about_Preference_Variables.md). -Certificates are used in client certificate-based authentication. -They can only be mapped to local user accounts; they do not -work with domain accounts. +The WinRM service uses the application name to select a listener to service the +connection request. The value of this parameter should match the value of the +URLPrefix property of a listener on the remote computer. -To get a certificate, use the Get-Item -(http://go.microsoft.com/fwlink/?LinkID=113319) or -Get-ChildItem (http://go.microsoft.com/fwlink/?LinkID=113308) -cmdlets in the Windows PowerShell Cert: drive. +#### PSAuthentication \ --PSComputerName -Specifies the target computers on which the activity run. -The default is the local computer. This activity common -parameter is also a workflow common parameter. +Specifies the mechanism that is used to authenticate the user's credentials +when connecting to the target computers. Valid values are Default, Basic, +Credssp, Digest, Kerberos, Negotiate, and NegotiateWithImplicitCredential. The +default value is Default. This activity common parameter is also a workflow +common parameter. -Type the NETBIOS name, IP address, or fully-qualified -domain name of one or more computers in a comma-separated -list. To specify the local computer, type the computer name, -"localhost", or a dot (.). - -To include the local computer in the value of the -PSComputerName parameter, open Windows PowerShell with -the "Run as administrator" option. - -If this parameter is omitted from the command, or it value -is $null or an empty string, the workflow target is the local -computer and Windows PowerShell remoting is not used to run -the command. - -To use an IP address in the value of the ComputerName -parameter, the command must include the PSCredential -parameter. Also, the computer must be configured for HTTPS -transport or the IP address of the remote computer must be -included in the WinRM TrustedHosts list on the local computer. -For instructions for adding a computer name to the TrustedHosts -list, see "How to Add a Computer to the Trusted Host List" in -about_Remote_Troubleshooting -(http://go.microsoft.com/fwlink/?LinkID=135188). - --PSConfigurationName -Specifies the session configurations that are used to -create sessions on the target computers. Enter the name of a -session configuration on the target computers (not on the -computer that is running the workflow. The default is -Microsoft.PowerShell. This activity common parameter -is also a workflow common parameter. +For information about the values of this parameter, see the description of the +**System.Management.Automation.Runspaces.AuthenticationMechanism** enumeration in +MSDN. + +> [!WARNING] +> Credential Security Service 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. + +#### PSCertificateThumbprint \ --PSConnectionRetryCount -Specifies the maximum number of attempts to connect to -each target computer if the first connection attempt fails. -Enter a number between 1 and 4,294,967,295 (UInt.MaxValue). -The default value, zero (0), represents no retry attempts. -This activity common parameter is also a workflow common +Specifies the digital public key certificate (X509) of a user account that has +permission to perform this action. Enter the certificate thumbprint of the +certificate. This activity common parameter is also a workflow common parameter. --PSConnectionRetryIntervalSec -Specifies the delay between connection retry attempts in -seconds. The default value is zero (0). This parameter is -valid only when the value of PSConnectionRetryCount is at -least 1. This activity common parameter is also a workflow -common parameter. +Certificates are used in client certificate-based authentication. They can only +be mapped to local user accounts; they do not work with domain accounts. + +To get a certificate, use the [Get-Item](http://go.microsoft.com/fwlink/?LinkID=113319) +or [Get-ChildItem](http://go.microsoft.com/fwlink/?LinkID=113308) +cmdlets in the Windows PowerShell Cert: drive. --PSConnectionURI -Specifies a Uniform Resource Identifier (URI) that -defines the connection endpoint for the activity on -the target computer. The URI must be fully qualified. -This activity common parameter is also a workflow common +#### PSComputerName \ + +Specifies the target computers on which the activity run. The default is the +local computer. This activity common parameter is also a workflow common +parameter. + +Type the NETBIOS name, IP address, or fully-qualified domain name of one or +more computers in a comma-separated list. To specify the local computer, type +the computer name, "localhost", or a dot (.). + +To include the local computer in the value of the PSComputerName parameter, +open Windows PowerShell with the "Run as administrator" option. + +If this parameter is omitted from the command, or it value is $null or an empty +string, the workflow target is the local computer and Windows PowerShell +remoting is not used to run the command. + +To use an IP address in the value of the ComputerName parameter, the command +must include the PSCredential parameter. Also, the computer must be configured +for HTTPS transport or the IP address of the remote computer must be included +in the WinRM TrustedHosts list on the local computer. For instructions for +adding a computer name to the TrustedHosts list, see "How to Add a Computer to +the Trusted Host List" in +[about_Remote_Troubleshooting](http://go.microsoft.com/fwlink/?LinkID=135188). + +#### PSConfigurationName \ + +Specifies the session configurations that are used to create sessions on the +target computers. Enter the name of a session configuration on the target +computers (not on the computer that is running the workflow. The default is +Microsoft.PowerShell. This activity common parameter is also a workflow common parameter. +#### PSConnectionRetryCount \ + +Specifies the maximum number of attempts to connect to each target computer if +the first connection attempt fails. Enter a number between 1 and 4,294,967,295 +(UInt.MaxValue). The default value, zero (0), represents no retry attempts. +This activity common parameter is also a workflow common parameter. + +#### PSConnectionRetryIntervalSec \ + +Specifies the delay between connection retry attempts in seconds. The default +value is zero (0). This parameter is valid only when the value of +PSConnectionRetryCount is at least 1. This activity common parameter is also a +workflow common parameter. + +#### PSConnectionURI \ + +Specifies a Uniform Resource Identifier (URI) that defines the connection +endpoint for the activity on the target computer. The URI must be fully +qualified. This activity common parameter is also a workflow common parameter. + The format of this string is as follows: +``` ://:/ +``` The default value is http://localhost:5985/WSMAN. -If you do not specify a PSConnectionURI, you can -use the PSUseSSL, PSComputerName, PSPort, and -PSApplicationName parameters to specify the PSConnectionURI -values. - -Valid values for the Transport segment of the URI -are HTTP and HTTPS. If you specify a connection URI -with a Transport segment, but do not specify a port, -the session is created with standards ports: 80 for -HTTP and 443 for HTTPS. To use the default ports for -Windows PowerShell remoting, specify port 5985 for HTTP -or 5986 for HTTPS. - --PSCredential -Specifies a user account that has permission to -run the activity on the target computer. The default -is the current user. This parameter is valid only -when the PSComputerName parameter is included in the -command. This activity common parameter is also a -workflow common parameter. +If you do not specify a PSConnectionURI, you can use the PSUseSSL, +PSComputerName, PSPort, and PSApplicationName parameters to specify the +PSConnectionURI values. -Type a user name, such as "User01" or "Domain01\User01", -or enter a variable that contains a PSCredential object, -such as one that the Get-Credential cmdlet returns. If -you enter only a user name, you will be prompted for a -password. - --PSDebug -Adds debug messages from the activity to the specified -debug record collection, instead of writing the debug -messages to the console or to the value of the Debug -property of the workflow job. You can add debug messages -from multiple activities to the same debug record collection -object. +Valid values for the Transport segment of the URI are HTTP and HTTPS. If you +specify a connection URI with a Transport segment, but do not specify a port, +the session is created with standards ports: 80 for HTTP and 443 for HTTPS. To +use the default ports for Windows PowerShell remoting, specify port 5985 for +HTTP or 5986 for HTTPS. -To use this activity common parameter, use the New-Object -cmdlet to create a PSDataCollection object with a type of -DebugRecord and save the object in a variable. Then, use the -variable as the value of the PSDebug parameter of one or -more activities, as shown in the following example. +#### PSCredential \ -workflow Test-Workflow +Specifies a user account that has permission to run the activity on the target +computer. The default is the current user. This parameter is valid only when +the PSComputerName parameter is included in the command. This activity common +parameter is also a workflow common parameter. + +Type a user name, such as "User01" or "Domain01\User01", or enter a variable +that contains a PSCredential object, such as one that the Get-Credential cmdlet +returns. If you enter only a user name, you will be prompted for a password. + +#### PSDebug \ + +Adds debug messages from the activity to the specified debug record collection, +instead of writing the debug messages to the console or to the value of the +Debug property of the workflow job. You can add debug messages from multiple +activities to the same debug record collection object. + +To use this activity common parameter, use the New-Object cmdlet to create a +PSDataCollection object with a type of DebugRecord and save the object in a +variable. Then, use the variable as the value of the PSDebug parameter of one +or more activities, as shown in the following example. + +```powershell +Workflow Test-Workflow { -$debugCollection = New-Object -Type System.Management.Automation.PSDataCollection[System.Management.Automation.DebugRecord] -InlineScript {\Server01\Share01\Get-AssetData.ps1} -PSDebug $debugCollection -Debug $True -InlineScript {\Server01\Share01\Set-AssetData.ps1} -PSDebug $debugCollection -Debug $True -if ($debugCollection -like "Missing") { ...} + $debugCollection = New-Object -Type ` + System.Management.Automation.PSDataCollection[System.Management.Automation.DebugRecord] + InlineScript {\Server01\Share01\Get-AssetData.ps1} -PSDebug $debugCollection -Debug $True + InlineScript {\Server01\Share01\Set-AssetData.ps1} -PSDebug $debugCollection -Debug $True + if ($debugCollection -like "Missing") { ...} } +``` + +#### PSDisableSerialization \ --PSDisableSerialization -Directs the activity to return "live" (not serialized) -objects to the workflow. The resulting objects have -methods, as well as properties, but they cannot be +Directs the activity to return "live" (not serialized) objects to the workflow. +The resulting objects have methods, as well as properties, but they cannot be saved when a checkpoint is taken. --PSDisableSerializationPreference -Applies the equivalent of the PSDisableSerialization -parameter to the entire workflow, not just the activity. -Adding this parameter is generally not recommended, because -a workflow that doesn’t serialize its objects cannot be resumed -or persisted. +#### PSDisableSerializationPreference \ + +Applies the equivalent of the PSDisableSerialization parameter to the entire +workflow, not just the activity. Adding this parameter is generally not +recommended, because a workflow that doesn’t serialize its objects cannot be +resumed or persisted. Valid values: --- (Default) If omitted, and you have also not added the -PSDisableSerialization parameter to an activity, -objects are serialized. - --- $True. Directs all activities within a workflow to return -"live" (not serialized) objects. The resulting objects have -methods, as well as properties, but they cannot be saved -when a checkpoint is taken. - --- $False. Workflow objects are serialized. - --PSError -Adds error messages from the activity to the specified error -record collection, instead of writing the error messages to -the console or to the value of the Error property of the -workflow job. You can add error messages from multiple + +- (Default) If omitted, and you have also not added the + PSDisableSerialization parameter to an activity, objects are serialized. + +- `$True`. Directs all activities within a workflow to return + "live" (not serialized) objects. The resulting objects have methods, as well + as properties, but they cannot be saved when a checkpoint is taken. +- `$False`. Workflow objects are serialized. + +#### PSError \ + +Adds error messages from the activity to the specified error record collection, +instead of writing the error messages to the console or to the value of the +Error property of the workflow job. You can add error messages from multiple activities to the same error record collection object. -To use this activity common parameter, use the New-Object -cmdlet to create a PSDataCollection object with a type -of ErrorRecord and save the object in a variable. Then, -use the variable as the value of the PSError parameter -of one or more activities, as shown in the following example. +To use this activity common parameter, use the `New-Object` cmdlet to create a +PSDataCollection object with a type of ErrorRecord and save the object in a +variable. Then, use the variable as the value of the PSError parameter of one +or more activities, as shown in the following example. -workflow Test-Workflow +```powershell +Workflow Test-Workflow { -$errorCollection = New-Object -Type System.Management.Automation.PSDataCollection[System.Management.Automation.ErrorRecord] -InlineScript {\Server01\Share01\Get-AssetData.ps1} -PSError $errorCollection -InlineScript {\Server01\Share01\Set-AssetData.ps1} -PSError $errorCollection -if ($errorCollection.Count -gt 2) { ...} + $typeName = "System.Management.Automation.PSDataCollection" + $typeName += '[System.Management.Automation.ErrorRecord]' + $ec = New-Object $typeName + InlineScript {\Server01\Share01\Get-AssetData.ps1} -PSError $ec + InlineScript {\Server01\Share01\Set-AssetData.ps1} -PSError $ec + if ($ec.Count -gt 2) + { + # Do Some Work. + } } +``` --PSPersist -Takes a checkpoint after the activity. This checkpoint -is in addition to any checkpoints that are specified in -the workflow. This activity common parameter is also a -workflow common parameter. +#### PSPersist \ + +Takes a checkpoint after the activity. This checkpoint is in addition to any +checkpoints that are specified in the workflow. This activity common parameter +is also a workflow common parameter. -A "checkpoint" or "persistence point" is a snapshot of the -workflow state and data that is captured while the workflow -runs and is saved to a persistence store on disk. Windows -PowerShell Workflow uses the saved data to resume a suspended -or interrupted workflow from the last persistence point, -rather than to restart the workflow. +A "checkpoint" or "persistence point" is a snapshot of the workflow state and +data that is captured while the workflow runs and is saved to a persistence +store on disk. Windows PowerShell Workflow uses the saved data to resume a +suspended or interrupted workflow from the last persistence point, rather than +to restart the workflow. Valid values: --- (Default) If you omit this parameter, no checkpoints are -added. Checkpoints are taken based on the settings for the -workflow. +- (Default) If you omit this parameter, no checkpoints are + added. Checkpoints are taken based on the settings for the workflow. --- $True. Takes a checkpoint after the activity completes. -This checkpoint is in addition to any checkpoints that -are specified in the workflow. +- `$True`. Takes a checkpoint after the activity completes. + This checkpoint is in addition to any checkpoints that are specified in + the workflow. --- $False. No checkpoints are added. Checkpoints are taken -only when specified in the workflow. +- `$False`. No checkpoints are added. Checkpoints are taken only when + specified in the workflow. --PSPort -Specifies the network port on the target computers. -The default ports are 5985 (the WinRM port for HTTP) -and 5986 (the WinRM port for HTTPS). This activity +#### PSPort \ + +Specifies the network port on the target computers. The default ports are 5985 +(the WinRM port for HTTP) and 5986 (the WinRM port for HTTPS). This activity common parameter is also a workflow common parameter. -Do not use the PSPort parameter unless you must. The -port set in the command applies to all computers or -sessions on which the command runs. An alternate port -setting might prevent the command from running on all -computers. Before using an alternate port, you must -configure the WinRM listener on the remote computer -to listen at that port. - --PSProgress -Adds progress messages from the activity to the -specified progress record collection, instead of -writing the progress messages to the console or -to the value of the Progress property of the -workflow job. You can add progress messages -from multiple activities to the same progress -record collection object. - --PSProgressMessage -Specifies a friendly description of the activity. -The PSProgressMessage value appears in the progress -bar while the workflow runs. When the DisplayName is -also included in the command, the progress bar content -appears in : format. - -This parameter is particularly useful for identifying -activities in a ForEach -Parallel script block. Without -this message, activities in all parallel branches are -identified by the same name. - --PSRemotingBehavior -Specifies how remoting is managed when the activity is -run on target computers. PowerShell is the default. +Do not use the PSPort parameter unless you must. The port set in the command +applies to all computers or sessions on which the command runs. An alternate +port setting might prevent the command from running on all computers. Before +using an alternate port, you must configure the WinRM listener on the remote +computer to listen at that port. + +#### PSProgress \ + +Adds progress messages from the activity to the specified progress record +collection, instead of writing the progress messages to the console or to the +value of the Progress property of the workflow job. You can add progress +messages from multiple activities to the same progress record collection +object. + +#### PSProgressMessage \ + +Specifies a friendly description of the activity. The PSProgressMessage value +appears in the progress bar while the workflow runs. When the DisplayName is +also included in the command, the progress bar content appears in +\:\ format. + +This parameter is particularly useful for identifying activities in a ForEach +-Parallel script block. Without this message, activities in all parallel +branches are identified by the same name. + +#### PSRemotingBehavior \ + +Specifies how remoting is managed when the activity is run on target computers. +PowerShell is the default. Valid values are: -None: The activity is not run on remote computers. - -PowerShell: Windows PowerShell remoting is used to -run the activity on target computers. - -Custom: The activity supports its own type of remoting. -This value is valid when the cmdlet that is being -implemented as an activity sets the value of the -RemotingCapability attribute to SupportedByCommand and -the command includes the ComputerName parameter. - --PSRequiredModules -Imports the specified modules before running the command. -Enter the module names. The modules must be installed on -the target computer. - -Modules that are installed in a path specified in the -PSModulePath environment variable are automatically -imported on first use of any command in the module. Use -this parameter to import modules that are not in a -PSModulePath location. - -Because each activity in a workflow runs in its own -session, an Import-Module command imports a module only -into the session in which it runs. It does not import the -module into sessions in which other activities run. - --PSSessionOption -Sets advanced options for the sessions to the -target computers. Enter a PSSessionOption object, -such as one that you create by using the New-PSSessionOption -cmdlet. This activity common parameter is also a workflow +- None: The activity is not run on remote computers. + +- PowerShell: Windows PowerShell remoting is used to run the activity on + target computers. + +- Custom: The activity supports its own type of remoting. This value is valid + when the cmdlet that is being implemented as an activity sets the value of + the RemotingCapability attribute to SupportedByCommand and the command + includes the ComputerName parameter. + +#### PSRequiredModules \ + +Imports the specified modules before running the command. Enter the module +names. The modules must be installed on the target computer. + +Modules that are installed in a path specified in the PSModulePath environment +variable are automatically imported on first use of any command in the module. +Use this parameter to import modules that are not in a PSModulePath location. + +Because each activity in a workflow runs in its own session, an Import-Module +command imports a module only into the session in which it runs. It does not +import the module into sessions in which other activities run. + +#### PSSessionOption \ + +Sets advanced options for the sessions to the target computers. Enter a +PSSessionOption object, such as one that you create by using the +New-PSSessionOption cmdlet. This activity common parameter is also a workflow common parameter. -The default values for the session options are -determined by the value of the $PSSessionOption -preference variable, if it is set. Otherwise, the -session uses the values specified in the session -configuration. - -For a description of the session options, including -the default values, see the help topic for the -New-PSSessionOption cmdlet -(http://go.microsoft.com/fwlink/?LinkID=144305). - -For more information about the $PSSessionOption -preference variable, see [about_Preference_Variables](../../Microsoft.PowerShell.Core/About/about_Preference_Variables.md). - --PSUseSSL -A value of $True uses the Secure Sockets Layer (SSL) -protocol to establish a connection to the target -computer. By default, SSL is not used. A value of $False -has no effect. This activity common parameter is also -a workflow common parameter. - -WS-Management encrypts all Windows PowerShell -content transmitted over the network. UseSSL is -an additional protection that sends the data across -an HTTPS, instead of HTTP. If you use this parameter, -but SSL is not available on the port used for the -command, the command fails. - --PSVerbose -Adds verbose messages from the activity to the -specified verbose record collection, instead of -writing the verbose messages to the console or -to the value of the Verbose property of the workflow -job. You can add verbose messages from multiple -activities to the same verbose record collection -object. +The default values for the session options are determined by the value of the +`$PSSessionOption` preference variable, if it is set. Otherwise, the session +uses the values specified in the session configuration. + +For a description of the session options, including the default values, see the +help topic for the New-PSSessionOption cmdlet +[New-PSSessionOption](http://go.microsoft.com/fwlink/?LinkID=144305). + +For more information about the $PSSessionOption preference variable, see +[about_Preference_Variables](../../Microsoft.PowerShell.Core/About/about_Preference_Variables.md). --PSWarning -Adds warning messages from the activity to the -specified warning record collection, instead of -writing the warning messages to the console or -to the value of the Warning property of the -workflow job. You can add warning messages from -multiple activities to the same warning record -collection object. +#### PSUseSSL \ + +A value of $True uses the Secure Sockets Layer (SSL) protocol to establish a +connection to the target computer. By default, SSL is not used. A value of +$False has no effect. This activity common parameter is also a workflow common +parameter. + +WS-Management encrypts all Windows PowerShell content transmitted over the +network. UseSSL is an additional protection that sends the data across an +HTTPS, instead of HTTP. If you use this parameter, but SSL is not available on +the port used for the command, the command fails. + +#### PSVerbose \ + +Adds verbose messages from the activity to the specified verbose record +collection, instead of writing the verbose messages to the console or to the +value of the Verbose property of the workflow job. You can add verbose messages +from multiple activities to the same verbose record collection object. + +#### PSWarning \ + +Adds warning messages from the activity to the specified warning record +collection, instead of writing the warning messages to the console or to the +value of the Warning property of the workflow job. You can add warning messages +from multiple activities to the same warning record collection object. + +#### Result --Result This parameter is valid only in XAML workflows. --UseDefaultInput -Accepts all workflow input as input to the -activity by value. +#### UseDefaultInput \ + +Accepts all workflow input as input to the activity by value. -For example, the Get-Process activity in the -following sample workflow uses the UseDefaultInput -activity common parameter to get input that is -passed to the workflow. When you run the workflow -with input, that input is used by the activity. +For example, the Get-Process activity in the following sample workflow uses the +UseDefaultInput activity common parameter to get input that is passed to the +workflow. When you run the workflow with input, that input is used by the +activity. +```powershell workflow Test-Workflow { -Get-Service -UseDefaultInput $True + Get-Service -UseDefaultInput $True } PS C:> Test-Workflow -InputObject WinRm +``` -Status Name DisplayName PSComputerName ------- ---- ----------- -------------- -Running winrm Windows Remote Management (WS-Manag... localhost - --Verbose -Displays detailed information about the -operation performed by the command. This -information resembles the information in a -trace or in a transaction log. The Verbose -parameter overrides the value of the -$VerbosePreference variable for the current -command. This parameter works only when the -command generates a verbose message. This -parameter is also a Windows PowerShell common -parameter. +```output +Status Name DisplayName PSComputerName +------ ---- ----------- -------------- +Running winrm Windows Remote Management (WS-Manag... localhost +``` + +#### Verbose \ --WarningAction -Determines how the activity responds to a warning. -"Continue" is the default value. The WarningAction -parameter overrides the value of the $WarningPreference -variable for the current command. This parameter works -only when the command generates a warning message. This -parameter is also a Windows PowerShell common parameter. +Displays detailed information about the operation performed by the command. +This information resembles the information in a trace or in a transaction log. +The Verbose parameter overrides the value of the $VerbosePreference variable +for the current command. This parameter works only when the command generates a +verbose message. This parameter is also a Windows PowerShell common parameter. + +#### WarningAction \ + +Determines how the activity responds to a warning. "Continue" is the default +value. The WarningAction parameter overrides the value of the +$WarningPreference variable for the current command. This parameter works only +when the command generates a warning message. This parameter is also a Windows +PowerShell common parameter. Valid Values: -SilentlyContinue. Suppresses the warning message -and continues executing the command. +- SilentlyContinue. Suppresses the warning message and continues executing the + command. -Continue. Displays the warning message and continues -executing the command. "Continue" is the default -value. +- Continue. Displays the warning message and continues executing the command. + "Continue" is the default value. -Inquire. Displays the warning message and prompts -you for confirmation before continuing execution. -This value is rarely used. +- Inquire. Displays the warning message and prompts you for confirmation before + continuing execution. This value is rarely used. -Stop. Displays the warning message and stops -executing the command. +- Stop. Displays the warning message and stops executing the command. -NOTE: The WarningAction parameter does not override -the value of the $WarningAction preference variable -when the parameter is used in a command to run a -script or function. +> [!NOTE] +> The WarningAction parameter does not override +> the value of the $WarningAction preference variable +> when the parameter is used in a command to run a +> script or function. -# EXAMPLES +### EXAMPLES -The activity common parameters are extremely useful. -For example, you can use the PSComputerName parameter -to run particular activities on only a subset of the -target computers. +The activity common parameters are extremely useful. For example, you can use +the PSComputerName parameter to run particular activities on only a subset of +the target computers. -Or, you might use the PSConnectionRetryCount and -PSConnectionRetryIntervalSec parameters to adjust the -retry values for particular activities. +Or, you might use the PSConnectionRetryCount and PSConnectionRetryIntervalSec +parameters to adjust the retry values for particular activities. -The following example shows how to use the PSComputerName -activity common parameters to run a Get-EventLog activity -only on computers it a particular domain. +The following example shows how to use the PSComputerName activity common +parameters to run a Get-EventLog activity only on computers it a particular +domain. +```powershell Workflow Test-Workflow { -$UserDomain = Get-Content -Path .\UserComputers.txt -$Log = (Get-EventLog -LogName "Windows PowerShell" -PSComputerName $UserDomain} -if ($Log) ... + $UserDomain = Get-Content -Path '.\UserComputers.txt' + $Log = (Get-EventLog -LogName "Windows PowerShell" ` + -PSComputerName $UserDomain) + + if ($Log) + { + # Do Work Here. + } } +``` + - +[about_Activity_Parameters](about_Activity_Parameters.md) +[about_ActivityParameters]()about_ActivityParameters.md) --> -# SEE ALSO +## SEE ALSO [about_Workflows](about_workflows.md) [about_WorkflowCommonParameters](about_WorkflowCommonParameters.md) \ No newline at end of file