【问题标题】:Issues with Powershell Invoke-CommandPowershell Invoke-Command 的问题
【发布时间】:2014-10-13 23:11:48
【问题描述】:

我正在尝试使用 powershell 将应用程序安装在远程服务器上。这是我正在使用的脚本:

$cred = 获取凭据
$s = New-PSSession -ComputerName $ServerName -Credential $cred

Invoke-Command -Session $s -ScriptBlock {Start-Process -FilePath "c:\windows\system32\msiexec.exe" -ArgumentList "/i \\computer\e$\installer.msi /qn" -Wait }

删除-PSSession -ComputerName $ServerName

如果我直接在远程计算机上运行以下命令,它会执行得很漂亮:

Start-Process -FilePath "c:\windows\system32\msiexec.exe" -ArgumentList "/i \\computer\e$\installer.msi /qn" -Wait

但是当我作为 Invoke-Command 的一部分远程运行它时,PS 会话打开,脚本运行,msiexec 在远程计算机上启动,然后 PS 会话关闭,但应用程序永远不会安装,msiexec 永远不会关闭。

任何帮助将不胜感激。

谢谢,

扎克

【问题讨论】:

    标签: windows powershell powershell-3.0


    【解决方案1】:

    您需要先将包复制到本地。 一旦你开始远程处理,你就不能再 UNC。

    目的地可以是服务器/计算机上的任何位置。 我使用温度,但它是你喜欢的任何东西。
    我也喜欢使用 $env:windir\temp,以防万一。

        Copy-item "\\servershare\File.msi" -conatiner -recurse `
                   \\$Computer\c$\windows\temp\
    
        Invoke-Command -Computername $Computer -credential $cred -ScriptBlock {
            Start-Process -FilePath `
            "c:\windows\system32\msiexec.exe" `
            -ArgumentList "/i `
            \\computer\e$\installer.msi /qn" -Wait
            }
    

    希望对你有帮助。

    【讨论】:

    • 我最初将它复制到本地,但它不起作用,所以我切换到了 UNC。原来本地不起作用的原因是因为 msiexec 不喜欢在“ArgumentList”中传递的 .msi 文件路径中的空格。一旦我将 .msi 移动到不同的路径,并在我的脚本中引用了新路径,它就完美地工作了。谢谢你的帮助,雷米。
    • @ZacharyWheeler - 我可以要求大家在提供更正后发布最终脚本吗?太感谢了!
    猜你喜欢
    • 1970-01-01
    • 2018-02-28
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    相关资源
    最近更新 更多