代码之家  ›  专栏  ›  技术社区  ›  stackprotector

如何在PowerShell中重新实现Invoke RestMethod的SessionVariable/WebSession变量概念?

  •  0
  • stackprotector  · 技术社区  · 5 年前

    我想包几包 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
    }
    

    但是我如何使用会话变量的名称呢 登录 把它传给 -WebSession 参数甚至可以重新实现SessionVariable/WebSession的概念吗 调用rest方法 ? 我觉得这和一个 call-by-reference 通过 [ref] ,但如何在变量名(字符串)和实际变量之间建立桥梁?

    0 回复  |  直到 5 年前
    推荐文章