我想Invoke-RestMethod
用两个函数包装几个调用,我必须在它们之间传递WebSession
变量。目标:
Login -SessionVariable MySession
# do some work while using $MySession
Logout -WebSession $MySession
和函数可能看起来像这样Login
:Logout
function Login {
Param(
[String]SessionVariable
)
Invoke-RestMethod ... -SessionVariable $SessionVariable
Invoke-RestMethod ... -WebSession ???
Invoke-RestMethod ... -WebSession ???
}
function Logout {
Param(
WebSession
)
Invoke-RestMethod ... -WebSession $WebSession
}
但是如何使用会话变量的名称将其Login
传递给-WebSession
参数?是否有可能重新实现这个 SessionVariable/WebSession 的概念Invoke-RestMethod
?我认为它与call-by-reference
by[ref]
有关,但是如何在变量名(字符串)和实际变量之间建立桥梁?