Skip to content

Commit 8d323e5

Browse files
committed
add error handling
1 parent a36e549 commit 8d323e5

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

EXCHANGE-Connect-ExchangeOnPremises/Connect-ExchangeOnPremises.ps1

+12-7
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ function Connect-ExchangeOnPremises {
3535
[System.Management.Automation.Credential()]
3636
$Credential = [System.Management.Automation.PSCredential]::Empty
3737
)
38+
try{
3839

39-
$Splatting = @{
40-
ConnectionUri = $ConnectionUri
41-
ConfigurationName = 'microsoft.exchange'
42-
}
43-
IF ($PSBoundParameters['Credential']) { $Splatting.Credential = $Credential }
4440

45-
# Load Exchange cmdlets (Implicit remoting)
46-
Import-PSSession -Session (New-PSSession @Splatting)
41+
$Splatting = @{
42+
ConnectionUri = $ConnectionUri
43+
ConfigurationName = 'microsoft.exchange'
44+
}
45+
IF ($PSBoundParameters['Credential']) { $Splatting.Credential = $Credential }
46+
47+
# Load Exchange cmdlets (Implicit remoting)
48+
Import-PSSession -Session (New-PSSession @Splatting)
49+
}catch{
50+
$PSCmdlet.ThrowTerminatingError($_)
51+
}
4752
}

0 commit comments

Comments
 (0)