PowerShell Script Running successfully in ISE but Failing as a Scheduled Task

Maranya, Damon 326 Reputation points
2023-01-10T21:25:26.453+00:00

I am working on a script that takes a list of DIDs/GUIDIds from a locally stored file generated by another script. It then removes the listed devices from Active Directory. But it won't run as a scheduled task.

The Last Run Result status is 0x1. Which as far as I can tell is a vague catchall value meaning "I can't". There is nothing in the History tab at all.

I am logged in with the account that will be used to run task in the Task Scheduler. I've already delegated delete device permissions to the account that will run the script, and it currently completes without error when I run it manually in ISE. During the manual runs I am using the -whatif parameter, so that I don't lose the devices that the first script found. But that shouldn't affect the result when running it without the parameter in a scheduled task.

The Task Scheduler logs show task started>action started>action completed> task completed. The PowerShell logs show PowerShell Console Startup>PowerShell Named Pipe IPC>PowerShell Console Startup. There are no events after PowerShell Console Startup.

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 36,291 Reputation points
    2023-01-10T23:36:14.543+00:00

    Add a transcript to the script so that you can see the errors that Powershell generates.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-5.1

    Start-Transcript -path C:\Logs\MyScriptLog.txt
    
    .... the rest of your script
    
    
    Stop-Transcript 
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.