Get all messages from all transport servers by a specific sender, starting on a specific day

Get all messages from all transport servers by a specific sender, starting on a specific day and export to CSV

Use this one-liner:

Get-TransportServer | Get-MessageTrackingLog -sender:test@test.com -start 7/15/2014 -resultsize unlimited | export-csv c:export.csv

How to Get OutlookAnywhere Configuration Settings from ActiveDirectory

When you type get-outlookanywhere settings, the settings are typically retried from CAS servers. However, those settings can also be retrieved directly from active directory and usually faster than retrieving from CAS servers. To do that, use this PowerShell one liner:

get-outlookanywhere -ADPropertiesOnly | fl identity, *auth*, *hostname

That command will display server name, client authentication method, iisauthentication method and external/internal hostnames

Manually Purge Log Files from Exchange Database Copies

Purpose:  The purpose of this document is to provide instruction on how to safely purge Exchange Database log files manually after log file buildup on a Exchange Server.  Log files are stored in the logs directly until an Exchange aware Full or Incremental Backup is successfully ran.  Once Exchange is aware that this backup is complete, Exchange will purge the log files.  If a backup has not ran successfully, then log files will continue to be created in the logs directory and the previous log files will still exist, consuming space.  Over time, this will fill up the hard drive where the log files are kept.  This manual purge is done live, meaning the instructions below happen while the Exchange Database remains mounted.  In the instructions below, we are using an Exchange Database DB53 that has 4 Database Copies; 1 Mounted, 3 Healthy.

Overview of the Instructions Below:

1. Capture and isolate the Log Files that will moved and purged into a text file.

2. Using Excel, open that text file and format it. Format meaning remove unwanted rows such as Header/Footer rows and removing log files for dates you wish to not remove.  For Example, I want to remove all the log files EXCEPT the last day or two. **NOTE do not remove the newest log files – give yourself a buffer**.

3. Using Excel, we will formulate the Move-Item and Remove-Item scripts to be ran on each server that holds the database copy.  From one database copy, we will move the log files to another serverstorage location.  From the other 3 database copies, we will purge the log files.  Purging log files is quick, moving log files is a little bit slower.

4. Run the appropriate .ps1 script that will be created on each server that holds a database copy.

Instructions:

Capture and Isolate the Log Files:
1. Determine the LogFilePrefix for the database:
get-mailboxdatabase DB53 | FL LogFilePrefix

2. Determine the Database Copies Status to figure out which copy is mounted, healthy, or other status. Of the Mounted/Healthy Database Copies, choose 1 Database Copy to move the logs that wish to be purged to a storage share and purge the logs on the remaining copies. This ensures a copy of the logs exist in the event of a problem.

Get-mailboxdatabasecopystatus DB53

3. In a command prompt, run the following DIR command. It will put the results into the text file specified.  You will be using the LogFilePrefix you have found in Step1.

dir MBX01e$db53logsE01*.log > C:usersstevedesktopDB53.txt

In Excel, Open the Text File and Format It

4. Open Excel and then Open that Txt File.  Make sure during the Text Import Wizard (when opening the txt file in Excel), the logs are in their own column. I chose fixed width in the Wizard. Click on Finish.

5. Remove the rows that do not contain a log file (Very Beginning Rows and Very Last Rows).

6. Sort the dates (if not sorted already) and remove the rows of the date range that you do not wish to delete. For Example, I want to purge all log files EXCEPT for the last 2 days’ worth.

In Excel, Create the PowerShell Code used to Move/Purge Log Files

7. In Column F (Or the next Open Column) type this formula in and Copy on down to the last row. Note: Cell E2 is the log file name. You may have to change this value if the log file name exists in a different cell.

=”Write-Host “&E2&”; Move-Item E:DB53Logs”&E2&” FileSvr1filesDB53″ 

8. In Column G (or the next Open Column) type this formula in and Copy on down to the last row. Note: Cell E2 is the log file name. You may have to change this value if the log file name exists in a different cell.

=”Write-Host “&E2&”; Remove-Item E:DB53Logs”&E2&” -force”

 9. Copy the Contents out of the Move-Item Column and paste into notepad. Save that notepad file as DB53_move.ps1.  Copy this and run this on the server that has the database copy for you wish to move the log files.

10. Copy the Contents out of the Remove-Item Column and paste into notepad. Save that notepad file as DB53_remove.ps1.  Run this in PowerShell on the servers that have the remaining database copies.

Now you have carefully Moved/Purged the Log Files of that database. You now have bought yourself enough free space on the hard drives to work out your backup issues.

Install and Configure PowerShell Web Access

Here are the steps I took to configure PowerShell Web Access. These commands are being ran from an elevated PowerShell Prompt on the server WebSvr1.TestDomain.Com.

1. Install the Windows PowerShell Web Access Feature. Run the following command:  Install-WindowsFeature –Name WindowsPowerShellWebAccess –IncludeManagementTools

2. Configure the PSWA Gateway. Run the following command:  Install-PSWAWebApplication.  

If you do not have a certificate for the default site configured, you can use the -UseTestCertificate switch, else it will use the certificate already configured.  You should be able to access the url now: https://WebSvr1.TestDomain.Com/pswa  but you will not be able to login until the next step is completed.

3.Configure the PSWA authorization rules.  Run the following command:      Add-PSWAAuthorizationRule –UserGroupName TestDomainExAdmins –ComputerName WebSvr1.TestDomain.Com –ConfigurationName *

