Solved

schedule powershell script

Posted on 2011-03-08
4
636 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
  • 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

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

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

25 Experts available now in Live!

Get 1:1 Help Now