2017-09-26 211 views
0

我在尝试通过PowerShell安装各种程序时遇到了一些问题。这是一个例子,我已经建立了模块的组件(下调):Powershell命令不能通过PSRemote工作

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\Install\3rd 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 e c o u l d o o t t o e e d e d d e。通过使用新的应用程序,您可以使用一个或多个应用程序来创建应用程序。在应用程序中创建应用程序时,您可以使用以下应用程序中的任何一种应用程序来创建应用程序。

当我将RDP放入机器本身时,完全相同的命令没有任何问题。

我的研究指出这是一个双跳的问题,但缺少将文件复制到机器,有没有办法处理这不是一场噩梦?

+1

'{-ScriptBlock TEST-INSTALL-脚本 - Basepath $ basepath -Arguments $ args}' - 这不起作用;请参阅:https://stackoverflow.com/q/36328690/478656和https://stackoverflow.com/q/40247384/478656和链接的问题 – TessellatingHeckler

+1

此外,为什么要在Powershell cmd.exe内调用'cmd.exe'/C msiexec/package \''$ basepath \''$ Arguments' - >'msiexec/package \'“$ using:basepath \'”$ Arguments' – BenH

+0

@BenH我使用cmd是因为有一些遗留工具还需要使用cmd进行安装,我发现保持相同的流动更容易(您只能看到修剪版本) – Jewtus

回答

0

我能够构建一个最小化的解决方法,即在通过安装路径的远程调用之前放入。我还内置了功能,使其更易于管理,但我把一个例子,如果这里声明(我建的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 
     }