Solved

schedule powershell script

Posted on 2011-03-08
4
649 Views
Last Modified: 2012-08-13
I am very new to powershell.  I was given the below command to export any mail that has specific keywords in it.  It works great, but I need it to run a lot of different searches, and wanted to script it so that I didn't have to babysit it.  How do i script it when it asks for a folder to put the messages in?  It also asks to confirm for all mailboxes.  I would also like to schedule this to run in the evening, so any help with scheduling it would be great, but I am guessing that I can figure that part out.

Get-mailboxdatabase –identity special | get-mailbox | export-mailbox –subjectkeywords “search” –targetmailbox mailbox
0
Comment
Question by:norwoodhelpdesk
[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
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:KenMcF
ID: 35070352
You can add -targetfolder to your script

And to schedule you can save this a .PS1 file and add this line

add-pssnapin *EX*
Get-mailboxdatabase –identity special | get-mailbox | export-mailbox –subjectkeywords “search” –targetmailbox mailbox -targetfolder c:\mailboxes

Then create a schedule task. it should be like this if your .PS1 file is named exportmailbox.ps1

powershell.exe c:\exportmailbox.ps1



0
 

Author Comment

by:norwoodhelpdesk
ID: 35070704
Thanks, i will try it out.  I do have a few more questions.

It also prompts for confirmation, and I choose A for all.  Will this still need me to enter that?

also, what is the C:\mailboxes for?  I don't want it in a PST, I just want it in a mailbox that is on the server.

0
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
ID: 35070810
Sorry, I had the syntax wrong. The target folder should be the folder in the mailbox not on the lcoal drive. So change that to the folder in your destination mailbox.

You can add -confirm:$False to that so it will not prompt.
0
 

Author Comment

by:norwoodhelpdesk
ID: 35070972
Worked great.  Thanks so much.
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

729 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