I'm running into a roadblock trying to narrow down the cause of a powershell exception.
- Server is being deployed with a Server 2012 clone with standardized machine and admin name which is then changed after the first boot.
- 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.
- ScheduledTask is registered properly and contains the right administrative credentials.
- ScheduledTask correctly runs the PowerShell script(s) and the intended work and results are successful.
- Problem: There is always a ScheduledJobException until the system is rdp-ed into at least once again with the administrative credentials.
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.
$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.