New CMDlet: Clean-MailboxDatabase in Exchange 2013
Command is Update-StoreMailboxState

Examples:
This updates the mailbox state for a mailbox located on the mailbox database DB01
Update-StoreMailboxState -Database DB01 -Identity GUIDof DB

 
This updates the mailbox state for a mailbox located on the mailbox database DB01 with a GUID of 4a830e3f-fd07-4629-baa1-8bce16b85d44.
Update-StoreMailboxState -Database MDB01 -Identity 4a830e3f-fd07-4629-baa1-8bce16b85d44
 
This updates the mailbox state for all disconnected mailboxes on the mailbox database DB01.
Get-MailboxStatistics -Database DB01 | Where { $_.DisconnectReason -ne $null } | ForEach { Update-StoreMailboxState -Database
$_.Database -Identity $_.MailboxGuid -Confirm:$false }

Powershell Check to see if mailbox exists

Scenario:  You have a list of mailboxes that you do not know if they still exist or not.  Instead of checking one by one, you can script this.  

In my users.csv I have a header with Name that contains all of the aliases underneath.


$users = Import-csv C:users.csv
$users | ForEach { $exist = [bool](Get-mailbox $_.name -erroraction SilentlyContinue); Write-host “$Exist $_.Name”}

Cancel a Remote Wipe Request from a Mobile Device via Powershell

Scenario:  A user has found a missing mobile device. While the device was missing, the user has initiated a remote wipe on it.  We want to prevent the remote wipe from occurring when the phone is powered back on.

Solution: Run this via Exchange Management Shell:

clear-activesyncdevice <identity> -cancel:$true

Note: I tried running the -cancel $true as stated in the article, but I received this error:
A positional parameter cannot be found that accepts argument ‘True’.  I replaced it with -cancel:$true

Microsoft Article Reference

PublicFolders health set is “Unhealthy” after you install Exchange Server 2013 Cumulative Update 3

Issue: PublicFolders health set is “Unhealthy” after you install Exchange Server 2013 Cumulative Update 3
Scenario: Installed cu3 for exchange 2013, no public folder mailboxes on exchange 2013, get-healthreport gives unhealthy status for public folders
Resolution: Create an override for all servers using version bound override
Add-GlobalMonitoringOverride -Identity “PublicfoldersPublicFolderLocalEWSLogonEscalate” -ItemType “Responder”-PropertyName Enabled -PropertyValue 0 -ApplyVersion “15.0.775.38”
Add-GlobalMonitoringOverride -Identity “PublicfoldersPublicFolderLocalEWSLogonMonitor” -ItemType “Monitor” -PropertyName Enabled -PropertyValue 0 -ApplyVersion “15.0.775.38”

Add-GlobalMonitoringOverride -Identity “PublicfoldersPublicFolderLocalEWSLogonProbe” -ItemType “Probe” -PropertyName Enabled -PropertyValue 0 -ApplyVersion “15.0.775.38”

Transport service won’t start on exchange 2010 server.

Issue: Transport service won’t start on exchange 2010 server.
Event log details: Transport Mail Database: MSExchangeTransport has detected a critical storage error, updated the registry key (SOFTWAREMicrosoftExchangeServerv14TransportQueueDatabase) and as a result, will attempt self-healing after process restart. Event id: 7001/17106

Resolution: Stopped transport service, remove queue database, restart transport service

Giving Reviewer Rights to a calendar of a bunch of Exchange Mailboxes

To give calendar reviewer rights to a user called nosey1 to bunch of mailboxes, use this one liner below. you will need to add their email aliases
to a text file.

Get-content C:scriptsCalperm.txt | ForEach-Object {Add-MailboxFolderPermission $_”:Calendar” -User nosey1 -AccessRights Reviewer}

Removing Duplicate Contact Items in a Exchange Mailbox

