Exchange Management shell Command - Piping Output

Hi All,

I currently have the following command set up as an argument used in a Scheduled Task:

-version 2.0 -ExecutionPolicy ByPass -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; get-mailbox | Set-MailboxJunkEmailConfiguration -TrustedSendersAndDomains @{Add='computer.com','test.com'}"

This command applies to all mailboxes on our estate.  Is there a way to pipe out the settings of each mailbox using the get-mailboxjunkemailconfiguration after each mailbox is configured with the above addresses?  I would like to update the existing argument and not create a separate script to manage this, if possible.

Thanks in advance.
khanfeAsked:
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.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Of course, just append the new command after a semicolon (for clarity I have inserted line breaks, but you need to remove those if running as shortcut or scheduled task):
-version 2.0 -ExecutionPolicy ByPass -command "
. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1';
Connect-ExchangeServer -auto; 
get-mailbox | Set-MailboxJunkEmailConfiguration -TrustedSendersAndDomains @{Add='computer.com','test.com'}; 
get-mailbox | Get-MailboxJunkEmailConfiguration | export-csv -NoType 'c:\temp\JunkConfig.csv';
"

Open in new window

With this size of the command string it is probably a better idea to store it in a PS1 script instead ...

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
khanfeAuthor Commented:
That works - thanks for your help!
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
Shell Scripting

From novice to tech pro — start learning today.