MS Exchange

Contents

Purge Exchange log files (after successful backup fails to purge)

#Note: takes some time for the space to free up. Also note: add all volumes with logs on them.
diskshadow
add volume e:
add volume c:
begin backup
create
end backup
exit

Export a user’s contact photo

export-RecipientDataProperty -identity jsmith -picture | ForEach { $_.FileData | Add-Content C:\temp\jsmith.jpg -Encoding byte}

Show disabled users that aren’t hidden in the GAL

Get-Mailbox -Filter{(HiddenFromAddressListsEnabled -eq $false) -AND (UserAccountControl -eq “AccountDisabled, NormalAccount”)}

Show all users in the GAL

Get-Mailbox | Where {$_.HiddenFromAddressListsEnabled -eq $false} | select name, alias

Import Exchange Module (2010)

add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010

Set calendar sharing details

set-MailboxCalendarFolder -Identity jsmith:\Calendar -PublishEnabled $true
set-MailboxCalendarFolder -Identity jsmith:\Calendar -DetailLevel reviewer
#Enable visibility of calendar items/sharing
#Note that limiteddetails will show the subject, but you can’t see anything else.
set-MailboxFolderPermission jsmith:\Calendar -User Default -AccessRights reviewer -verbose

Assign full access permissions to a mailbox

Gives Jane access to John’s mailbox

get-mailbox -identity john.smith | add-MailboxPermission -AccessRights Fullaccess -user jane.smith
#OR
Add-MailboxPermission -Identity “john smith” -User "jane smith" -AccessRights FullAccess -InheritanceType All

Show the DAG status

(Get-DatabaseAvailabilityGroup) | ForEach {$_.Servers | ForEach {Get-MailboxDatabaseCopyStatus -Server $_}}
Get-MailboxDatabase -Status | Format-List name,server,mounted

Heath Check

Test-ServiceHealth
Test-ReplicationHealth

Modify distribution group/list (DL)

get-DistributionGroupMember "All Staff"
get-DistributionGroupMember “All Staff” | select primarysmtpaddress
Add-DistributionGroupMember "Simpson Family" -Member "maggie.simpson@interslicer.com"
Remove-DistributionGroupMember "Simpson Family" -Member “Bart Simpson”

Export Global Address List (GAL)

get-mailbox -resultsize unlimited | ?{$_.HiddenFromAddressListsEnabled -eq $false} | get-user | select DisplayName,Phone,WindowsEmailAddress | Sort-Object displayname

Set calendar sharing details

set-MailboxCalendarFolder -Identity jsmith:\Calendar -PublishEnabled $true
set-MailboxCalendarFolder -Identity jsmith:\Calendar -DetailLevel reviewer
#Enable visibility of calendar items/sharing
#Note that limiteddetails will show the subject, but you can’t see anything else.
set-MailboxFolderPermission jsmith:\Calendar -User Default -AccessRights reviewer -verbose
Get-MailboxDatabase -Status | Format-List name,server,mounted

Test IMAP on a server

# Test the server on port 143 (TLS) - ensure it connects
telnet server 443
# Test the server on port 993 (SSL) - ensure it connects
telnet server 993
# (Exchange Admin Console) IMAP.Proxy should show online:
Get-ServerHealth server | ?{$_.HealthSetname -like "IMAP*"}
# (Exchange Admin Console) IF IMAP.Proxy is offline, bring it online
Set-ServerComponentState -Identity server -Component IMAPProxy -State Active -Requester HealthAPI
# Need to restart IMAP services on the server for changes to take effect
restart-service MSExchangeImap4
restart-service MSExchangeIMAP4BE
# IMAP should now work

Calendar Sharing Policy

Get-SharingPolicy | fl
Set-SharingPolicy -Identity "Default Sharing Policy" -Domains 'intelematics.com: CalendarSharingFreeBusyReviewer'

 

Import/Export calendar/mailbox

# Exporting

New-MailboxExportRequest -Mailbox "<MailboxName>" -FilePath \\ServerName\ShareName\NewFileName.pst -IncludeFolders "#Calendar#"

