2

I've have created a Powershell script that automatically connects to office 365 and sets all users default calendar permissions to reviewer. this script runs perfectly when executed manually.

but

I am trying to launch the powershell script via task scheduler on WS-2012-R2.

i run the task but when i check a test users calendar permissions its still the same "contributor".

When task scheduler starts the task, it creates a process, that process is given a process ID.

i went to check the ID in task manager it showed as "Pick an App" under the processes tab.

i right clicked and clicked details and it shows as OpenWith.exe

i checked file association and (.PS1) is associated to WindowsPowershell

i went to the scripts file location in explorer, Rclicked and changed the OPenWith from POwershell to Windows Powershell ISE and i still get the same thing when i run through task sheduler. ("pick and app & OPenWith.exe")

i have tried editing the "actions" in Task Manager to a combination of things such as.

In task shceduler properties

Program/script: was set to: C:\Powershell script\default reviewer permissions this doesnt work

then i changed that to C:\Windows\System32\WindowsPowerShell\v1.0\POwershell and also PowerShell_ise

with C:\Powershell script\default reviewer permissions in the "add arguments (optional) section.

and visa versa

Can anyone please tell me what i can do to make this script run.

Many thanks

5
  • What happens when you launch powershell from a command-line like:powershell -? as this should show the syntax needed? You should be using something like: PowerShell -File "D:\WORK\ps\webtest.ps1" for your tasks. Commented Sep 17, 2015 at 15:10
  • When i run "Powershell -?" i get syntax suggestions. in "actions" Tab i changed the Program/Script to PowerShell and in the add arguments field i entered -File "C:\Powershell script\Default Reviewer permissions.ps1" and it worked. many thanks for your help Commented Sep 18, 2015 at 7:45
  • Can you add "comment has something useful" to this? Or, I can check with the Moderator to see if I can break out my comment as an answer. I think I may have made the mistake as adding as a comment. I will check with the Moderator either way.. I don't think this will be the last time we will see this issue. :) Commented Sep 18, 2015 at 17:02
  • "comment has something useful" Commented Sep 19, 2015 at 19:01
  • Thanks Daniel.. There is a actually a "scoring" to the left of comments or better yet, if you look a the answer I provided maybe more in line. I apologize for originally not being clear. Commented Sep 19, 2015 at 22:45

1 Answer 1

2

What happens when you launch PowerShell from a command-line (CMD and not a PowerShell Session) like:

powershell -?

as this should show the syntax needed?

For example, mine shows (Removing the extra help information):

PowerShell [-File ]

Specifically:

-File Execute a script file.

You should be using something like in your Scheduled Task (note: the use of quotes as well):

PowerShell -File "D:\WORK\ps\webtest.ps1"

Hope this helps!

Sign up to request clarification or add additional context in comments.

1 Comment

This helped me trying to run a script via Task Scheduler, the issue was I was simply pointing to the script, hence 'OpenWith.exe' was showing up. Broadly speaking I changed it to CMD "Script" and that got it, it is now running a command prompt that can run the script (i.e. knows what to open the script with)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.