Solved

problems starting a .PS1 script via windows 2008 task scheduler

Posted on 2011-03-11
6
752 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
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…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now