-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathTest-3.workaround.ps1
More file actions
27 lines (23 loc) · 740 Bytes
/
Copy pathTest-3.workaround.ps1
File metadata and controls
27 lines (23 loc) · 740 Bytes
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
# This function creates a "connection" and gives it to the caller not by
# returning but by creating its variable in the parent (caller) scope.
# So the result of the function is the variable `$Connection`.
# (Why this unusual way is used is a different story).
function Connect-Something1 {
$Connection = "this-is-connection"
Set-Variable -Name Connection -Value $Connection -Scope 1
}
# Use an extra script block to work around the problem of test 2.
class Connector {
[object] Connect() {
# create connection using an extra script block
$Connection = &{
Connect-Something1
$Connection
}
# return connection
return $Connection
}
}
# It returns "this-is-connection"
$connect = [Connector]::new()
$connect.Connect()