# Importing
New-MailboxImportRequest -Mailbox "MailboxName" -FilePath \\<ServerName>\<ShareName>\<NewFileName>.pst -IncludeFolders "#Calendar#"
# Correcting permissions to auto-allow more that Free/Busy:
Set-MailboxFolderPermission John.Smith:\Calendar" -User Default -AccessRights Reviewer

Update the GAL/Address Book

Get-GlobalAddressList | update-GlobalAddressList
Get-AddressList | update-AddressList
Get-OfflineAddressBook | Update-OfflineAddressBook

Exchange 2010 Prerequisites

Import-Module ServerManager
Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Web-ISAPI-Ext,Web-Digest-Auth,Web-Dyn-Compression,NET-HTTP-Activation,RPC-Over-HTTP-Proxy -Restart
Set-Service NetTcpPortSharing -StartupType Automatic

Enable mailbox user “test”

Enable-Mailbox -Identity test

Search a mailbox for an email

# Search john's mailbox for emails with a specific subject and from Tim, then send the results to a folder called TEST in my mailbox (after having my name legally changed to Jane Smith)
Search-Mailbox -Identity john.smith -SearchQuery {Subject:"RE: Your lack of performance lately" AND From:"john.smith"} -TargetMailbox "jane smith" -TargetFolder "TEST" -LogLevel Full

# within a certain date range - send all results to jane's inbox in a folder called "Search Results"
Get-Mailbox john.smith –ResultSize Unlimited | Search-Mailbox -TargetMailbox "jane smith" -TargetFolder “Search Results” -SearchQuery {Received:01/11/2016 10:00..30/12/2016 13:00} –SearchDumpster

Show mailbox size

Get-Mailbox -identity John.Walker | Get-MailboxStatistics | Select TotalItemSize

Show top 30 largest mailboxes by size

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,TotalItemSize -First 30

Search for/trace an email (examples)

# Note date format! Find all emails from sender email address
# Note that you may need to use wildcards or full email address
get-exchangeserver | get-messagetrackinglog -resultsize unlimited -start "10/19/2016 9:10AM" -end "10/24/2016 9:15AM" | ? {$_.sender -like "donald.trump@whitehouse.gov"} 
# this one has timestamp
get-exchangeserver | Get-MessageTrackingLog -Start (Get-Date).AddDays(-14) -ResultSize Unlimited | ? {$_.sender -like "amanda.hugginkiss@domain.com"} | select timestamp, eventID, sender, recipients, messagesubject | out-gridview
# for a domain
get-exchangeserver | Get-MessageTrackingLog -Start (Get-Date).AddDays(-14) -ResultSize Unlimited | ? {$_.sender -like "*@piedpieper.com"} | select timestamp, eventID, sender, recipients, messagesubject | out-gridview
# within past 24 hrs
get-exchangeserver | Get-MessageTrackingLog -Start (Get-Date).AddHours(-24) -ResultSize Unlimited | ? {$_.sender -like "fred.durst@limpbizkit.com"}

Get user examples

Get-User -Identity Referalls@refer.com
Get-content c:\USERS.txt | Get-Mailbox | Format-Table -AutoSize
Get-content c:\USERS.txt | Get-Mailbox | Select-Object PrimarySmtpAddress | Format-Table -AutoSize
Get-Mailbox -Identity Referrals | Select-Object PrimarySmtpAddress
Get-Mailbox -Identity Referrals@Refer.com

Remove full access rights to a mailbox

get-mailbox -identity tim.smith | Remove-MailboxPermission -AccessRights Fullaccess -user jane.smith

 

Move DAG to another server

Move-ActiveMailboxDatabase 'User Database1' -ActivateOnServer Server2 -MountDialOverride:None
Move-ActiveMailboxDatabase 'Public Folders' -ActivateOnServer Server2 -MountDialOverride:None
Move-ActiveMailboxDatabase 'User Database2' -ActivateOnServer Server2 -MountDialOverride:None

Show mailbox last login time

