Skip to content

Instantly share code, notes, and snippets.

@Apoc70
Last active June 26, 2024 08:56
Show Gist options
  • Save Apoc70/4bd4361a3542dbf01226456bde58ef03 to your computer and use it in GitHub Desktop.
Save Apoc70/4bd4361a3542dbf01226456bde58ef03 to your computer and use it in GitHub Desktop.
Get Exchange org information for on-premises or Exchange Online as Xml
<#
.SYNOPSIS
This script exports On-Premises Exchange Org and Exchange Online Org configurations to Xml
.DESCRIPTION
The script exports dat using Export-CLixml to the folder \Output
You must create the folder prior to excurting the script.
.PARAMETER Environment
The envrionment to query, either OnPremises or ExchangeOnline
.EXAMPLE
.\Get-ExchangeInfo.ps1 -Environment OnPremises
#>
param(
[ValidateSet('OnPremises','ExchangeOnline')]
[string]$Environment = 'OnPremises'
)
$ScriptDir = Split-Path -Path $script:MyInvocation.MyCommand.Path
$TimeStamp = (Get-Date -Format yyyyMMdd-HHmm)
$OutputFolder = 'Output'
$OutputPath = Join-Path -Path $ScriptDir -ChildPath $OutputFolder
if(-not (Test-Path -Path $OutputPath -PathType Container)) {
Write-Host ('Creating folder: {0}' -f $OutputPath)
New-Item -Path $OutputPath -ItemType Directory | Out-Null
}
Write-Host ('Output to: {0}' -f $OutputPath)
# On-Premises
function Get-ExchangeData{
param(
[string]$Prefix
)
Get-OrganizationConfig | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-OrganizationConfig.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-OrganizationRelationship | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-OrganizationRelationship.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-IntraOrganizationConfiguration | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-IntraOrganizationConfiguration.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
try {
if (gcm Get-OfflineAddressBook -ErrorAction SilentlyContinue) {
Get-OfflineAddressBook | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-OfflineAddressBook.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
}
}
catch {Write-Warning 'Get-OfflineAddressBook does not exist. This might be an RBAC role assignment issue.'}
try {
if (gcm Get-AddressList -ErrorAction SilentlyContinue) {
Get-AddressList | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-AddressList.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
}
}
catch {Write-Warning 'Get-AddressList does not exist. This might be an RBAC role assignment issue.'}
Get-SharingPolicy | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-SharingPolicy.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-AcceptedDomain | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-AcceptedDomain.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-RemoteDomain | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-RemoteDomain.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-EmailAddressPolicy | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-EmailAddressPolicy.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-TransportRule | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-EmailAddressPolicy.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-RetentionPolicy | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-RetentionPolicy.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-RetentionPolicyTag | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-RetentionPolicyTag.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
if($Prefix -eq 'OnPremises') {
# OnPremises stuff only
Get-AuthConfig | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-AuthConfig.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-DatabaseAvailabilityGroup | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-DatabaseAvailabilityGroup.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-ExchangeServer | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-ExchangeServer.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-ReceiveConnector | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-ReceiveConnector.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-SendConnector | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-SendConnector.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-HybridConfiguration | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-HybridConfiguration.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
}
else {
# Exo stuff only
# Adjust the cmdlets, if you use a cmdlet prefix for your Exchange Online connection
Get-InboundConnector | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-InboundConnector.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-OutboundConnector | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-OutboundConnector.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
Get-MigrationEndpoint | Export-CliXml -Path (Join-Path -Path $OutputPath -ChildPath ('{0}-{1}-MigrationEndpoint.xml' -f $Prefix, $TimeStamp)) -Encoding UTF8 -Force
}
}
Write-Host ('Checking {0}' -f $Environment)
Get-ExchangeData -Prefix $Environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment