A few days ago, we posted blog Exchange Server 2007 recipient management one-liners covering common recipient management scenarios in Exchange Server 2007 using Exchange Management Console ("console"), and the one-liners behind the scenes - single-line commands in Exchange Management Shell ("shell" or "EMS based on Windows PowerShell") executed to achieve the thing. Now the console exposes one-liners for each wizard after successful completion. Here's some more one-liners:
Distribution Group
There are several distribution group types including: MailEnabledUniversalSecurityGroup: Universal Security Group that can receive mail MailEnabledUniversalDistributionGroup: Universal Distribution Group that can receive mail MailEnabledNonUniversalGroup: Domain Local or Global, Security or Global, Distribution Group that can receive mail, which are created in Exchange 2000/2003. It is recommended to convert any groups of this type to Universal groups to prevent member expansion problems in multi-domain environments. MailEnabledDynamicDistributionGroup: Query-Based Distribution Group that can receive mail The section below lists common scenarios for distribution group management. Those scenarios similar to Mailbox management are not repeated here. Scenario: Create a new distribution group Administrators can create a new distribution group by creating a new group and mail-enabling it, or mail-enable an existing group. The steps for creating a new distribution group using the "New Distribution Group" wizard are similar to the steps creating a new mailbox using the "New Mailbox" wizard. Shell one-liner: # Create a new distribution group and mail-enable itnew-DistributionGroup -alias testdg -name "Test Distribution Group" -type <distribution | security> -org Users -SamAccountName Testers# Mail-enable an existing universal groupenable-DistributionGroup testuniversalgroup -alias enableddg Scenario: Create a new dynamic distribution group Creating a new dynamic distribution group using the "New Dynamic Distribution Group" wizard follows the similar steps creating a new distribution group. Shell one-liner: # Create a new dynamic distribution group using the “custom” RecipientFilter parameter (rather than precanned filter syntax).new-DynamicDistributionGroup -alias testddg -name TestDDG -recipientfilter {Company -eq "example"} -org Users Change Management Scenario: Add members to a distribution group Shell one-liner: add-DistributionGroupMember testdg -Member jaredz Scenario: Set OOF and delivery report option for groups Shell one-liner: set-DistributionGroup testdg -ReportToOriginatorEnabled:$True -SendOofMessageToOriginatorEnabled:$True Bulk Management Scenario: Create a distribution group and add mailboxes specified by a CSV file to the distribution group Shell one-liner: Below one-liner creates a distribution group for all team members based on Avalanche.csv file, which contains NHL Avalanche team roster information including the below columns: Pos,No,Player,Age,Ht,Wt,Born,Exp,Birth City new-distributiongroup -alias avalanche -name "Avalanche Team" -type distribution -org users -SamAccountName AvalancheTeamimport-csv Avalanche.csv | foreach {add-distributiongroupmember avalanche -member "avalanche$($_.No)"} Scenario: Create a dynamic distribution group for players in the "center" position based on a CSV file Shell one-liner: # Avalanche.csv file has below columns: # Pos,No,Player,Age,Ht,Wt,Born,Exp,Birth Cityimport-csv Avalanche.csv | foreach {set-user "avalanche$($_.No)" -Department $_.Pos}new-DynamicDistributionGroup -alias avalanche_centers -name avalanche_centers -recipientfilter {Company -eq "avalanche" -and Department -eq "centers"} -org Users Scenario: Set storage quotas for all members in a distribution group Shell one-liner: Get-DistributionGroup testdg | Get-DistributionGroupMember | Set-Mailbox -UseDatabaseQuotaDefaults:$False -IssueWarningQuota 90MB -ProhibitSendQuota 95MB -ProhibitSendReceiveQuota 100MB
There are several distribution group types including:
The section below lists common scenarios for distribution group management. Those scenarios similar to Mailbox management are not repeated here.
Scenario: Create a new distribution group
Administrators can create a new distribution group by creating a new group and mail-enabling it, or mail-enable an existing group. The steps for creating a new distribution group using the "New Distribution Group" wizard are similar to the steps creating a new mailbox using the "New Mailbox" wizard.
Shell one-liner:
# Create a new distribution group and mail-enable itnew-DistributionGroup -alias testdg -name "Test Distribution Group" -type <distribution | security> -org Users -SamAccountName Testers# Mail-enable an existing universal groupenable-DistributionGroup testuniversalgroup -alias enableddg
Scenario: Create a new dynamic distribution group
Creating a new dynamic distribution group using the "New Dynamic Distribution Group" wizard follows the similar steps creating a new distribution group.
# Create a new dynamic distribution group using the “custom” RecipientFilter parameter (rather than precanned filter syntax).new-DynamicDistributionGroup -alias testddg -name TestDDG -recipientfilter {Company -eq "example"} -org Users
Change Management
Scenario: Add members to a distribution group
add-DistributionGroupMember testdg -Member jaredz
Scenario: Set OOF and delivery report option for groups
set-DistributionGroup testdg -ReportToOriginatorEnabled:$True -SendOofMessageToOriginatorEnabled:$True
Bulk Management
Scenario: Create a distribution group and add mailboxes specified by a CSV file to the distribution group
Below one-liner creates a distribution group for all team members based on Avalanche.csv file, which contains NHL Avalanche team roster information including the below columns: Pos,No,Player,Age,Ht,Wt,Born,Exp,Birth City
new-distributiongroup -alias avalanche -name "Avalanche Team" -type distribution -org users -SamAccountName AvalancheTeamimport-csv Avalanche.csv | foreach {add-distributiongroupmember avalanche -member "avalanche$($_.No)"}
Scenario: Create a dynamic distribution group for players in the "center" position based on a CSV file
# Avalanche.csv file has below columns: # Pos,No,Player,Age,Ht,Wt,Born,Exp,Birth Cityimport-csv Avalanche.csv | foreach {set-user "avalanche$($_.No)" -Department $_.Pos}new-DynamicDistributionGroup -alias avalanche_centers -name avalanche_centers -recipientfilter {Company -eq "avalanche" -and Department -eq "centers"} -org Users
Scenario: Set storage quotas for all members in a distribution group
Get-DistributionGroup testdg | Get-DistributionGroupMember | Set-Mailbox -UseDatabaseQuotaDefaults:$False -IssueWarningQuota 90MB -ProhibitSendQuota 95MB -ProhibitSendReceiveQuota 100MB
Mail Contact
There are several mail contact types including MailEnabledContact and MailEnabledUser. Both can be managed through the GUI console or through the shell. The section below lists common scenarios for mail-enabled contact management. Those scenarios similar to Mailbox management are not repeated here. Scenario: Create a new mail contact Administrators can create a new mail contact by creating a new contact and mail-enabling it, or by mail-enabling an existing contact. The steps creating a new mail contact using the "New Mail Contact" wizard are similar to the steps creating a new mailbox using the "New Mailbox" wizard. Shell one-liner: # Create a new mail contactnew-MailContact -alias testmc -name TestMailContact -org Users -ExternalEmailAddress textmc@example.com# Mail-enable an existing contactenable-Mailcontact testcontact -alias enabledmc -ExternalEmailAddress enabledmc@example.com# Create a new mail usernew-MailUser -alias testmc -name TestMailContact -org Users -ExternalEmailAddress textmc@example.com# Mail-enable an existing userenable-MailUser testcontact -alias enabledmc -ExternalEmailAddress enabledmc@example.com Bulk Management Scenario: Bulk create MailContacts based on a CSV file Shell one-liner: # contacts.csv is a sample csv file containing below columns:# name,company,department,displayName,targetAddress,mailNicknameimport-csv contacts.csv | foreach { new-mailcontact -alias $_.mailnickname -name $_.displayName -ExternalEmailAddress $_.targetaddress -org Users }
There are several mail contact types including MailEnabledContact and MailEnabledUser. Both can be managed through the GUI console or through the shell. The section below lists common scenarios for mail-enabled contact management. Those scenarios similar to Mailbox management are not repeated here.
Scenario: Create a new mail contact
Administrators can create a new mail contact by creating a new contact and mail-enabling it, or by mail-enabling an existing contact. The steps creating a new mail contact using the "New Mail Contact" wizard are similar to the steps creating a new mailbox using the "New Mailbox" wizard.
# Create a new mail contactnew-MailContact -alias testmc -name TestMailContact -org Users -ExternalEmailAddress textmc@example.com# Mail-enable an existing contactenable-Mailcontact testcontact -alias enabledmc -ExternalEmailAddress enabledmc@example.com# Create a new mail usernew-MailUser -alias testmc -name TestMailContact -org Users -ExternalEmailAddress textmc@example.com# Mail-enable an existing userenable-MailUser testcontact -alias enabledmc -ExternalEmailAddress enabledmc@example.com
Scenario: Bulk create MailContacts based on a CSV file
# contacts.csv is a sample csv file containing below columns:# name,company,department,displayName,targetAddress,mailNicknameimport-csv contacts.csv | foreach { new-mailcontact -alias $_.mailnickname -name $_.displayName -ExternalEmailAddress $_.targetaddress -org Users }
Disconnected Mailbox
Scenario: Find disconnected mailboxes on a mailbox database Disconnected mailboxes are displayed under the Disconnected Mailbox node in the console. Shell one-liner: Get-MailboxStatistics -Database "Mailbox Database" | where { $_.DisconnectDate -ne $null } Scenario: Recover disconnected mailboxes Disconnected mailboxes are displayed under the Disconnected Mailbox node in the console. Right clicking the context menu "Connect..." will launch the "Connect Mailbox" wizard to walk through the steps of connecting a mailbox. Shell one-liner: # Connect all disconnected mailboxes stored in the specified mailbox database.Get-MailboxStatistics | where {$_.DisconnectDate -ne $null} | Connect-Mailbox -Database "Mailbox Database"
Scenario: Find disconnected mailboxes on a mailbox database
Disconnected mailboxes are displayed under the Disconnected Mailbox node in the console.
Get-MailboxStatistics -Database "Mailbox Database" | where { $_.DisconnectDate -ne $null }
Scenario: Recover disconnected mailboxes
Disconnected mailboxes are displayed under the Disconnected Mailbox node in the console. Right clicking the context menu "Connect..." will launch the "Connect Mailbox" wizard to walk through the steps of connecting a mailbox.
# Connect all disconnected mailboxes stored in the specified mailbox database.Get-MailboxStatistics | where {$_.DisconnectDate -ne $null} | Connect-Mailbox -Database "Mailbox Database"
- Jared (Ji-Chao) Zhang