How to import custom PowerShell module into the remote session?

前端 未结 5 1267
名媛妹妹
名媛妹妹 2020-12-13 02:18

I\'m developing a custom PowerShell module, which I\'d like to use in context of a remote session to a different computer. The following code (which obviously doesn\'t work)

5条回答
  •  天涯浪人
    2020-12-13 02:51

    What about making scriptblock out of your custom function and sending it off to terget servers using Invoke-command

    Import-module YourModule
    $s = [scriptblock]::Create($(get-item Function:\Your-ModuleFunction).Definition)
    
    Invoke-Command -ScriptBlock $s -Computername s1,s2,sn
    

提交回复
热议问题