Troubleshooting Techniques: Verify ActiveSync is operational on a server

Scenario:  You received complaints that ActiveSync isn’t working for some users in your environment.  Your environment consists of large number of servers and you need a quick way of determining which server is not able to process ActiveSync requests.

Troubleshooting Steps:

  1. Check the server component state on each server: Get-exchangeserver EX* | Get-servercomponentstate | Where {($_.Component -eq “ActiveSyncProxy”) -and ($_.state -ne “Active”)}
  2. Test-ActiveSyncConnectivity:$1 = get-credential
    $Servers = Get-clientaccessserver esg* | Where AdminDisplayVersion -like *15*
    $final = @()
    $Servers | %{$final += Test-ActiveSyncConnectivity -AllowUnsecureAccess:$true -ClientAccessServer $_ -MailboxCredential $1 -lightmode}
  3. Check Logs on the server:
    1. Verify EAS connections are being logged in the IIS Logs: C:inetpublogslogfilesw3svc1
    2. Verify the EAS logs are generating activity. EAS logs should be generated every hour:  c:Program FilesMicrosoftExchange ServerV15LoggingHttpProxyEas
  4. Go to the URL and test.  A working server produces  DeviceIdMissingOrInvalid as an error after authentication:  https://<server fqdn>/Microsoft-server-activesync

Script to monitor the state of the ActiveSyncProxy server component and email an alert

Scenario:  You want to monitor the ActiveSyncProxy server component state. If ActiveSyncProxy becomes inactive, you want the script to automatically resolve the issue and to send an alert via email.

Script:

#Collect Servers
$1 = Get-exchangeserver Ex* | Get-servercomponentstate | Where {($_.Component -eq "ActiveSyncProxy") -and ($_.state -ne "Active")}

#Loop Servers for Component State
$1 | Select -ExpandProperty Identity | %{$s = [string]$_;Set-servercomponentstate $s -component ActiveSyncProxy -state Active -Requester HealthAPI}

#Send an Email
If($1 -ne $null){
$1_body = $1 | Out-String
#Email
$body =""
$smtp = "smtp.domain.com"
[string[]]$to = "Steve@Domain.com","Fred@Domain.com"
$from = "EASMonitor@domain.com"
$subject = "ActiveSync Monitor - Activesync is currently not working on a server" 
$body += "<b><Font color=Black>There could be an issue with ActiveSync as the server component state is not active on the following servers: </b></font><br><br>"
$body += "<Font color=red>$1_body </font><br><br><br>"
#Send Email
send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -Priority high
}

 

“Mailbox Size exceeds target quota ” when issuing new-moverequest

Scenario:  When issuing a new move request, you receive the following error:

Mailbox Size <size> exceeds target quota <size>

Solution:  Temporarily lift the ProhibitSendReceive quota size and run the new move request again. You can set the ProhibitSendReceive quota to unlimited OR to a higher value than the current mailbox size.

Get-mailbox <alias> | Select Prohibit*

Set-mailbox <alias> -prohibitsendreceive unlimited.

If the mailbox is 50MB,  you could also run this:

Set-mailbox <alias> -prohibitsendreceive 55MG.

Excel Magic – When inserting the cell value of a date into a formula, the date converts into a numeric value and doesn’t display in a date format correctly

Scenario:  In Cell A1 you have a date of ‘6/3/2016’.  In Cell B1, you have a formula that pulls in the date:

=”Today is “&A1

Instead of getting the value  Today is 6/3/2016, you get Today is 41428

 

Solution:  Use the Text function inside your fomula to convert the date from numeric form to date form.

=”Today is “& TEXT(A1,”M/D/YYYY”)

Today is 6/3/2016

 

Excel Magic – Use a formula to remove characters before and/or after a character of a cell value.

Scenario:  You have an excel (CSV) worksheet of undeliverable emails.  You need to pull only the email address out of the body of the message.  Note: I replaced all carriage returns internal to the cell value by doing a Find and Replace on:  <Control J> and replace with .

Example: Cell Value A1:

Delivery has failed to these recipients or groups:
.
.bob@xyz.net<mailto:bob@xyz.net>
. A problem occurred while delivering this message to this email address. Try sending this message again.

Solution:

Use the following Excel Formulas to remove all characters to the left and to the right of the <  and  >.

In cell B1, remove everything to the left of the ‘<‘ in A1.

=RIGHT(A1,LEN(A1)-FIND(“<“,A1)) 

Result:  mailto:bob@xyz.net>
 . A problem occurred while delivering this message to this email address. Try sending this message again. 

