Powershell Script to check how many emails were Sent and Received by a specific user

Powershell Script to check how many emails were Sent and Received by a specific user:

[Int] $intSent = $intRec = 0

Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -Start “03/09/2014” -End “03/10/2014” -Sender “user@domain.com” -EventID RECEIVE | ? {$_.Source -eq “STOREDRIVER”} | ForEach { $intSent++ }

Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -Start “03/09/2014” -End “03/10/2014” -Recipients “user@domain.com” -EventID DELIVER | ForEach { $intRec++ }

Write-Host “E-mails sent:    “, $intSent

Write-Host “E-mails received:”, $intRec

Disable Outlook Auto-Mapping with Mailboxes

If you wish to give a user full access to a mailbox, but do not want to have the mailbox auto-map into the users Outlook profile, assign the full access permission with with the -AutoMapping parameter.

Add-MailboxPermission mailboxname -user username -accessrights fullaccess -AutoMapping $false

The attempt to connect to http://server/powershell using “Kerberos” authentication failed: Connecting to remote server failed with the following error message: The WinRM client cannot process the request because the server name cannot be resolved

Error message: The attempt to connect to http://server/powershell using “Kerberos” authentication failed: Connecting to remote server failed with the following error message: The WinRM client cannot process the request because the server name cannot be resolved
Resolution: Try any of the options below
  
Option 1: 
Close console
Delete:  “C:Users[User Profile]AppDataRoamingMicrosoftMMCExchange Managment Console”
Try connecting again. It should re-query the servers
Option 2:
Close EMC
Delete the following registry value from the server: 
  HKCUSoftwareMicrosoftExchangeServerv14AdminToolsNodeStructureSettings
Reopen your EMC .
Option 3
If you know a working server’s name, launch the console
Right Click on Microsoft Exchange, Click on Add Exchange forest
Under specify the FQDN or URL running the remote powershell instance, type the fqdn of the server

Click OK

Receiving “You don’t have sufficient permissions” when editing Distribution List membership/owner

Scenario:  You receive the following error message when editing the members/owner of a group in powershell:
You don’t have sufficient permissions. This operation can only be performed by a manager of the group.


Resolution:  Use -BypassSecurityGroupManagerCheck in the powershell command.

Adding member to Distribution List
Add-DistributionGroupMember “<Distribution Group Name>” -Member <User Name>
-BypassSecurityGroupManagerCheck

Setting the owner of a Distribution List
Set-DistributionGroup -Identity “<Distribution Group Name>” –ManagedBy <User Name>
-BypassSecurityGroupManagerCheck

Recommendations to avoid IOS Calendar Corruption with Exchange Mailboxes

Scenario: An entry on an IOS calendar shows incorrect times for an appointment, has disappeared, or is missing information, although the calendar entries in OWA and Outlook is correct. Specifically a single occurrence of a repeat appointment/meeting has one of the symptoms from above.

Recommendations from support:


1. Microsoft recommends running the same version of Outlook on all the computers. Mailbox owners and any delegates need to be using the same version of Outlook with the latest updates on all the computers that are used for calendaring. If you are in a mixed environment of Mac, Windows and iOS devices, each platform needs to be using the same version and each device should have the latest updates. 
2. Only one person should process meeting requests. Other people, computers or devices that receive the meeting request should ignore them, they should not delete or process them. Users should have a maximum of 2 delegates.
3. Manage your calendar exclusively from Outlook or OWA. Don’t accept, decline, modify or invite others to appointments from your mobile device. You can create new appointments on your mobile device.
4. Verify that the device has the latest iOS version installed. (Please verify this before adding the Exchange account to the device. Sometimes, new devices are running an older version of iOS, so it is a good habit to confirm that all updates are applied before adding Exchange accounts)
5. To change an entire series of meetings, cancel the original meeting and create a new one. To change one instance, cancel just that meeting and create a new one to replace it. Always put an end date on a recurring meeting.
6. A “corrupt” meeting will remain that way until you delete it. If it is a recurring appointment, delete all occurrences and reschedule it.
7. When scheduling a recurring meeting, Microsoft recommends setting the end date no more than 6 months. If you need to schedule a meeting for a longer period, start a new recurring meeting.

8. Making multiple changes to recurring events can contribute to unexpected results.

Exchange Activesync Monitor for Specific Devices

Scenario:  Monitor specific ActiveSync Devices and report when a device has not made a successful ActiveSync connection for over an hour.  Report the time in local time and not Greenwich.  

Script: I ran the following Exchange PS script every hour . Depending on your requirements, you may need to manipulate or move the script around.

#Format Date to Greenwich
$currentdate = get-date
$currentdate = $currentdate.Addhours(-1)
$currentdate = $currentdate.touniversaltime()

#Pull the devices that have not connected to LastSuccessSync in over an hour
$devices = get-activesyncdevicestatistics DeviceID  | Where {$_.LastSuccessSync -lt $currentdate} | Sort LastSuccessSync | Select DeviceID, DeviceOS, deviceFriendlyName, LastSuccessSync, LastSyncAttemptTime, DeviceModel, Identity

#For the device(s) found, format the information
ForEach ($entry in $devices){
$Device = “Device: “+$entry.DeviceFriendlyName
$DeviceOS = “Device OS:   “+$entry.DeviceOS
$DeviceLastAttempt = “Last Sync Attempt (EST):   “+$entry.LastSyncAttemptTime.ToLocalTime()
$DeviceLastSync = “Last Success Sync (EST):   “+$entry.LastSuccessSync.ToLocalTime()
$DeviceModel = “Device Model:   “+$entry.DeviceModel
$DeviceIdentity = “DeviceID:   “+$entry.Identity
$DeviceIdentity = $DeviceIdentity -replace “Domain/OU/”,””
$DeviceIdentity = $DeviceIdentity -replace “/ExchangeActiveSyncDevices/”,”_”
}

#Email the results if there is a device that has not reported in over 1 hour.
If ($Devices -ne $null){
$SmtpClient = new-object system.net.mail.smtpClient 
$MailMessage = New-Object system.net.mail.mailmessage 
$SmtpClient.Host = “smtp.domain.com” 
$mailmessage.from = (“EASMonitoring@domain.com”) 
#$mailmessage.To.add(“User@domain.com”) 
$mailmessage.Subject = “Alert: A mobile device has not connected to e-mail in over 60 minutes.”
$mailmessage.Body = “The mobile device below has not connected to e-mail in over 60 minutes.
$DeviceIdentity
$Device
$DeviceOS
$DeviceLastAttempt
$DeviceLastSync

$smtpclient.Send($mailmessage)
}

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)
}
}