Solved

problems starting a .PS1 script via windows 2008 task scheduler

Posted on 2011-03-11
6
759 Views
Last Modified: 2012-05-11
good day, i am trying to launch an Exchange 2010 powershell script:
.ps1 script looks like this:
get-mailboxdatabase "Mailbox Database Prod-DB01" | get-mailbox | add-mailboxpermission -user Joe_Smith -accessrights fullaccess -inheritancetype all

this runs fine if i run it from the server. c:\scripts\setrights.ps1
however it will not run in task manager?

please advise.. thx
0
Comment
Question by:siber1
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:LLMorrisson
ID: 35112754
You need to change the execution policy on the server.

set-executionpolicy RemoteSigned

Open in new window


Then once you have created your ps1 script, make a stub cmd or bat file and put this in it;

powershell -command "& '<pathandnameofscript>.ps1' "

Open in new window


Then schedule the cmd or bat file in task scheduler.
0
 

Author Comment

by:siber1
ID: 35112786
I get the following error when i try to run that .bat file as you suggested:

the term 'get-mailboxdatabase' is not recognized....
0
 

Author Comment

by:siber1
ID: 35112850
Since this is an exchange 2010 command, it will only run under the Exchange mgnt shell [ESM] interface. how can i specify this in the .bat file?

0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 5

Expert Comment

by:LLMorrisson
ID: 35112895
Ah yes, You need to include the EMS as part of the call also.

PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\V14\Bin\ExShell.Psc1" -Command ". '<pathandnameofscript.ps1'"

Open in new window

0
 
LVL 5

Accepted Solution

by:
LLMorrisson earned 500 total points
ID: 35112912
Sorry that got a bit messed up;

PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\V14\Bin\ExShell.Psc1" -Command "<pathandnameofscript.ps1>"
0
 

Author Comment

by:siber1
ID: 35112923
excellent. worked perfect. thx LL
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
Read this checklist to learn more about the 15 things you should never include in an email signature.
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question