13Dec Exchange 2007 - Some Useful Shell Commands
Exchange 2007 is pretty damn cool! This article is just a list of some very useful commands I’ve come across during my time installing and administering Exchange 2007.
You WILL have to change the properties of the commands below as they won’t work as shown until you replace the email addresses and domain names with ones that you control or own.
Verify Installation
Get-ExchangeServer
License Exchange 2007
set-exchangeserver -Identity ‘CN=xxx,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=xxx,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=xxx,DC=local’ -ProductKey ‘xxxxx’
Move Private Storage Group Path (First Storage Group)
move-StorageGroupPath -Identity ‘xxx\First Storage Group’ -LogFolderPath ‘D:\Exchange\Mailbox\First Storage Group’ -SystemFolderPath ‘D:\Exchange\Mailbox\First Storage Group’
Move Private Database Path (in First Storage Group)
move-DatabasePath -Identity ‘xxx\First Storage Group\Mailbox Database’ -EdbFilePath ‘D:\Exchange\Mailbox\First Storage Group\Database\Mailbox Database.edb’
Move Public Storage Group Path (Second Storage Group)
move-StorageGroupPath -Identity ‘xxx\Second Storage Group’ -LogFolderPath ‘D:\Exchange\Mailbox\Second Storage Group’ -SystemFolderPath ‘D:\Exchange\Mailbox\Second Storage Group’
Move Public Database Path (in Second Storage Group)
move-DatabasePath -Identity ‘xxx\Second Storage Group\Public Folder Database’ -EdbFilePath ‘D:\Exchange\Mailbox\Second Storage Group\Database\Public Folder Database.edb’
Important note:
Create Team Storage Group
new-StorageGroup -Server ‘xxx’ -Name ‘Team Storage Group’ -LogFolderPath ‘D:\Exchange\Mailbox\Team Storage Group’ -SystemFolderPath ‘D:\Exchange\Mailbox\Team Storage Group’
Create and Mount Team Storage Group Database
new-mailboxdatabase -StorageGroup ‘CN=Team Storage Group,CN=InformationStore,CN=xxx,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=xxx,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=xxx,DC=local’ -Name ‘Team Mailbox Database’ -EdbFilePath ‘D:\Exchange\Mailbox\Team Storage Group\Database\Team Mailbox Database.edb’
then
mount-database -Identity ‘CN=Team Mailbox Database,CN=Team Storage Group,CN=InformationStore,CN=xxx,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=xxx,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=xxx,DC=local’
Enable LCR for ‘Team Storage Group’ and ‘Team Storage Group Database’
enable-DatabaseCopy -Identity ‘xxx\Team Storage Group\Team Mailbox Database’ -CopyEdbFilePath ‘D:\Exchange LCR\Mailbox\Team Storage Group\Database\Team Mailbox Database.edb’
then
enable-StorageGroupCopy -Identity ‘CN=Team Storage Group,CN=InformationStore,CN=xxx,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=xxx,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=xxx,DC=local’ -CopyLogFolderPath ‘D:\Exchange LCR\Mailbox\Team Storage Group’ -CopySystemFolderPath ‘D:\Exchange LCR\Mailbox\Team Storage Group’
Configure Accepted Domains
new-AcceptedDomain -Name ‘xxx.com’ -DomainName ‘xxx.com’ -DomainType ‘Authoritative’
Create Postmaster Mailbox
Get-TransportServer
then
Set-TransportServer xxx.xxx.local -ExternalPostmasterAddress postmaster@xxx.com
Testing Mailflow
test-mailflow
and/or
test-mailflow -Identity xxx.xxx.local -DomainController xxx.xxx.local
Check Journaling Agent Status
Get-TransportAgent
Enable Journaling Agent
Enable-TransportAgent - Identity “Journaling Agent”
Create Journaling Rule for Internal Email
new-journalRule -Name ‘xxx - Journal All Internal Email’ -JournalEmailAddress ‘xxx.local/Domain Users/xxx’ -Scope ‘Internal’ -Enabled $true
Create Journaling Rule for External Email
new-journalRule -Name ‘xxx - Journal All External Email’ -JournalEmailAddress ‘xxx.local/Domain Users/xxx’ -Scope ‘External’ -Enabled $true
Enable mailbox for existing user
Enable-Mailbox -Identity ‘xxx.local/Domain Users/Test and Training Accounts/Exchange 2007′ -Alias ‘ex2007′ -Database ‘CN=Mailbox Database,CN=First Storage Group,CN=InformationStore,CN=xxx,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=xxx,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=xxx,DC=local’
Create Transport Rule (BE CAREFUL WITH THESE!)
new-TransportRule -Name ‘xxx - Append Disclaimer for user ”Exchange 2007”’ -Comments ” -Conditions ‘Microsoft.Exchange.MessagingPolicies.Rules.Tasks.FromPredicate’ -Actions ‘Microsoft.Exchange.MessagingPolicies.Rules.Tasks.ApplyDisclaimerAction’ -Exceptions ‘Microsoft.Exchange.MessagingPolicies.Rules.Tasks.SentToScopePredicate’ -Enabled $true -Priority ‘0′
Enable IMAP4
Set-service msExchangeIMAP4 -startuptype automatic
then
Start-service msExchangeIMAP4
Configure IMAP4
Set-ImapSettings -UnencryptedOrTLSBindings:0.0.0.0:143 -LoginType:PlainTextLogin
then
Restart-Service MsExchangeIMAP4
Move Single Mailbox Example
Get-Recipient | where {$_.Name -Eq “John Doe”} | Move-Mailbox -TargetDatabase “xxx.xxx.local\Team Mailbox Database”
Enable ‘Out Of Office” For Specific User (default is on for everyone)
Set-Mailbox “John Doe” -ExternalOofOptions External
Add SMTP Connector for anonymous sender through specific IP Range
New-ReceiveConnector -Name “Allow xxx.xxx.local Relay” -Usage Custom -PermissionGroups AnonymousUsers -Bindings 192.168.1.11:25 -RemoteIpRanges 192.168.1.0/24
Get-ReceiveConnector “Allow xxx.xxx.local Relay” | Add-ADPermission -User “NT AUTHORITY\ANONYMOUS LOGON” -ExtendedRights “Ms-Exch-SMTP-Accept-Any-Recipient”
Note the | symbol in the above command as it concatenates 2 commands together!
Set-AddressList
The default filter was…
Set-AddressList “All Rooms” -RecipientFilter { (Alias -ne $null -and (RecipientDisplayType -eq ‘ConferenceRoomMailbox’ -or RecipientDisplayType -eq ‘SyncedConferenceRoomMailbox’)) }
The following command changes the filter so that the “All Rooms” address list is populated with any ad object with a “DisplayName” of “Resource”…
Set-AddressList “All Rooms” -RecipientFilter { (Alias -ne $null -and (RecipientDisplayType -eq ‘ConferenceRoomMailbox’ -or RecipientDisplayType -eq ‘SyncedConferenceRoomMailbox’ -or DisplayName -like ‘Resource*’)) }
Change the type of mailbox for resources like meeting rooms/projectors/etc
set-mailbox “resource Chicago meeting room” -type room
Valid types are…
* Regular
* Room
* Equipment
* Shared
Add a group to have full access to a mailbox
Add-MailboxPermission “Agents” -User “Agents” -AccessRights FullAccess
Formatting Results Without Truncation
The example command below will get all permissions on the “xxx.local\xxx” mailbox and format them without truncation so all information is visible. The default is to truncate the results which makes them quite hard to see.
e.g. Get-MailboxPermission -Identity “xxx.local\xxx” | Format-List
Get All Mailbox Database Sizes - To Screen
Get-MailboxDatabase | foreach {get-childitem $_.edbFilePath | select-object name,length}
Get All Mailbox Sizes - Export to CSV
Get-MailboxDatabase | foreach {get-childitem $_.edbFilePath | select-object name,length} | export-csv c:\mailbox.database.sizes.csv | foreach {$_.length=($_.length)/1024/1024/1024; $_}
Create New Distribution Lists
New-DistributionGroup -Type Distribution -SamAccountName “Notifications” -Name “Notifications” -OrganizationalUnit “Distribution Lists”
New-DistributionGroup -Type Distribution -SamAccountName “Managers” -Name “Managers” -OrganizationalUnit “Distribution Lists”
Configure New Distribution Lists
You need to run the below command against your new group or you won’t be able to send to the group from anything but Outlook …
Set-DistributionGroup -Identity “Managers” -EmailAddressPolicyEnabled:$false -RequireSenderAuthenticationEnabled:$false
Add Members to Distribution Lists
Add-DistributionGroupMember -Identity “Managers” -Member “xxx.local\xxx”
Add-DistributionGroupMember -Identity “Notifications” -Member “Testers”
Show List of all Regular User Mailboxes
Get-Recipient -RecipientType UserMailbox
Show List of all “Shared Mailbox” Mailboxes
Get-Recipient -RecipientTypeDetails SharedMailbox
Change All “Shared Mailbox” Mailboxes to “User Mailbox” Mailboxes
Get-Recipient -RecipientTypeDetails SharedMailbox | Set-Mailbox -Type Regular
Move Offline Address Books (the example site below has 2)
move-OfflineAddressBook -Identity ‘067a3661-ef79-4859-bd17-e147e4a84cba’ -Server ‘xxx’
move-OfflineAddressBook -Identity ‘4954e53d-a7c1-452f-9fb4-2dae279bf1f5′ -Server ‘xxx’
Get Origin Server for All Public Folders
Get-PublicFolder -Recurse | Format-Table Name, OriginatingServer
Create Send Connector
This command enables a specific server to send email directly to the internet via a non-Exchange SMTP gateway. Remember to disable any other send connectors that relay to the internet for servers that you are going to decommission.
New-SendConnector -Name “Internal xxx.xxx.local > Internet Send Connector” -AddressSpaces “*” -SmartHosts 10.10.11.10,10.10.111.10 -SmartHostAuthMechanism None -SourceTransportServers “xxx.xxx.local” -DNSRoutingEnabled $false
Create Email Address Policy
Note that the example below is a test example and will only apply to people in the “Testing” department under Organization in ADUAC. It will set the email address of each affected user to be “firstname@xxx.com” - it will NOT confirm this action!
New-EmailAddressPolicy -Name “xxx Email Address Policy” -EnabledPrimarySMTPAddressTemplate “%g@xxx.com” -DomainController xxx.xxx.local -IncludedRecipients MailboxUsers -ConditionalDepartment “Testing” -Confirm:$False
Add Public Folder Permissions
Be careful with the “Owner” permission - read the Microsoft Technet document about “Add-PublicFolderClientPermission” to see what the valid options for ‘-AccessRights’ are.
Add-PublicFolderClientPermission -Identity “\xxx” -User “xxx.local\xxx” -AccessRights “Owner” -Confirm:$False
Create & Configure Public Folder
Add-PublicFolder -Name “xxx” -Path “\”
then
Enable-MailPublicFolder -Identity “\xxx”
then
Set-MailPublicFolder -Identity “\xxx” -PrimarySMTPAddress xxx@xxx.com -WindowsEmailAddress xxx@xxx.com -RequireSenderAuthenticationEnabled:$False -Alias “xxx” -DisplayName “xxx” -EmailAddressPolicyEnabled:$False -PublicFolderType MAPI -Server xxx.xxx.local -DomainController xxx.xxx.local
Create External Contact
New-MailContact -Alias JDoe -Name “John Doe” -FirstName “John” -LastName “Doe” -org “External Contacts” -ExternalEmailAddress john.doe@xxx.com
Set-MailContact -Identity “John Doe” -EmailAddressPolicyEnabled:$False -ExternalEmailAddress john.doe@xxx.com -PrimarySmtpAddress john.doe@xxx.com -WindowsEmailAddress john.doe@xxx.com -DomainController xxx.xxx.local
Forward All User’s Email To Contact (Use With Creating A Contact)
Set-Mailbox -Identity “xxx.local\xxx” -DeliverToMailboxAndForward:$True -ForwardingAddress john.doe@xxx.com


February 25th, 2008 at 21:26
Can anybody show me how to add or delete a emailaddress in VB.NET code, the powershell sample does it like that:
$Mailbox = Get-Mailbox “Kim Akers”
$Mailbox.EmailAddresses += “kim@contoso.com”
Set-Mailbox “Kim Akers” -EmailAddresses $Mailbox.EmailAddresses
How is this done in VB.NET?
Thanks,
Thorir