20. April 2024

Exchange Remote-Verbindung herstellen (Exchange Remote Server Administration)

Eine Remote-Verbindung zu einem OnPremise Exchange Server kann mit dem folgenden Skript hergestellt werden. Das Skript ermittelt einen Exchange Server aus der AD und stellt eine Verbindung her.

#Autor:     Eddie
#Date:      2021/09/02
#Web        https://exchangeblogonline.de
#Intention: Connect to Exchange

#Clear Screen
Clear-Host

#vars
$ADPartitionPath = (Get-ADRootDSE).configurationNamingContext
$DOMAIN = $env:USERDOMAIN
$EXSERVER = (Get-ChildItem  "AD:\CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=$DOMAIN,CN=Microsoft Exchange,CN=Services,$ADPartitionPath").Name

#auskommentieren, wenn mehrere Exchange Server vorhanden sind
#$SESSION = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://$(Get-Random $EXSERVER)/powershell" -Authentication Kerberos -AllowRedirection 

$SESSION = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://$($EXSERVER)/powershell" -Authentication Kerberos -AllowRedirection

#function import Exchange Session
function Import-EXSession{
    Import-PSSession $SESSION -DisableNameChecking -AllowClobber
}

#connect string
try{
    Import-EXSession

    #check if connection is open
    if((Get-PSSession).State -eq "Opened"){
        Clear-Host
        $SERVER = (Get-PSSession).ComputerName
        Write-Host "`nConnection to [$SERVER] established..." -ForegroundColor Green 
    }
}catch{
    Write-Host "´nConnection to Exchange failed. Please try again." -ForegroundColor Red 
}

Der Inhalt kann als Datei auf dem Desktop z.B. als Connect-Exchange.ps1 abgespeichert werden, um zukünftig via PowerShell eine Verbindung aufzubauen. Voraussetzung ist, dass der Client Mitglied der Domäne ist.

0 0 votes
Article Rating
Abonnieren
Benachrichtige mich bei
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x