I want to wrap several Invoke-RestMethod
calls by two functions and I have to pass the WebSession
variable between them. Goal:
Login -SessionVariable MySession
# do some work while using $MySession
Logout -WebSession $MySession
The Login
and Logout
functions will probably look like that:
function Login {
Param(
[String]SessionVariable
)
Invoke-RestMethod ... -SessionVariable $SessionVariable
Invoke-RestMethod ... -WebSession ???
Invoke-RestMethod ... -WebSession ???
}
function Logout {
Param(
WebSession
)
Invoke-RestMethod ... -WebSession $WebSession
}
But how can I use the name of the session variable in Login
to pass it to the -WebSession
parameter? Is it even possible to reimplement this SessionVariable/WebSession concept of Invoke-RestMethod
? I think it has something to do with a call-by-reference
by [ref]
, but how do I build the bridge between a variable name (a string) and an actual variable?