I'm trying to automate the upgrading of Spotfire BI system on our Windows servers.
The instructions show a command that can be used to silently install which states the location of the executable file followed by all the required options/parameters as shown with this example:
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"
This does work, and as long as it preceded by the call operator (&), it runs well in PowerShell. However, I can't get it to work when running this on a remote server:
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
I can run the code contained in the function directly on the remote server and it works correctly. However, when I try and run it from the central server through WinRM/Invoke-Command
within a function, it fails giving me this error:
The term 'X:/downloads/spotfire/install.exe' is not recognized as the name of a cmdlet
Is it possible to run an executable using PowerShell on a remote server?
CodePudding user response:
Your executable path is based on a drive letter, X:
.
However, in remote sessions mapped drives (drives connected to network shares) aren't available by default, so you have two options:
Establish a (temporary) drive mapping with
New-PSDrive
before calling the executable (e.g.,$null = New-PSDrive X FileSystem \\foo\bar
)More simply, use the full UNC path of the target executable (e.g.
& \\foo\bar\downloads\spotfire\install.exe ...
)
If the target executable isn't actually accessible from the remote session, you'd have to copy it there first, which requires establishing a remote session explicitly and using Copy-Item
-ToSession
- see the docs for an example.