Scenario:  You have a mailbox that has hundreds of copies of their contacts in their mailbox.  For example, a user originally had 2500 contacts and now has 800,000 contacts because of the multiple copies.   Here are the steps I followed to resolve this issue.

1. Export their contacts in the users Outlook to a CSV.   In my scenario, the outlook session was locking up so I exported the PST out via Exchange Shell and then re-exported to a CSV out of Outlook. (New-MailboxExportRequest mailbox -IncludeFolders “#Contacts#” -ExcludeDumpster -FilePath servershare$contacts.pst -name mailbox  -acceptlargedataloss -baditemlimit 999)

Outlook 2013:  File–>Open&Export–>Import/Export–>Export to a File–>Comma Separated Values–>Select Contacts Folder–>Save Exported File to location –> Click Finish.

2. Open Powershell, and Import the CSV created in step 1 into a Variable.
$File = Import-CSV “C:usersusernamedesktopuserscontacts.csv”

3. Select the unique values for the $File, compares all columns.
$uniq = $File | Select * -unique

4. Export the unique values to a .csv file
$uniq | Export-csv “C:usersusernamedesktopuserscontacts_unique.csv”

5. Delete the existing contacts in the users mailbox via Exchange Shell.  The Search-Mailbox has a 10,000 item limit. I put the command in a loop so it continues to remove all contacts at 10,000 per loop cycle.

do {
Write-Host $i
Search-Mailbox mailbox -SearchQuery kind:contacts -DeleteContent -Force
$i++
}
while ($i -le 81)

6. Opened Outlook 2013 and followed similar steps as step 1, except I performed the import on the unique CSV.  Note, I did have to clean up the CSV by removing the very first line as the very first line was not the column names.  In order for the CSV import to work, the first line needs to be the column names and NOT the other junk that export may have carried over.

Now the unique contacts are restored.

Find a Message in the message tracking log against every transport server in your Exchange Org

The Powershell one liner below will search the Message Tracking Log against every transport server in your Exchange Organization.  Note that you may want to change the Select statement to include/remove which values you want to pull back into view (you can replace with the entire Select statement with FL to see every value available).

Get-TransportServer | Get-MessageTrackingLog -Sender:user@domain.com -Recipients user@domain.com -MessageSubject “another test” -Start 5/8/2014 | Sort Timestamp | Select TimeStamp, EventID, Source, MessageSubject, ClientIP, ClientHostname, ServerIP, ServerHostname

Exchange PowerShell script that will perform a mailbox count on each database and email the results.

Below is a Exchange PowerShell script that will perform a mailbox count on each database and email the results.  The script is performed with the get-mailboxstatistics for each mailbox on that database as the results are much faster than the get-mailbox command.


# Create an empty HashTable to store database name and count.
$MailboxCount = @{}

# Collect Databases
$databases = Get-mailboxDatabase | Where Name -like “2013DB*” | Sort name

#Loop through each
ForEach ($database in $databases){
$MBs = Get-mailboxstatistics -database $database
$MailboxCount.Add($Database,$MBs.count)
}

#Format the Results
$MailboxCountOrdered = $MailboxCount.GetEnumerator() | Sort-Object Name | Out-String
$orderedMailboxCount = $MailboxCount.GetEnumerator() | Sort-object Value | Out-String

#Send an email:
$SmtpClient = new-object system.net.mail.smtpClient 
$MailMessage = New-Object system.net.mail.mailmessage 
$SmtpClient.Host = “mail.server.com” 
$mailmessage.from = (“MailboxCount@domain.com”) 
$mailmessage.To.add(“email.address”) 
$mailmessage.Subject = “Mailbox Count”
$mailmessage.Body = “Mailbox Count

The following list shows the Mailbox Count for the Databases in Ex2013. The 2 lists below are the same; one is in order of database name and the other is in order of mailbox count.
Database Order:
$MailboxCountOrdered 
Count Order:
$OrderedMailboxCount

$smtpclient.Send($mailmessage)