Powershell 命令无法通过 PSRemote 运行

Powershell commands not working via PSRemote

我在尝试通过 powershell 安装各种程序时遇到了一些问题。这是我构建的模块组件的示例(精简):

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

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

当我尝试通过

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

该命令似乎没有执行任何操作,因此我尝试使用 PSRemote 选项卡尝试获取更多详细信息,我使用了以下命令:

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

我收到回复说无法访问该文件或它不是有效文件。

T h i s i n s t a l l a t i o n p a c k a g e c o u l d n o t b e o p e n e d . V e r i f y t h a t t h e p a c k a g e e x i s t s a n d t h a t y o u c a n a c c e s s i t , o r c o n t a c t t h e a p p l i c a t i o n v e n d o r t o v e r i f y t h a t t h i s i s a v a l i d W i n d o w s I n s t a l l e r p a c k a g e .

当我将 RDP 连接到机器本身时,完全相同的命令可以正常工作。

我的研究表明这是一个双跃点问题,但如果没有将文件复制到机器上,有没有一种不可怕的处理方法?

我能够构建一个最小的解决方法,我在传递安装路径的远程调用之前放入了该方法。我还构建了一个函数以使其更易于管理,但我在此处放置了一个示例 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 "$DeployPathrd Party\Microsoft Visual C++ 2010 Redistributable"))
            {
                Copy-Item -Path "$installPathrd Party\Microsoft Visual C++ 2010 Redistributable" -Destination "$DeployPathrd Party\Microsoft Visual C++ 2010 Redistributable\" -Force -Recurse
            }
            If($ODBCDriver){Get-InstallerLocal -installPath $installPath -deployPath $DeployPath -Type "SQL Driver"}
            $installPath = $localpath
        }