Exchange Management shell Command - Piping Output

khanfe
khanfe used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
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 ...

Author

Commented:
That works - thanks for your help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial