Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm running into a roadblock trying to narrow down the cause of a powershell exception.


  1. Server is being deployed with a Server 2012 clone with standardized machine and admin name which is then changed after the first boot.
  2. After the Machine and Admin name are changed, then a PowerShell script runs manually to created a ScheduledTask which is then supposed to run the same script every half hour.


  1. ScheduledTask is registered properly and contains the right administrative credentials.
  2. ScheduledTask correctly runs the PowerShell script(s) and the intended work and results are successful.
  3. Problem: There is always a ScheduledJobException until the system is rdp-ed into at least once again with the administrative credentials.

Exception copy:

Type: Microsoft.PowerShell.ScheduledJob.ScheduledJobException 
Description: StackTrace: at Create-ScheduledJob, C:\PowerShellScriptTaskName.ps1: line 31 at Check-ScheduledJob, C:\PowerShellScriptTaskName.ps1: line 69 at , : line 365 
Error: Exception: An error occurred while registering scheduled job definition PowerShellScriptTaskName to the Windows Task Scheduler. The Task Scheduler error is: Could not load file or assembly 'Microsoft.PowerShell.ScheduledJob' or one of its dependencies. The system cannot find the file specified.. 

Line 69 is the script calling a custom function which contains Line 31.
Lines 29-31:

$JobOptions = New-ScheduledJobOption
$DailyTrigger = New-JobTrigger -Once -At (get-date) -RepetitionInterval (New-TimeSpan -Minutes 30) -RepetitionDuration ([timeSpan]::maxvalue)
Register-ScheduledJob -Name PowerShellScriptTaskName -FilePath c:\PowerShellScriptTaskName.ps1 -ScheduledJobOption $JobOptions -Trigger $DailyTrigger

I am looking for any thoughts as to why the Exceptions would still be popping up and anything I might look at to help avoid them during the initial deployment.
It's confusing to me since the Task still runs the Script and the Script still executes successfully, and it appears the error is usually resolved by logging into the cloned machine with the administration credentials a 2nd or 3rd time after deployment.

share|improve this question
Additional troubleshooting resulted in seeing the error disappear when the desktop session was logged in and active, even if the rdp session was closed. I found the failures reappear when I logged out of the session...even though the script still ran per the scheduled job/task. –  Flint Weather Aug 13 '14 at 16:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.