In cell C1,  remove everything to the right of the ‘>’ in cell B1.

=LEFT(B1,FIND(“>”,B1)-1)

Result:  mailto:bob@xyz.net

 

 

Determine who has a mailbox and remote mailbox via AD Powershell

Scenario:  You have a list of username’s in a .csv file with a column header labeled: name.  You want to quickly determine which usernames have a Mailbox and RemoteMailbox.

Script:

Import-module ActiveDirectory

$Members = Import-csv C:sharecvusers.csv | Select -ExpandProperty Name

$Members = $Members | Sort

$Members_OnPrem = @()
$Members_o365 = @()

$Members  | %{
    "$_"
    $type = Get-ADUser $_ -properties msExchRecipientTypeDetails | Select -ExpandProperty MSexchRecipientTypeDetails
         If ($type -eq "1"){$Members_OnPrem += $_}
         If ($type -eq "2147483648"){$Members_o365 += $_}
}


Performing a Search-Mailbox with complex search criteria

Scenario: Batman is at it again.  He is now under litigation hold for attacking Superman and you want to search in Superman’s mailbox for any message that was received and sent by Batman, or specific terms were in the Subject, Body, or attachments.  You are only interested for messages sent after 1/1/2012.

Script:

Search-Mailbox Superman -SearchDumpster -SearchQuery "(Received:1/1/2012..5/18/2016) AND (To:Batman@DC.com OR From:Batman@DC.com OR CC:Batman@DC.com OR BCC:Batman@DC.com OR 'Batman' OR 'Bruce' OR 'Wayne')" –targetmailbox BobTheLawyer -loglevel full -targetfolder "Search_Batman"

Test-ActiveSyncConnectivity to verify EAS is working properly

Scenario: You want to test whether ActiveSync (EAS) is working properly.  You can use the following script to determine if EAS is failing on any of your Exchange Client Access Servers:

Script:

#Gather Credentials for the Test User into a variable
$1 = get-credential ("DomainEASTestuser")

#Gather Servers into a variable
$Servers = Get-clientaccessserver 

#Define your collection variable
$EAS = @()

#Loop through each server and test
$Servers | %{$EAS += Test-ActiveSyncConnectivity -AllowUnsecureAccess:$true -ClientAccessServer $_ -MailboxCredential $1 -lightmode}

Use PowerShell to filter by or count when files were created.

Scenario:  You suspect that logs are not being generated properly and you want to find the logs or count the logs based on any log created after a specific date.

#View the file information for the logs:
Get-ChildItem "\Ex2013Server1C$Program FilesMicrosoftExchange ServerV15LoggingHttpProxyEas" | Where-Object { $_.CreationTime -gt [datetime]"2016/05/17" } | Sort-Object CreationTime | Format-Table Name, CreationTime

#Count the Logs
(Get-ChildItem "\Ex2013Server1C$Program FilesMicrosoftExchange ServerV15LoggingHttpProxyEas" | Where-Object { $_.CreationTime -gt [datetime]"2016/05/17" } | Sort-Object CreationTime | Format-Table Name, CreationTime).count

Powershell Data Formatting

Scenario:  You have collected information into a variable, and you want to run different formatting commands against that variable to performs tasks such as Sorting, Grouping, Selecting, Ect.

Don’t forget the Pipe!    $final | Sort name

Example of the command you ran:

$final = get-mailboximportrequest -batchname ‘502’

#To display all properties:

$final | FL        #List Style  
$final | Select *  #Table or List Style
$final | FT        # Table Style

#Sorting based on  a property:

$final | Sort Identity   #Ascending Order

$final | Sort Identity -Descending #Descending Order

$final | Sort -unique  # Sorts Unique Values

#Grouping  based on a property

$final | Group RequestQueue   #Provides a Count of number of objects in array based on the value of the RequestQueue.

$final | Group Request Queue | Sort Count #Same as command above by sorts by the count of the value of the Request Queue

# Where statements: Filter your variable based on a Property Value with

$final | Where Status -ne Completed

$final | Where {$_.Status -ne "Completed"}

$final | Where Status -like "*Failed*"

$final | Where WhenCreated -gt "5/3/2016 2:00:00 PM"

#common conditions: 
-eq      equals
-ne      not equals
-gt      greater than
-ge      greater than or equal
-lt      less than
-le      less than or equal
-like    Contains
-notlike Does not contain


#Rename a Property

$final | Select Identity, @{Name="Database";Expression={$_.RequestQueue} #this will display the request queue as the headername of Database.