Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Cannot resume PowerShell Workflow (Job) after System Startup using Task Scheduler

$
0
0
Hello PowerShell gurus, I have a question that has kept me up the last two nights trying to find a solution. I hope someone can assist or provide some guidance. Thanks in advance for your assistance.

Description of Problem: Unable to resume a job (PowerShell Job) that is in a Suspended state using Task Scheduler(this job is running a PowerShell workflow). The Schedule Task runs successfully(I receive a message The operation completes successfully) and the PowerShell script executes to completion without any errors (from what I can see) but the job will not change state from Suspended to Resume. fyi: if I run the powershell script that the Task Scheduler executes from the POSH console using local administrator account (POSH console running in Admin Mode), the script runs successfully (ie, resumes the job) but that same script will not resume the job when running as a Schedule Task

Desired Behavior: Resume the PowerShell Job that is currently suspended by using Task Scheduler to execute a Powershell script at System Startup.

Troubleshooting:
Here are some things I've tried:
- the powershell script that the Schedule Task calls to resume the job, I inserted a "create directory" command in the script just so I can verify the script is being called and that works fine (ie, schedule task runs on time and creates a directory so I know the schedule task is actually executing the script)
- ran the script from the POSH admin console and it runs fine (the script resumes the job)
- i put a start/stop transcript in the script to capture any commands/output and added a "Get-Job" command (so I can see the suspended job). The transcript did not capture any Suspended Jobs. The Get-Job command runs successfully but transcript didn't pick up any jobs being suspended (nothing was captured in the transcript). I'm concerned that the PowerShell shell doesn't have visibility to the jobs on the system or simply the transcript isn't picking up Get-Job output
- I tried to hard code the Job name in the script (Resume-Job -name JobName) and my transcript log file reports that the Job isn't found even though I verified the job exists and currently is suspended.
- I tried running the task immediately from the Task Scheduler GUI and the message from Task Scheduler is the operations completed successfully but the job does not resume.


Details:
* new virtual machine (Windows 2012 R2) in Azure
* machine not on the domain (machine was newly created)

Down below is the schedule task information & powershell script
schedule task information (I built it with powershell)
 $resumeActionscript = '-WindowStyle Normal -NoLogo -NoProfile -File "C:\temp\resume-job.ps1"'
 $action = New-ScheduledTaskAction -Execute "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument $resumeActionscript
 $user = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest -LogonType ServiceAccount
 $trigger = New-ScheduledTaskTrigger -AtStartup -RandomDelay 00:00:15
 $settings = New-ScheduledTaskSettingsSet
 $InputObj = New-ScheduledTask -Action $action -Principal $user -Trigger $trigger -Settings $settings
 Register-ScheduledTask ChangeSwapDiskTask -InputObject $InputObj
resume-job.ps1
start-transcript c:\temp\mylogfile.txt
get-job
write-output "get-job command executed"
resume-job -name TempStorageMove
stop-transcript

Viewing all articles
Browse latest Browse all 6937

Trending Articles