This command is allowing the ExAdmin group members to authenticate with PowerShell Web Access to the server WebSvr1.TestDomain.com. Now you can authenticate on the PSWA webpage.  Alternatively, you can use these switches with the Add-PSWAAuthorizationRule to add to your rule(s):

-UserName
-UserGroupName
-ComputerName
-ComputerGroupName
-ConfigurationName
4. Now you can successfully navigate to https://WebSvr1.TestDomain.Com/PSWA and run powershell.

Export Mail into a PST between two dates

Scenario:  You want to export mail from a mailbox into a PST with a filter of between two dates.

Run this command:

New-MailboxExportRequest -ContentFilter {(Received -gt ’01/01/2014′) -and (Received -lt ’04/01/2014′)} -Mailbox “testuser1” -Name testuser1 -FilePath ServerSharetestuser1.pst -baditemlimit 999 -acceptlargedataloss

Exchange Server unexpectedly reboot after CU6 and databases in service down state.

Issue
Exchange Server unexpectedly reboot after CU6 and databases in service down state.
Cause
Based on the dump it looks to be caused by Replication Services Crashing.
Resolution
Database copy status on the server was showing ServiceDown
After sometime it was showing initializing and few mins later again showing ServiceDown
Checked Event ID
Log Name:      Application
Source:        MSExchange Common
Date:          
Event ID:      4999
Task Category: General
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      
Description:
Watson report about to be sent for process id: 41108, with parameters: E12IIS, c-RTL-AMD64, 15.00.0995.029, msexchangerepl, M.Exchange.Common, M.E.C.H.DatabaseFailureItem.Parse, System.ArgumentOutOfRangeException, fe19, 15.00.0995.012.
ErrorReportingEnabled: True
Log Name:      Application
Source:        Windows Error Reporting
Date:         
Event ID:      1001
Task Category: None
Level:         Information
Keywords:      Classic
User:          N/A
Computer:    
Description:
Fault bucket , type 0
Event Name: E12IIS
Response: Not available
Cab Id: 0
Ran the below command
Wevtutil.exe cl “Microsoft-Exchange-MailboxDatabaseFailureItems/Operational”
Ran it and restarted the Replication Services
All the copy status came to healthy in sometime
Dump Analyzes
==============
*******************************************************************************
*                                                                             *
*                        Bugcheck Analysis                                    *
*                                                                             *
*******************************************************************************
CRITICAL_PROCESS_DIED (ef)
        A critical system process died
Arguments:
Arg1: fffffa80611bd080, Process object or thread object
Arg2: 0000000000000000, If this is 0, a process died. If this is 1, a thread died.
Arg3: 0000000000000000
Arg4: 0000000000000000
Debugging Details:
——————
PROCESS_OBJECT: fffffa80611bd080
IMAGE_NAME:  wininit.exe
DEBUG_FLR_IMAGE_TIMESTAMP:  0
MODULE_NAME: wininit
FAULTING_MODULE: 0000000000000000
PROCESS_NAME:  MSExchangeHMWo
BUGCHECK_STR:  0xEF_MSExchangeHMWo
DEFAULT_BUCKET_ID:  WIN8_DRIVER_FAULT
   

Forward emails that comes to a mailbox to an external address and also keep the mail.

Scenario: you want to forward emails that comes to a particular mailbox to an external address and also keep the mail.

Resolution: Create a mail contact using powershell or Exchange 2013 ECP. If you have exchange 2010 users, you can also use the mgmt console

From Powershell, type Set-Mailbox -Identity ‘testmailbox’ -DeliverToMailboxAndForward:$true -ForwardingAddress ‘mailcontactalias’

The error “Members can’t remove themselves from security groups. Please set the group to Closed for requests to leave.” when editing a distribution group.

Scenario: When editing the managers of a distribution group, this error is displayed:

Members can’t remove themselves from security groups. Please set the group to Closed for requests to leave.

Resolution: Set the MemberDepartRestriction to closed for that distribution group.

set-distributiongroup  <alias of group> -memberdepartrestriction closed

Installing SNMP Services on remote servers via powershell

Open notepad, paste the following in notepad without the quotes.
“Get-WindowsFeature -name SNMP* | Add-WindowsFeature -IncludeManagementTools”
 then save as c:snmpinstall.ps1

From powershell run the following.(without the quotes) Replace servername with the actual server name(s).
For more servers add additional lines as needed.

Invoke-Command -FilePath C:snmpinstall.ps1 -ComputerName servername
Invoke-Command -FilePath c:snmpinstall.ps1 -ComputerName servername
Invoke-Command -FilePath c:snmpinstall.ps1 -ComputerName servername

Check for hotfix on multiple computers

Create file c:server_list.txt with a list of the servers to check.
In powershell scripts below: Replace $Patch variable KB2982791with the hotfix your looking for.

2 Files will be created on your desktop.
      Hotfix=Present.log
      Missing=Hotfix.log


Run the following from powershell
$computers = cat C:server_list.txt
$Patch = “KB2982791”
foreach ($computer in $computers)  
{  
if (get-hotfix -id $Patch -ComputerName $computer -ErrorAction 0)  
{  
Add-content “Hotfix is Present in $computer” -path “$env:USERPROFILEDesktopHotfix-Present.log” 
}
Else  
{  
Add-content “Hotfix is not Present in $computer” -path “$env:USERPROFILEDesktopMissing-Hotfix.log”   

}