Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I'm not a coder but trying to help my development team by taking on simple tasks myself, one of which is to set up a Windows scheduled task to export components of our mongodb through Powershell. With help from http://docs.mongodb.org/manual/administration/import-export/ and some trial and error (as well as a bit of troubleshooting help from dev friends), I've been able to write some Powershell command lines that successfully export the relevant Mongodb collections when manually executed within Powershell:

cd c:\mongobinlocation

.\mongoexport --db db --collection collection1 --jsonArray --out "\\server\archivelocation\collection1.json"

.\mongoexport --db db --collection collection2 --jsonArray --out "\\server\archivelocation\collection2.json"

.\mongoexport --db db --collection collection3 --jsonArray --out "\\server\archivelocation\collection3.json"

However, I then set upon trying to set up a scheduled task to run the script in Powershell (using instructions here: http://www.ilovepowershell.com/how-to-run-powershell-script-as-scheduled-task/) and realized that the Powershell command lines that I have set up do not equate to a Powershell script that can be run in a scheduled task. I'm looking for a basic template example that I could modify to insert my command lines above and I've had no luck- everything I see looks drastically different than my little ol' command lines. Is there any way to wrap the above commands into something basic or do I have to start from scratch and learn how to write a Powershell script?

Thanks for any and all help, and I appreciate your time!

share|improve this question
    
What you've written would be fine in a .bat file - there don't appear to be any PowerShell commands in there. You can just save your file as a .bat, then create a scheduled task to run it - no template required! –  Simon MᶜKenzie Mar 21 '13 at 5:14
    
Thanks so much, Simon- this was exactly what I needed to know. I did exactly as you directed and it appears to be working perfectly. Thanks again! –  LuckyBuckeye Mar 21 '13 at 6:41

1 Answer 1

I have not worked with Scheduled tasks at all. I need to learn them. Since I know nothing about scheduling tasks I put my scheduling in my PowerShell scripts.

While($true){ #Easily replaced by a for-loop
    ... #your script
    Start-Sleep (60*60*24)
    #I prefer to use "timeout /t <seconds>"
}

If you throw this on a server that doesn't get restarted you have a easy scheduled task. If you're really looking to learn check out Workflows with PowerShell.

share|improve this answer
    
Thanks, Bob. I'll go with the .bat file proposed by Simon above, but I appreciate your comment and will keep it in mind in the future- I am indeed looking to increase my knowledge level and I'm sure this will be handy in the future. Thanks again! –  LuckyBuckeye Mar 21 '13 at 6:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.