PowerShell Workflow: Restarting a suspended workflow started from a scheduled task.

So I have a series of PowerShell workflows that do controlled patching using SCCM.

If I start the patching workflow using a scheduled task when it suspends at a checkpoint I'm looking at being able to resume it again but the job is not viewable to resume.

Having read http://blogs.msdn.com/b/powershell/archive/2013/12/23/automatically-resuming-windows-powershell-workflow-jobs-at-logon.aspx and trying to meet requirements there.

Below is an example of sequential patching workflow where server 1 is patched, then suspended and an email is sent to say resume the workflow to patch the second server (it's just an example of suspending and resuming workflow).

I've made the scheduled job interactive and run with highest privileges, opening the console as admin and same username as the task is run.

PS C:\Windows\system32> get-job

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
11     PatchSequent... PSScheduledJob  Completed     True            localhost            Import-module iiSCOMTo...


PS C:\Windows\system32> get-job | receive-job
8/09/2015 11:14:39 AM isp-dev-patch1: Did not snapshot as requested
8/09/2015 11:14:39 AM isp-dev-patch1: Starting maint mode
8/09/2015 11:15:06 AM isp-dev-patch1 Putting into Maint mode has succeeded
8/09/2015 11:15:06 AM isp-dev-patch1: Starting Patching
8/09/2015 11:15:07 AM isp-dev-patch1: Scanning and installing patches
8/09/2015 11:17:09 AM isp-dev-patch1: Monitoring patching
8/09/2015 11:18:11 AM isp-dev-patch1: Finished patching
8/09/2015 11:18:41 AM isp-dev-patch1: Patching is complete.

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
1      Job1            PSWorkflowJob   Suspended     True            localhost            Invoke-iiPatchSequenti...


PS C:\Windows\system32> ipmo PSWorkflow
PS C:\Windows\system32> get-job

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
11     PatchSequent... PSScheduledJob  Completed     False           localhost            Import-module iiSCOMTo...


PS C:\Windows\system32>

I cannot actually find the suspended workflow from a console, same username, same server, elevated or not elevated.

Starting the same task from console, works fine as I guess it satisfies all the requirements to find the suspended workflow.

So question is how do people reliably find and resume a suspended workflow that is started from a scheduled task? The future would be to build an SMA and WAP environment.

September 8th, 2015 12:01am

Looks like I worked this out.


Create the scheduled task with run with highest privileges and create a loop back workflow session on the server and run the command as a job, Scheduled task 'action':

PowerShell.exe -WindowStyle Normal -NoLogo -NoProfile -Command "$ws = New-PSWorkflowSession -EnableNetworkAccess; Invoke-Command -Session $ws {PowerShellWorkFlowCommand -asjob}"


I need -EnableNetAccess as the workflow is patching remote computers.

Once the scheduled task is run, on the same server with the same creds and an elevated PowerShell console session (IE as administrator):

$ws = New-PSWorkflowSession -EnableNetworkAccess

Invoke-Command -Session $ws { get-job }

Invoke-Command -Session $ws { get-job | Resume-Job}

Etc.


Free Windows Admin Tool Kit Click here and download it now
September 12th, 2015 6:44am

Looks like I worked this out.


Create the scheduled task with run with highest privileges and create a loop back workflow session on the server and run the command as a job, Scheduled task 'action':

PowerShell.exe -WindowStyle Normal -NoLogo -NoProfile -Command "$ws = New-PSWorkflowSession -EnableNetworkAccess; Invoke-Command -Session $ws {PowerShellWorkFlowCommand -asjob}"


I need -EnableNetAccess as the workflow is patching remote computers.

Once the scheduled task is run, on the same server with the same creds and an elevated PowerShell console session (IE as administrator):

$ws = New-PSWorkflowSession -EnableNetworkAccess

Invoke-Command -Session $ws { get-job }

Invoke-Command -Session $ws { get-job | Resume-Job}

Etc.


September 12th, 2015 6:45am

Looks like I worked this out.


Create the scheduled task with run with highest privileges and create a loop back workflow session on the server and run the command as a job, Scheduled task 'action':

PowerShell.exe -WindowStyle Normal -NoLogo -NoProfile -Command "$ws = New-PSWorkflowSession -EnableNetworkAccess; Invoke-Command -Session $ws {PowerShellWorkFlowCommand -asjob}"


I need -EnableNetAccess as the workflow is patching remote computers.

Once the scheduled task is run, on the same server with the same creds and an elevated PowerShell console session (IE as administrator):

$ws = New-PSWorkflowSession -EnableNetworkAccess

Invoke-Command -Session $ws { get-job }

Invoke-Command -Session $ws { get-job | Resume-Job}

Etc.


Free Windows Admin Tool Kit Click here and download it now
September 12th, 2015 10:42am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics