MICROSOFT Exchange



MICROSOFT EXCHANGE TIPS

   

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


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.