MICROSOFT EXCHANGE TIPS
HOW TO LIST ALL MAILBOX INSIDE DATABASE
get-mailbox -database
HOW TO GET MAILBOX DATABASE NAME
Get-MailboxDatabase -Status -IncludePreExchange | Sort Name | Format-Table Name, Server, Mounted
HOW TO IMPORT PST TO MAILBOX
New-MailboxImportRequest -mailbox email.address@domain.cz -FilePath PST_File_PathaccountName.pst -TargetRootFolder /
CHECK RUNNING IMPORT PROCESS
Get-MailboxImportRequest -Status InProgress | Get-MailboxImportRequestStatistics -IncludeReport
CHECK COMPLETED IMPORT PROCESS
Get-MailboxImportRequest -Status Completed | Get-MailboxImportRequestStatistics -IncludeReport
HOW TO CREATE MAILBOX
Enable-Mailbox accountName@domain.cz -Database MailboxDatabase01
MOVE STORE AND LOGS
Move-Databasepath "DatabaseName" –EdbFilepath "C:NewlocationDBname.edb" –LogFolderpath "C:Newlocation"
MOVE USER MAILBOX
Get-Mailbox -Database "CIS-users" | New-MoveRequest -TargetDatabase "cis-other"
OR ONLY USER
Get-Mailbox "p.mares" | New-MoveRequest -TargetDatabase CIS-itnoncbs5
CHECK STATUS
Get-MoveRequestStatistics -MoveRequestQueue "CIS-users" | ft displayname,percentcomplete,statusdetail,totalmailboxsize
CLENUP AFTER MOVE
Get-MoveRequest -MoveStatus Completed | Remove-MoveRequest
ADD DOMAIN TO WHITELIST
Set-ContentFilterConfig -BypassedSenderDomains @{Add="contoso.com","contoso2.com"}
TURN ON / OFF SPAM FILTER
Set-SenderFilterConfig -Enabled $true
Set-SenderFilterConfig -Enabled $false
UPDATE GLOBAL ADDRESS LIST
Update-OfflineAddressBook "Default Offline Address Book"
Update-GlobalAddressList "Default Global Address List"
HOW TO EXPORT EMAILS TRACKING LOG
To screen
Get-MessageTrackingLog -Server SERVER-NAME -Start "03/13/2018 09:00:00" -End "12/31/2018 17:00:00" -Sender "EMAIL-ADDRESS"
To File
Get-MessageTrackingLog -Server SERVER-NAME -Start "03/13/2018 09:00:00" -End "12/31/2018 17:00:00" -Sender "EMAIL-ADDRESS" | Out-File c:xxx.txt
To File with TimeStamp
Get-MessageTrackingLog -Server SERVER-NAME -Start "03/13/2018 09:00:00" -End "12/31/2018 17:00:00" -Sender "EMAIL-ADDRESS" | FT Recipients, TimeStamp, MessageSubject | Out-File c:xxx.txt
GET ALL MESSAGES FROM DOMAIN “test.com”
Get-Message -Filter {FromAddress -like “*@test.com”}
Exchange Cleanup log files”
Set-Executionpolicy RemoteSigned
$days=10
$IISLogPath="C:\inetpub\logs\LogFiles\"
$ExchangeLoggingPath="C:\Program Files\Microsoft\Exchange Server\V15\Logging\"
$ETLLoggingPath="C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\ETLTraces\"
$ETLLoggingPath2="C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\Logs"
Function CleanLogfiles($TargetFolder)
{
write-host -debug -ForegroundColor Yellow -BackgroundColor Cyan $TargetFolder
if (Test-Path $TargetFolder) {
$Now = Get-Date
$LastWrite = $Now.AddDays(-$days)
# $Files = Get-ChildItem $TargetFolder -Include *.log,*.blg, *.etl -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}
$Files = Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Logging\" -Recurse | Where-Object {$_.Name -like "*.log" -or $_.Name -like "*.blg" -or $_.Name -like "*.etl"} | where {$_.lastWriteTime -le "$lastwrite"} | Select-Object FullName
foreach ($File in $Files)
{
$FullFileName = $File.FullName
Write-Host "Deleting file $FullFileName" -ForegroundColor "yellow";
Remove-Item $FullFileName -ErrorAction SilentlyContinue | out-null
}
}
Else {
Write-Host "The folder $TargetFolder doesn't exist! Check the folder path!" -ForegroundColor "red"
}
}
CleanLogfiles($IISLogPath)
CleanLogfiles($ExchangeLoggingPath)
CleanLogfiles($ETLLoggingPath)
CleanLogfiles($ETLLoggingPath2)
CleanUp exchange log files older than …
[CmdletBinding()]
Param(
[Parameter( Mandatory = $false )]
[ValidateRange( 1, 31 )]
[Int] $daysago = 10,
[Parameter( Mandatory = $false )]
[Bool] $reportOnly = $true
)
Set-StrictMode -Version 2.0
$folders = @( 'C:\Program Files\Microsoft\Exchange Server\V15\TransportRoles\Logs',
'C:\Program Files\Microsoft\Exchange Server\V15\Logging',
'C:\inetpub\logs\LogFiles' )
function wv
{
Write-Verbose ( ( Get-Date -Format u ) + ' ' + ( $args -join ' ' ) )
}
function processFolder
{
Param(
[Parameter( Mandatory = $true )]
[ValidateNotNullOrEmpty()]
[String] $folder,
[Parameter( Mandatory = $true )]
[System.DateTime] $date,
[Parameter( Mandatory = $true )]
[Bool] $reportOnly = $false
)
${func} = 'processFolder'
wv "${func}: enter, folder name $folder"
$exists = Test-Path -LiteralPath $folder -PathType Container
if( -not $exists )
{
wv "${func}: exit, folder $folder does not exist"
return
}
$files = Get-ChildItem -Recurse $folder
$str = $files.Count.ToString( 'n0' )
wv "${func}: files in folder $str"
$script:totalSize = 0
$files |
Where-Object { $_.PSIsContainer -eq $false } |
ForEach-Object { $script:totalSize += $_.Length }
$str = $script:totalSize.ToString( 'n0' )
wv "${func}: total size of files in folder $str"
$script:deletedSize = 0
$files |
Where-Object { $_.CreationTime -le $date -and $_.PSIsContainer -eq $false -and $_.Exists } |
ForEach-Object { $script:deletedSize += $_.Length }
$str = $script:deletedSize.ToString( 'n0' )
wv "${func}: total size of files to be deleted in folder $str"
if( $reportOnly )
{
wv "${func}: exit, no deletions"
return
}
$files |
Where-Object { $_.CreationTime -le $date -and $_.PSIsContainer -eq $false -and $_.Exists } |
ForEach-Object { Remove-Item $_.FullName -EA 0 }
wv "${func}: exit, deletions complete"
}
##
## Main
##
wv "Clean-LogFolder: start $( Get-Date )"
$date = ( Get-Date ).AddDays( -$daysago )
wv "Clean-LogFolder: daysago $daysago"
wv "Clean-LogFolder: date $date"
wv "Clean-LogFolder: reportOnly $reportOnly"
foreach( $folder in $folders )
{
processFolder $folder $date $reportOnly
}
wv "Clean-LogFolder: done $( Get-Date )"
How to get Exchange version info
Get-ExchangeServer | Format-List Name,Edition,AdminDisplayVersion
HOW TO EXPORT EMAILS TO PST
Example 1
New-MailboxExportRequest -Mailbox AylaKol -FilePath "\\SERVER01\PSTFileShare\Ayla_Recovered.pst"
This example exports the user Ayla Kol's primary mailbox to a .pst file on the network shared folder PSTFileShare on SERVER01.
Example 2
New-MailboxExportRequest -Mailbox Kweku -FilePath "\\SERVER01\PSTFileShare\Kweku_Archive.pst" -IsArchive
This example exports the user Kweku's archive to a .pst file on the network shared folder PSTFileShare on SERVER01.
Example 3
New-MailboxExportRequest -Mailbox Tony -ContentFilter "(Body -like '*company*') -and (body -like '*profit*') -and (Received -lt '01/01/2018')" -FilePath "\\SERVER01\PSTFileShare\Tony_CompanyProfits.pst"
This example exports messages that contain the words "company" and "profit" in the body of the message for the user Tony received before January 1, 2018.
Example 4
New-MailboxExportRequest -Mailbox Kweku -IncludeFolders "#Inbox#" -FilePath \\SERVER01\PSTFileShare\Kweku\InPlaceHold.pst
This example exports all messages from Kweku's Inbox to the .pst file InPlaceHold.
How to bypass Exchange malware filter
Set-MalwareFilteringServer -BypassFiltering $True -identity
Like this:
Like Loading...