Schedule script for all mailbox

I have merged safe sender list (test.com) of outlook 2010 for all users using the following power shell command from ExchangeManagementShell:
get-Mailbox -ResultSize Unlimited| Set-MailboxJunkEmailConfiguration -TrustedSendersAndDomains @{Add='address@whitelist.com','test.com'}, and which successfully merged safe sender list of all users adding the domain test.com in outlook safe sender list. Since new hires will be joining for that I intend to run the command as a script daily schedule basis from exchange server, and intend to keep command output in a seperate log file. Appreciate if you please assist to know the followings:
1. How to run the power shell command as a daily schedule basis from exchange server as a script
2. How to keep the script output in a seperate log file to monitor the same.

Appreciate any available link/steps to perform the same with details.
ipsec600Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
What you need to do is put your command in a txt file and re-name the extension to .ps1. From there create a scheduled task on the server and point to the .ps1 file you created. You can setup the interval on how often you want the script to run.

To create a log file for this just add the following to your script...

get-Mailbox -ResultSize Unlimited| Set-MailboxJunkEmailConfiguration -TrustedSendersAndDomains @{Add='address@whitelist.com','test.com'} | select DisplayName, PrimarySMTPAddress | Out-file "c:\test.log -append"

Open in new window



Will.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ipsec600Author Commented:
Hi Will,
Thanks a lot for replying, its just great!!!
i) When I run the powershell command from EMS then it is ok,  and creating the test.log file but nothing is coming in the log file.
ii) when I run (.ps1) from exchange servers schedule task, it is being completed successfully but test.log is not generated.
iii) Now when I am going to run the command as a batch file from another server 2008, but batch file is not running, i followed the below article, is it possible to assist.

http://www.mikepfeiffer.net/2010/02/creating-scheduled-tasks-for-exchange-2010-powershell-scripts/

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command “$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exmbx01.test.com.local/PowerShell/ -Authentication Kerberos ; Import-PSSession $s ; get-Mailbox -ResultSize Unlimited| Set-MailboxJunkEmailConfiguration -TrustedSendersAndDomains @{Add='address@whitelist.com','test.com'} | select DisplayName, PrimarySMTPAddress | Out-file "c:\test.log -append"
0
Will SzymkowskiSenior Solution ArchitectCommented:
Try changing the test.log to test.txt and see if that works.
0
ipsec600Author Commented:
Hi Will,
I tried changing the test.log to test.txt but still nothing is coming in the file, which is blank, can you advise please.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.