我正在嘗試在我們的 Windows 服務器上自動升級 Spotfire BI 系統。
說明顯示了一個可用于靜默安裝的命令,該命令說明可執行檔案的位置,后跟所有必需的選項/引數,如本示例所示:
install.exe INSTALLDIR="<node manager installation dir>" NODEMANAGER_REGISTRATION_PORT=9080 NODEMANAGER_COMMUNICATION_PORT=9443 SERVER_NAME=SpotfireServerName SERVER_BACKEND_REGISTRATION_PORT=9080 SERVER_BACKEND_COMMUNICATION_PORT=9443 NODEMANAGER_HOST_NAMES=NodeManagerHostNames NODEMANAGER_HOST=NodeManagerHost -silent -log "C:\Users\user\Log file.log"
這確實有效,只要它前面有呼叫運算子 (&),它就可以在 PowerShell 中運行良好。但是,在遠程服務器上運行它時,我無法讓它作業:
function nodeManagerUpgrade {
Param([String]$ServiceName1,
[String]$InstallDirectory,
[String]$HostNames1
)
Stop-Service $ServiceName1
# this is the line that fails
& "X:/downloads/spotfire/install.exe" INSTALLDIR="$InstallDirectory" NODEMANAGER_REGISTRATION_PORT=17080 NODEMANAGER_COMMUNICATION_PORT=17443 SERVER_NAME=localhost SERVER_BACKEND_REGISTRATION_PORT=19080 SERVER_BACKEND_COMMUNICATION_PORT1=9443 NODEMANAGER_HOST_NAMES=$HostNames1 -silent -log "install.log"
}
Invoke-Command -ComputerName $NodeIP -ScriptBlock ${function:nodeManagerUpgrade} -argumentlist ($ServiceName,$InstallDirectory,$HostNames) -credential $credentials
我可以直接在遠程服務器上運行函式中包含的代碼,它可以正常作業。但是,當我嘗試通過WinRM/Invoke-Command一個函式從中央服務器運行它時,它無法給我這個錯誤:
The term 'X:/downloads/spotfire/install.exe' is not recognized as the name of a cmdlet
是否可以在遠程服務器上使用 PowerShell 運行可執行檔案?
uj5u.com熱心網友回復:
您的可執行路徑基于驅動器號X:.
但是,在遠程會話中,映射驅動器(連接到網路共享的驅動器)默認情況下不可用,因此您有兩種選擇:
New-PSDrive在呼叫可執行檔案(例如,$null = New-PSDrive X FileSystem \\foo\bar)之前建立(臨時)驅動器映射更簡單地說,使用目標可執行檔案的完整UNC路徑(例如
& \\foo\bar\downloads\spotfire\install.exe ...)
如果實際上無法從遠程會話訪問目標可執行檔案,則必須先將其復制到那里,這需要顯式建立遠程會話并使用- 請參閱檔案以獲取示例。Copy-Item -ToSession
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/437594.html
