简体   繁体   English

Powershell命令无法通过PSRemote使用

[英]Powershell commands not working via PSRemote

I'm having some issues with trying to install various programs via powershell. 我在尝试通过Powershell安装各种程序时遇到一些问题。 This is an example (trimmed down) of the component of the module I've built: 这是我构建的模块组件的一个示例(精简):

Function TEST-INSTALL-Scripts
{
    Param($basepath,$Arguments)

    $command = @"
cmd.exe /C msiexec /package `"$basepath`" $Arguments
"@
    Invoke-Expression -Command $command
}

When I try to invoke it via 当我尝试通过调用它

Invoke-Command -Session $session -ScriptBlock {TEST-INSTALL-Scripts -Basepath $basepath -Arguments $args}

The command doesn't seem to do anything so I tried using a PSRemote tab to try to get some more details and I used this command: 该命令似乎没有执行任何操作,因此我尝试使用PSRemote选项卡尝试获取更多详细信息,然后使用了以下命令:

$basepath = "\\$Server\d$\Files\Install\3rd Party\SQL Server Native Client\sqlncli_x64.msi"
$Arguments = '  /quiet /passive'
TEST-INSTALL-Scripts -basepath $basepath -Arguments $Arguments

And I get a response back saying the file cannot be accessed or its not a valid file. 我得到一个回复​​,说该文件无法访问或不是有效文件。

T hisinstallationpackag ecouldnotbeopened . 无法安装包装。 V erifythatthepackageex istsandthatyoucanacce ssit , orcontacttheapplicati onvendortoverifythatt hisisavalid W indows I nstallerpackage . 确认存在该包装并且您可以访问该包装,或与该包装进行联系,以免其遗失了有效的窗口以安装该包装。

When I RDP onto the machine itself, the exact same command works without any issue. 当我将RDP加载到计算机本身时,完全相同的命令可以正常工作。

My research is pointing toward this being a double hop issue, but short of copying the file to the machine, is there a way of dealing with this that isn't a nightmare? 我的研究指出这是一个双跳问题,但是没有将文件复制到计算机上,有没有办法解决这不是一场噩梦?

I was able to build a minimal workaround that I put in just before the remote call where I pass the install path. 我能够构建一个最小的解决方法,该解决方法是在传递安装路径的远程调用之前放置的。 I also built a function to make it easier to manager but I put an example IF statement here (I built Get-InstallerLocal which does the same copy based on type) 我还构建了一个使管理起来更容易的函数,但我在此处放置了一个示例IF语句(我构建了Get-InstallerLocal,它根据类型进行相同的复制)

        If($installPath.StartsWith("\\"))
        {
            $DeployPath = Invoke-Command -Session $session -ScriptBlock {$env:TEMP}
            $drive=(Get-Item $DeployPath).PSDrive.Name
            $localpath = $DeployPath
            $DeployPath = $DeployPath.Replace("$($drive):","\\$machine\$drive$")
            If(!(Test-Path "$DeployPath\3rd Party\Microsoft Visual C++ 2010 Redistributable"))
            {
                Copy-Item -Path "$installPath\3rd Party\Microsoft Visual C++ 2010 Redistributable" -Destination "$DeployPath\3rd Party\Microsoft Visual C++ 2010 Redistributable\" -Force -Recurse
            }
            If($ODBCDriver){Get-InstallerLocal -installPath $installPath -deployPath $DeployPath -Type "SQL Driver"}
            $installPath = $localpath
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM