Some Powershell One-Liners

​Run this one liner command to disable client access to a mailbox
Set-CASMailbox “testmbox” -EwsEnabled $false -ActiveSyncEnabled $false -MAPIEnabled $false -OWAEnabled $false -ImapEnabled $false -PopEnabled $false
Disable single item recovery and remove the mailbox from litigation hold.
 
Set-Mailbox “Mickey Mouse” -SingleItemRecoveryEnabled $false -LitigationHoldEnabled $false
 
Copy items from the Recoverable Items folder to a folder in the Discovery Search Mailbox and delete the contents from the source mailbox.
 
Search-Mailbox -Identity “testmbox” -SearchDumpsterOnly -TargetMailbox “Discovery Search Mailbox” -TargetFolder “GurinderSingh-RecoverableItems” -DeleteContent
  
If you need to delete only messages that match specified conditions, use the SearchQuery parameter to specify the conditions. This example deletes messages that have the string “card statement” in the Subject field.
 
Search-Mailbox -Identity “testmbox” -SearchQuery “Subject:’card statement'” -SearchDumpsterOnly -TargetMailbox “Discovery Search Mailbox” -TargetFolder “testmbox-RecoverableItems” -DeleteContent

Out of Office with PowerShell

Setting OOF for a mailbox. Run this command
Simple OOF
Set-MailboxAutoReplyConfiguration USERID -AutoReplyState Enabled –ExternalMessage “Message that you want to go out.” –InternalMessage “Message that you want to go out.”
To schedule run
Set-MailboxAutoReplyConfiguration USERID –AutoReplyState Scheduled –StartTime “12/19/2013” –EndTime “4/30/2014” –ExternalMessage “Message that you want to go out.” –InternalMessage “Message that you want to go out.”
To Check run
Get-MailboxAutoReplyConfiguration USERID
More Information

Reporting Mailbox Folder sizes with Powershell

​Reporting Mailbox Folder sizes with Powershell
report on individual folders and sizes:
Get-MailboxFolderStatistics testmbox
get folder stats and display folder size and items in folder:
Get-MailboxFolderStatistics testmbox | Ft name,FolderSize,ItemsinFolder
look at specific folders and sub folders:
Get-MailboxFolderStatistics testmbox -FolderScope Inbox | Select Name,FolderSize,ItemsinFolder

Exchange Script: Find ActiveSync Device Statistics for users in a Distribution Group

Scenario: You want to Find ActiveSync Device Statistics for users that are in a Distribution Group. If the Distribution Group does not contain members, it will not send the email. If it contains members, it will send an email for each member. Copy the content below and paste it into a .ps1 file and execute from Exchange Mangaement Shell.   
$mbox = Get-DistributionGroup “group-name”| Get-DistributionGroupMember
If ($mbox -ne $null)
{
$email = $mbox | ForEach {
$name = $_ | Select Name |Out-String
$body = get-activesyncdevicestatistics -mailbox $_.name | Sort DeviceFriendlyName | FT DeviceFriendlyName, DeviceModel, LastSyncAttemptTime, LastSuccessSync | Out-string
$SmtpClient = new-object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$SmtpClient.Host = “servername”
$mailmessage.from = (“EASMonitoring@domain.com”)
$mailmessage.To.add(“easstatistics@domain.com“)
$mailmessage.Subject = “EAS Statistics”
$mailmessage.Body = “
EAS Statistics for:$name
$body

$smtpclient.Send($mailmessage)
}
}

IMAP/POP Certificate issue after Install of Ex2013 CU3

Scenario: After the installation​ of Ex2013 CU3, the certificate that was assigned the POP and IMAP services became unassigned and assigned to another certificate.  The error clients were receiving:
“IMAP Error: Server Certificate was rejected by the verifier because the certificate’s common name ‘mail.domain.com’ does not match the hostname ‘imap.domain.com’.
Resolution:  From Ex2013 Management Shell, run the following: 
1. Determine the thumbprint of the certificate that should have IMAP and POP enabled by running: Get-ExchangeCertificate 
2. Then run: Enable-ExchangeCertificate -Thumbprint XXXXXXXXXX -Services POP,IMAP
3. Restart the Imap and Pop frontend and backend services.

Exporting and Importing Mailbox in 2010 SP1

Please trefer to any of the following links:
 
1.
 
 
OR
 
2.
 

Redistribute Exchange Databases

​To redistribute Exchange databases so they are mounted on the Mailbox Server that holds the first activation preference, run the following:
1. Open up Exchange Management Shell
2. Change the directory to the Scripts folder located in the Exchange Install Directory; 
Example: CD  “C:Program FilesMicrosoftExchange ServerV14Scripts”
3. Run the following command:
 .RedistributeActiveDatabases.ps1 -DagName <dagname> -BalanceDbsByActivationPreference –ShowFinalDatabaseDistribution –Confirm:$false
 Note: To find the DagName, you can run the get-databaseavailabilitygroup powershell command to list your Dags.

you cannot make changes to the contents of this read only folder

Issue: Customer reported this error while trying to remove a calendar appointment for her manager in Outlook 2010.

“you cannot make changes to the contents of this read only folder”
customer manages lots of calendars for several managers. The managers have given admin rights to this customer
Resolution: Reconfigured Outlook 2010 for Online mode. Customer was using Outlook in cache mode