Skip to content

Instantly share code, notes, and snippets.

@BanterBoy
Created January 3, 2021 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BanterBoy/f46265efe806b95acd6126de4dc59b04 to your computer and use it in GitHub Desktop.
Save BanterBoy/f46265efe806b95acd6126de4dc59b04 to your computer and use it in GitHub Desktop.
On-Premise Exchange Connection Functions
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