powershell - 如何在PowerShell中重新实现Invoke-RestMethod的SessionVariable/WebSession变量概念?
问题描述
我想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]
有关,但是如何在变量名(字符串)和实际变量之间建立桥梁?
解决方案
推荐阅读
- python - 在 Python 中的函数中多次从 randint() 生成随机数
- python - 如何修复随机无效语法
- pandas - 根据值在列中删除一个单元格
- reactjs - redux-offline 应用程序在首次加载时闪烁 InitialState 值
- javascript - Return 语句似乎在 javascript switch 语句中不起作用
- perl - Perl 中的模糊匹配
- azure-devops - 如何监控 azure devops 上项目的任何更改并通过电子邮件发送
- asp.net-core - IdentityServer4 和让多个应用程序共享身份验证
- vue.js - 显示每次导航到组件的重复值
- r - Shiny 响应进入,一个不太有效的例子