source/public/Connect-ExOP.ps1
Function Connect-ExOP { [CmdletBinding()] param( [parameter(mandatory, position = 0)] [string] $exchangeServer, [parameter()] [pscredential]$Credential ) Write-Verbose "Establishing Remote PowerShell Session $exchangeServer." $props = @{ Name = 'Exchange' ConfigurationName = 'Microsoft.Exchange' ConnectionUri = "http://$($exchangeServer)/PowerShell/" Authentication = 'Kerberos' Confirm = $false } if ($Credential) { $props += @{Credential = $Credential } } Remove-PSSession -Name Exchange -Confirm:$false -ErrorAction SilentlyContinue $Session = New-PSSession @props Import-Module (Import-PSSession $Session -AllowClobber -DisableNameChecking) -Global -WarningAction SilentlyContinue } |