Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

problems starting a .PS1 script via windows 2008 task scheduler

Posted on 2011-03-11
6
Medium Priority
?
772 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 2000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
New style of hardware planning for Microsoft Exchange server.
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…
how to add IIS SMTP to handle application/Scanner relays into office 365.
Suggested Courses

705 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