none
Combining PowerShell Commands RRS feed

  • Question

  • Trying to combine several PowerShell commands to set the archive database, retention policy and OWA mailbox policy. Can I use something like this or do I need to separate these commands somehow?

    Import-csv E:\users.csv | Foreach {Enable-Mailbox -Identity $_.Logon -ArchiveDatabase $_.ARDB Set-CasMailbox -OwaMailbox Policy $_.OwaPolicy Set-Mailbox -RetentionPolicy $_.RetentionPolicy}


    MCITP Exchange 2010 | MCTS Exchange 2007 | MCITP Lync Server 2010 | MCTS Windows 2008 | MCSE 2003

    Sunday, July 15, 2012 4:05 PM

Answers

  • Hi

    You can't do that but you can execute each command on a new line as part of the same foreach loop:

    $Users = Import-csv E:\users.csv 
    Foreach ($Line in $Users) 
    {
    Enable-Mailbox -Identity $Line.Logon -ArchiveDatabase $Line.ARDB 
    Set-CasMailbox -OwaMailbox Policy $Line.OwaPolicy 
    Set-Mailbox -RetentionPolicy $Line.RetentionPolicy
    }

    Save those lines as a .PS1 and run in the EMS.

    Cheers, Steve

    Monday, July 16, 2012 8:21 AM
  • Hi

    You command is almost correct, just add a pipe line

    Import-csv E:\users.csv | Foreach {Enable-Mailbox -Identity $_.Logon -ArchiveDatabase $_.ARDB | Set-CasMailbox -OwaMailbox Policy $_.OwaPolicy | Set-Mailbox -RetentionPolicy $_.RetentionPolicy}

    Cheers

    Zi Feng

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Zi Feng

    TechNet Community Support

    Monday, July 16, 2012 8:58 AM
    Moderator

All replies

  • Hi

    You can't do that but you can execute each command on a new line as part of the same foreach loop:

    $Users = Import-csv E:\users.csv 
    Foreach ($Line in $Users) 
    {
    Enable-Mailbox -Identity $Line.Logon -ArchiveDatabase $Line.ARDB 
    Set-CasMailbox -OwaMailbox Policy $Line.OwaPolicy 
    Set-Mailbox -RetentionPolicy $Line.RetentionPolicy
    }

    Save those lines as a .PS1 and run in the EMS.

    Cheers, Steve

    Monday, July 16, 2012 8:21 AM
  • Hi

    You command is almost correct, just add a pipe line

    Import-csv E:\users.csv | Foreach {Enable-Mailbox -Identity $_.Logon -ArchiveDatabase $_.ARDB | Set-CasMailbox -OwaMailbox Policy $_.OwaPolicy | Set-Mailbox -RetentionPolicy $_.RetentionPolicy}

    Cheers

    Zi Feng

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Zi Feng

    TechNet Community Support

    Monday, July 16, 2012 8:58 AM
    Moderator
  • Thanks. We just used separate lines, but I can see using the other ones in the future as we move more mailboxes.

    MCITP Exchange 2010 | MCTS Exchange 2007 | MCITP Lync Server 2010 | MCTS Windows 2008 | MCSE 2003

    Monday, July 16, 2012 3:28 PM
  • Hi Vegas

    If the issue is solved, please Mark As Answer and finish this thread

    Cheers

    Zi Feng

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contacttnmff@microsoft.com.


    Zi Feng

    TechNet Community Support

    Wednesday, July 18, 2012 2:00 AM
    Moderator