Combining PowerShell Commands
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
July 15th, 2012 12:05pm

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
Free Windows Admin Tool Kit Click here and download it now
July 16th, 2012 4:21am

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
July 16th, 2012 4:21am

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
Free Windows Admin Tool Kit Click here and download it now
July 16th, 2012 4:58am

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
July 16th, 2012 4:58am

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
Free Windows Admin Tool Kit Click here and download it now
July 16th, 2012 11:28am

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
July 17th, 2012 10:00pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics