Import-PowershellSession.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
<#
.SYNOPSIS This function imports the Exchange On-Premises powershell session. .DESCRIPTION This function imports the Exchange On Premises powershell session allowing exchange commands to be utilized. .PARAMETER exchangePowershellSession This is the powershell session created by new-ExchangeOnPremisesPowershell .OUTPUTS The powershell session to Exchange On-Premises. .EXAMPLE import-ExchangeOnPremisesPowershell -exchangePowershellSession session #> Function Import-PowershellSession { [cmdletbinding()] Param ( [Parameter(Mandatory = $true)] $PowershellSession, [Parameter(Mandatory = $false)] [boolean]$isAudit=$false ) #Output all parameters bound or unbound and their associated values. write-functionParameters -keyArray $MyInvocation.MyCommand.Parameters.Keys -parameterArray $PSBoundParameters -variableArray (Get-Variable -Scope Local -ErrorAction Ignore) #Define variables that will be utilzed in the function." #Begin estabilshing the powershell session. Out-LogFile -string "********************************************************************************" Out-LogFile -string "BEGIN IMPORT-POWERSHELLSESSION" Out-LogFile -string "********************************************************************************" try { Out-LogFile -string "Importing powershell session." Import-PSSession -Session $PowershellSession -allowClobber -ErrorAction Stop } catch { Out-LogFile -string $_ -iserror:$TRUE -isAudit $isAudit } Out-LogFile -string "The powershell session imported successfully." Out-LogFile -string "END IMPORT-POWERSHELLSESSION" Out-LogFile -string "********************************************************************************" } |