Search message tracking logs

Message tracking records the message activity as mail flows through the transport pipeline on Mailbox servers and Edge Transport servers. You can use the Get-MessageTrackingLog cmdlet in the Exchange Management Shell to search for entries in the message tracking log by using specific search criteria. For example:

  • Find out what happened to a message that was sent by a user to a specific recipient.
  • Find out if a transport rule acted on a message.
  • Find out if a message sent from an Internet sender made it into your Exchange organization.
  • Find all messages sent by a specified user during a specified time period.

This example searches the message tracking logs on the local server for all entries from 2/20/2018 8:00 AM to 2/20/2015 5:00 PM for all FAIL events where the message sender was sender@mutega.se

Get-MessageTrackingLog -ResultSize Unlimited -Start “2/20/2018 8:00AM” -End “2/20/2018 5:00PM” -EventId “Fail” -Sender “sender@mutega.se”

This example searches the message tracking logs on the local server for all entries from 2/20/2018 8:00 AM to 2/20/2015 5:00 PM for all emails sent to to@mutega.com where the message sender was sender@mutega.se

Get-MessageTrackingLog -ResultSize Unlimited -Start “2/20/2018 8:00AM” -End “2/20/2018 5:00PM” -EventId “Fail” -Sender “sender@mutega.se” -Recipients “to@mutega.com”

More info (Source article): https://technet.microsoft.com/en-us/library/bb124926%28v=exchg.160%29.aspx?f=255&MSPPError=-2147217396

Copy AD OU Structure To Another AD Location

This was made by MALEK Ahmed and change by João Dias, in order to copy a AD structure to a new AD location. Just copy and paste on the notepad and save it as .ps1

 

#START

#*********************************************************************************************
#
# Copy AD OU Structure To Another Location
#
# Written by João Dias
# Date 10/04/2017
#
# Version: 1.0
#
#*********************************************************************************************

#Configuration of the Source and the Destination
$sourceOU = “OU=mutegaold,DC=domain,DC=local”
$destinationOU = “OU=muteganew,DC=newdomain,DC=local”

#AD Path
$adPath= “LDAP://” + $destinationOU

#Importing AD module
import-module activedirectory
#Copying the OU’s to the destination
$objDomain=New-Object System.DirectoryServices.DirectoryEntry($adPath)
$ObjSearch=New-Object System.DirectoryServices.DirectorySearcher($ObjDomain)
[array] $OUs = @()
$OUs = dsquery * $sourceOU -Filter “(objectCategory=organizationalUnit)” -limit 0
$OUsorted = $OUs | sort-object { $_.Length}
for ($k=0; $k -le $OUsorted.Count -1; $k++)
{
$OUtoCreate = ($OUsorted[$k] -replace $sourceOU,$destinationOU).ToString()
$OUSearch = ($OUtoCreate -replace ‘”‘,””).ToString()
$ObjSearch.Filter = “(&(objectCategory=organizationalUnit)(distinguishedName=”+ $OUSearch + “))”
$allSearchResult = $ObjSearch.FindAll()
if ($allSearchResult.Count -eq 1)
{
“No changes were done on = ” + $OUtoCreate
}
else
{
dsadd ou $OUtoCreate
“OU Creation = ” + $OUtoCreate
}
}

#END

The script is provided “AS IS” without warranty of any kind. We disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Mutega IT, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Mutega IT has been advised of the possibility of such damages.

Export Active Directory Users data to a CSV file

Here is a old script that I write down during a AD migration, to export users data from Active Directory.  Just copy and paste on the notepad and save it as .ps1

#START

#*********************************************************************************************
#
# Export AD users data
#
# Written by João Dias
# Date 10/04/2017
#
# Version: 1.0
#
#*********************************************************************************************

#Define location
$path = Split-Path -parent “c:\temp\*.*”

#Define OU location
$ou = ‘OU=users,DC=domain,DC=local’

#Create a variable for the date stamp in the log file
$LogDate = get-date -f yyyyMMddhhmm

#Define CSV and log file location variables
$csvfile = $path + “\Users_$logDate.csv”

#import the ActiveDirectory Module
Import-Module ActiveDirectory

$AllADUsers = Get-ADUser -Filter * -SearchBase $ou

$AllADUsers |
Select-Object @{Label = “First Name”;Expression = {$_.GivenName}},
@{Label = “Last Name”;Expression = {$_.Surname}},
@{Label = “Display Name”;Expression = {$_.DisplayName}},
@{Label = “Logon Name”;Expression = {$_.sAMAccountName}},
@{Label = “Full address”;Expression = {$_.StreetAddress}},
@{Label = “City”;Expression = {$_.City}},
@{Label = “State”;Expression = {$_.st}},
@{Label = “Post Code”;Expression = {$_.PostalCode}},
@{Label = “Country/Region”;Expression = {if (($_.Country -eq ‘GB’) ) {‘United Kingdom’} Else {”}}},
@{Label = “Job Title”;Expression = {$_.Title}},
@{Label = “Company”;Expression = {$_.Company}},
@{Label = “Directorate”;Expression = {$_.Description}},
@{Label = “Department”;Expression = {$_.Department}},
@{Label = “Office”;Expression = {$_.OfficeName}},
@{Label = “Phone”;Expression = {$_.telephoneNumber}},
@{Label = “Email”;Expression = {$_.Mail}},
@{Label = “Manager”;Expression = {%{(Get-AdUser $_.Manager -server $ADServer -Properties DisplayName).DisplayName}}},
@{Label = “Account Status”;Expression = {if (($_.Enabled -eq ‘TRUE’) ) {‘Enabled’} Else {‘Disabled’}}}, # the ‘if statement# replaces $_.Enabled
@{Label = “Last LogOn Date”;Expression = {$_.lastlogondate}} |

#Export CSV report

Export-Csv -Path $csvfile -NoTypeInformation

#END

The script is provided “AS IS” without warranty of any kind. We disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Mutega IT, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Mutega IT has been advised of the possibility of such damages.