2017-09-26 189 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 
     }