Solved

problems starting a .PS1 script via windows 2008 task scheduler

Posted on 2011-03-11
6
764 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

734 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