Closed adstep closed 2 months ago
Working on a fix, seems a parameter was not renamed correctly.
Should be fixed in #38 Merging now, and publishing new release. Can you please confirm that this fixed the issue for you?
3.1.6 is now in PSGallery
Seeing an error now:
PS C:\windows\system32> Invoke-CommandAs -ScriptBlock { whoami } -AsUser $cred
Invoke-ScheduledTask : An error occurred while registering scheduled job definition
e60d4e36-5ace-49e7-a6b0-144db629961d to the Windows Task Scheduler. The Task Scheduler error is: (32,4):UserId:.
At C:\Program Files\WindowsPowerShell\Modules\Invoke-CommandAs\3.1.6\public\Invoke-CommandAs.ps1:399 char:17
+ Invoke-ScheduledTask @Parameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-ScheduledTask
Does the user have access to running scheduled tasks? create one manually in Task Schedule, and confirm please.
Yes, the user has permissions on the box. They are an Administrator. I was able to create a task.
Thanks for testing. Will investigate more tonight and get back to you.
It looks like this stack overflow post is talking about a similar issue to what I'm seeing. Doesn't look like they reach a resolution :(
Hey Marc, I was recently came back to the issue and was able to figure out what was going wrong with my use case. Apparently you can't create a schedule job if you are running as system. Our workaround has been to create a temporary user to register the job and then clean it up afterwards. I've created a PR to apply the workaround (#46.)
PR has been closed
Running as system administrator, impersonating a user doesn't work. I expect whoami to return 'MyUser'.