-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-Conn.ps1
More file actions
40 lines (37 loc) · 1.18 KB
/
Get-Conn.ps1
File metadata and controls
40 lines (37 loc) · 1.18 KB
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
function Get-Conn {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
$conn
,
[Parameter(Mandatory = $false)]
[string]$udl
,
[Parameter(Mandatory = $false)]
[string]$connStr
)
begin {
Write-Verbose -Message ((Get-ResStr 'STARTING_FUNCTION') -f $myInvocation.Mycommand)
Test-ValidateSingle -validParams (Get-SingleConnection) @PSBoundParameters
New-Variable -Name 'result' -Scope 'Private' -Value ($null)
$initialVariables = Get-CurrentVariables -Debug:$DebugPreference
}
process {
if ($conn) {
$result = $conn
if ($result.state -eq $adStateClosed) {
$result.open()
}
} elseif ($udl) {
$result = Get-ConnFromUdl -udl $udl
} elseif ($connStr) {
$result = Get-ConnFromStr $connStr
} else {
throw ((Get-ResStr 'ADO_SET_ERROR') -f $($myInvocation.MyCommand))
}
} end {
Get-CurrentVariables -InitialVariables $initialVariables -Debug:$DebugPreference
Return $result
}
# Test: Get-Conn -udl 'C:\temp\Eulanda_1 Eulanda.udl'
}