Created
January 3, 2021 05:53
-
-
Save BanterBoy/f46265efe806b95acd6126de4dc59b04 to your computer and use it in GitHub Desktop.
On-Premise Exchange Connection Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function New-OnPremExchangeSession { | |
param ( | |
[Parameter(ValueFromPipeline = $True, | |
HelpMessage = "Enter preferred Exchange Server")] | |
[ValidateSet('MAIL01', 'MAIL02') ] | |
[string[]]$ComputerName | |
) | |
switch ($ComputerName) { | |
MAIL01 { | |
$Creds = Get-Credential | |
$OnPremSession = New-PSSession -ConfigurationName Microsoft.Exchange ` | |
-ConnectionUri http://INTERNAL-EXCHANGE-URI/PowerShell/ ` | |
-Authentication Kerberos -Credential $Creds | |
Import-PSSession $OnPremSession -DisableNameChecking | |
} | |
MAIL02 { | |
$Creds = Get-Credential | |
$OnPremSession = New-PSSession -ConfigurationName Microsoft.Exchange ` | |
-ConnectionUri http://INTERNAL-EXCHANGE-URI/PowerShell/ ` | |
-Authentication Kerberos -Credential $Creds | |
Import-PSSession $OnPremSession -DisableNameChecking | |
} | |
default { | |
$Creds = Get-Credential | |
$OnPremSession = New-PSSession -ConfigurationName Microsoft.Exchange ` | |
-ConnectionUri http://INTERNAL-EXCHANGE-URI/PowerShell/ ` | |
-Authentication Kerberos -Credential $Creds | |
Import-PSSession $OnPremSession -DisableNameChecking | |
} | |
} | |
} | |
function Remove-OnPremExchangeSession { | |
Get-PSSession | Remove-PSSession | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment