Solved

problems starting a .PS1 script via windows 2008 task scheduler

Posted on 2011-03-11
6
747 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

OfficeMate Freezes on login or does not load after login credentials are input.
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

708 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

12 Experts available now in Live!

Get 1:1 Help Now