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
Solved

schedule powershell script

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

792 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