get-mailbox -identity john.smith | get-mailboxstatistics

Show members of distribution group

Get-DistributionGroupMember "All Zebras"


<h2>Show members of a dynamic distribution group</h2>

$members = Get-DynamicDistributionGroup -Identity "All Elephants"
Get-Recipient -RecipientPreviewFilter $members.RecipientFilter | select Displayname

<h2>List Receive Connector Remote IP Ranges</h2>

Get-ReceiveConnector “name of receive connector” |select -ExpandProperty RemoteIpRanges |select Expression |sort Expression

View mailbox database for user

get-mailbox -identity "john.smith" | select-object database,displayname

Message Queue operations

# View queue on server;
Get-Queue
# Messages on queue;
Get-Queue | Get-Message
# view queue on specified server
Get-Queue -Server <strong>serveradı</strong>
# view queue on all transport servers
Get-TransportServer | Get-Queue
# Message on the all transport servers queue
Get-TransportServer | Get-Queue | Get-Message
# Suspending all the messages on queue
Get-Queue | Get-Message | Suspend-Message
# Deleting messages on queue
Get-Queue | Get-Message | Remove-Message

 

Add members to a distribution group

Add-DistributionGroupMember -Identity "All Circus Staff" -Member "john.smith"

View Lync user

Get-CSUser -Identity "Jack Daniels"

Add a user to Lync

Import-Module Lync
Enable-CsUser –Identity "john smith" –RegistrarPool lyncserver.com –SipAddressType SamAccountName –SipDomain domain.com
#OR
Enable-CsUser –Identity "john smith" –RegistrarPool lyncserver.com –SipAddressType EmailAddress –SipDomain domain.com

View accepted domains

Get-AcceptedDomain

Place server into maintenance mode (before rebooting)

StartDagServerMaintenance.ps1 –ServerName EXCHSERVER1
StopDagServerMaintenance.ps1 –ServerName EXCHSERVER1

Scripts directory

C:\Program Files\Microsoft\Exchange Server\V15\scripts

Add accepted domain and set as Authoritative

New-AcceptedDomain -DomainName Contoso.com -DomainType Authoritative -Name Contoso

Bring mailbox database online after server failure

Resume-MailboxDatabaseCopy

Show distribution groups for a user

$Mailbox=get-Mailbox john.smith@domain.com
$DN=$mailbox.DistinguishedName
$Filter = "Members -like ""$DN"""
Get-DistributionGroup -ResultSize Unlimited -Filter $Filter | select Name, DisplayName, PrimarySmtpAddress

Set an out of office/autoreply on a mailbox

Set-MailboxAutoReplyConfiguration -Identity Ana -AutoReplyState Scheduled -StartTime "5/01/2015 08:30:00" -EndTime "6/15/2015 17:30:00" -InternalMessage "Insert internal auto-reply message here"

Create meeting room and enable autoresponse when booking

New-Mailbox -Name 'Meeting Room 1' -Alias 'MeetingRoom01' -OrganizationalUnit "domain.com/users and stuff/Resources" -UserPrincipalName "MeetingRoom01@domain.com" -SamAccountName 'MeetingRoom01' -FirstName '' -Initials '' -LastName '' -Room
Set-CalendarProcessing "MeetingRoom01" -AutomateProcessing AutoAccept

Delegate calendar/folder access

Allow Steve full access to Bill's calendar

add-MailboxFolderPermission -Identity bill.gates@microsoft.com:\calendar -User "steve.jobs" -AccessRights Editor

remove-MailboxFolderPermission -Identity bill.gates@microsoft.com:\calendar -User "steve.jobs" -AccessRights Editor

Show Server side rules (eg OWA rules)

Get-InboxRule –Mailbox "noreply@domain.com" | select description

List receive connectors that contain an IP

Get-ReceiveConnector | ? {$_.remoteIPRanges -match "172.20.254.24" }

Show all mailboxes that are being forwarded to other users

get-mailbox -resultsize unlimited -Filter { ForwardingAddress -like '*' } | select-object Name,ForwardingAddress | out-gridview