Skip to content

Commit

Permalink
Merged Exchange Server scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
SamErde committed Mar 5, 2024
1 parent fae713d commit 1aa08b0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Exchange Server/Basic Exchange Health Checks.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Some basic Exchange Server checks to run after maintenance.
Write-Host -ForeGroundColor Yellow "Service Health"
Test-ServiceHealth
Write-Host -ForeGroundColor Yellow "MAPI Connectivity"
Test-MAPIConnectivity
Write-Host -ForeGroundColor Yellow "Mailbox Database Copy Status"
Get-MailboxDatabaseCopyStatus
Write-Host -ForeGroundColor Yellow "Cluster Node Status"
Get-ClusterNode
Write-Host -ForeGroundColor Yellow "Replication Health"
Test-ReplicationHealth
Write-Host -ForeGroundColor Yellow "Server Component State"
Get-ServerComponentState -Identity $env:COMPUTERNAME
4 changes: 4 additions & 0 deletions Exchange Server/Get DB Sizes.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Get-MailboxDatabase -Status | Sort-Object Name | `
Select-Object Name,
@{Name='DB Size (Gb)';Expression={$_.DatabaseSize.ToGb()}},
@{Name='DB Free Whitespace (Gb)';Expression={$_.AvailableNewMailboxSpace.ToGb()}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$ReceiveConnectors = (Get-ExchangeServer | Get-ReceiveConnector).Where({$_.Enabled -eq $true}) | Sort-Object Name,Identity
$ExternalRelays = @()
foreach ($rc in $ReceiveConnectors) {
$dn = $rc.DistinguishedName
if (Get-ADPermission -Identity $dn -User "NT AUTHORITY\ANONYMOUS LOGON" | Where-Object {$_.ExtendedRights.RawIdentity -eq "MS-Exch-SMTP-Accept-Any-Recipient"}) {
$ExternalRelays += $rc
}
}

$ExternalRelays | Select-Object Name,Server,Enabled -Unique
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# A fun way to find every cmdlet that gets Exchange virtual directories and then pipe that list to run it against the current server.
foreach ($c in ((Get-Command "Get*VirtualDirectory" -CommandType Function).Name)) {& $c -server $env:COMPUTERNAME | Format-List Name,InternalUrl,ExternalUrl}
21 changes: 21 additions & 0 deletions Exchange Server/Remove Old Exchange Server Log Files.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<#
.SYNOPSIS
A script to clear old Exchange logs files.
.DESCRIPTION
This script will clear all Exchange Server log files under the installation's "Logging" path that are older than a set
number of days. (It will not touch database log files unless those are intentionally put in the worst possible location!)
#>

# Set the number of days to preserve logs from.
$LogAgeDays = 14

# Check for the existince of the Exchange logging folder under the install path.
if (Test-Path -Path "$env:ExchangeInstallPath\Logging") {
Set-Location -Path "$env:ExchangeInstallPath\Logging" -ErrorAction Stop

# Get Exchang Server logs that are older than [nn] days and remove them. Any log files still in use will not be deleted.
Get-ChildItem -Path "$env:ExchangeInstallPath\Logging" -Recurse -Include *.log | `
Where-Object { $_.LastWriteTime -lt ((Get-Date).AddDays(-$LogAgeDays)) } | `
Remove-Item -Confirm:$false -ErrorAction SilentlyContinue
}

0 comments on commit 1aa08b0

Please sign in to comment.