I am attempting to write a powershell script that schedules another powershell script. Here is the code that I currently have:
$Action = New-ScheduledTaskAction -Execute 'pwsh.exe' -Argument '-NonInteractive -NoLogo -NoProfile -File "C:\test.ps1"'
$Trigger = New-ScheduledTaskTrigger -Daily -At 6pm
$Settings = New-ScheduledTaskSettingsSet
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
Register-ScheduledTask -TaskName "Test" -InputObject $Task
This creates the task that I want, but when it is triggered, it fails, and claims that the file was not found. I would also like for it to prompt the user for the administrators password, but I could not figure that out in the documentation. I settled for non interactive, but that isn't really what I want. Thanks in advance for any help.
Edit: the error code is 0x80070002
User contributions licensed under CC BY-SA 3.0