Friday, September 25, 2015

windows - Powershell script won't launch in task scheduler when running as my admin user


I have a task setup:



  • Run whether logged in or not

  • Run with highest privs

  • When running the task use the following account (my admin account)


Program / Script: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
Arguments: -ExecutionPolicy Bypass C:\Temp\test.ps1


test.ps1 contains:


Write-Host "Hello"

If I run this script as my normal user without run as highest privs, powershell launches and it works as expected.


When using the above settings though, it shows as running, then shows as completed with a result of 0x0 but powershell doesn't launch.


Any ideas what I'm doing wrong?


Note: I've tried setting the Start In to C:\Temp, I've tried various other arguments like noprofile nologo etc.


Answer



PowerShell is running in a different user-context since you run this task as a different user than you're currently logged in. That's why you don't see any PowerShell window.


To make sure that your script really runs, try creating a txt file in your script. if it gets created, your script runs.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...