Problemas com o Invoke-Command ao instalar softwares no servidor remoto
Preciso instalar um aplicativo em vários servidores remotos no modo silencioso. Eu criei um script (Installer.ps1) como abaixo, usando o Powershell v3.0:
param(
[String] $ServerNameFilePath = $(throw "Provide the path of text file which contains the server names"),
[String] $InstallerFolderPath = $(throw "Provide the Installer Folder Path. This should be a network location"),
[String] $UserName = $(throw "Provide the User Name"),
[String] $Password= $(throw "Provide the Password")
)
Function InstallApp
{
$secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($UserName, $secpasswd)
$ScrBlock = {param($InstallerFolderPath) $ExePath = Join-Path $InstallerFolderPath "ServerReleaseManager.exe"; & $ExePath /q;}
Invoke-Command -ComputerName (Get-Content Servers.txt) -Credential $mycreds $ScrBlock -ArgumentList $InstallerFolderPath
}
InstallApp -ServerNameFilePath $ServerNameFilePath -InstallerFolderPath $InstallerFolderPath -UserName $UserName -Password $Password
Então chamo o script como abaixo (o caminho da pasta do Instalador pode ter espaços em branco e o executável ServerReleaseManager.exe aceita o argumento):
.\Installer.ps1 -ServerNameFilePath Servers.txt -InstallerFolderPath "\\TestServer01\Public\Stable Applications\Server Release Manager Update 2\2.7" -UserName "Domain\User" -Password "Test123"
Estou ficando abaixoCommandNotFoundException
sempre:
The term '\\TestServer01\Public\Stable Applications\Server Release Manager Update 2\2.7\ServerReleaseManager.exe' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Eu tentei outras opções como usar -FilePath
comInvoke-Command
mas mesmo erro. Eu estou realmente bloqueado aqui. Você pode me informar por que esse erro foi mostrado? Como resolver o erro? Ou existem maneiras melhores de lidar com isso. Obrigado pela ajuda.