【问题标题】:Local New-PSSession fails in official powershell linux based docker images本地 New-PSSession 在基于官方 powershell linux 的 docker 映像中失败
【发布时间】:2020-02-07 18:26:54
【问题描述】:

使用 docker 运行 powershell 核心(微软官方图像), 我正在尝试在我的脚本中设置一个本地会话,以便稍后在该会话中执行代码。

我曾尝试使用以下 Linux 映像:

6.2.3-alpine-3.8
6.2.3-centos-7
6.2.3-debian-9
6.2.3-ubuntu-18.04

在 alpine 和 debian 中出现错误: This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system.

在 Centos 和 Ubuntu 中都出现错误: MI_RESULT_ACCESS_DENIED

我尝试挖掘错误但仅在尝试从 linux 远程到 windows 的情况下被提及,而在这里我要做的只是打开最基本的本地会话。

        $FullCommand = "Invoke-Expression $CompleteScript"
        $Session = New-PSSession
        [scriptblock]$ScriptBlock = [scriptblock]::Create($FullCommand)
        Invoke-Command -Session $Session -ScriptBlock $ScriptBlock

        $Session = New-PSSession
        Invoke-Expression -Session $Session -Command $CompleteScript

在开始从 linux 到 windows 的远程会话之前,我想建立一个本地会话并能够在其上执行代码。

我是 powershell 新手,所以可能会遗漏一些东西,但我希望本地会话至少可以处理 microsoft 的 powershell 核心的官方 docker 映像之一,那里的文档没有让我对这个问题有任何见解。

【问题讨论】:

    标签: powershell docker ubuntu powershell-remoting powershell-core


    【解决方案1】:

    按照here的建议,我使用以下dockerfile sn -p 安装WSMan。

    #install powershell WSMan.Management module 
    RUN pwsh -Command "Install-Module -Name PSWSMan -Force"
    RUN pwsh -Command "Install-WSMan"
    

    【讨论】:

      猜你喜欢
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-11
      • 2019-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多