Проблемы с Invoke-Command при установке программного обеспечения на удаленный сервер
Мне нужно установить приложение на нескольких удаленных серверах в тихом режиме. Я создал скрипт (Installer.ps1), как показано ниже, используя 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
Затем я вызываю скрипт, как показано ниже (путь к папке установщика может содержать пробелы, а исполняемый файл ServerReleaseManager.exe принимает аргумент):
.\Installer.ps1 -ServerNameFilePath Servers.txt -InstallerFolderPath "\\TestServer01\Public\Stable Applications\Server Release Manager Update 2\2.7" -UserName "Domain\User" -Password "Test123"
Я получаю нижеCommandNotFoundException
всегда:
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.
Я пробовал другие варианты, такие как использование -FilePath
сInvoke-Command
но та же ошибка. Я действительно заблокирован здесь. Подскажите, пожалуйста, почему эта ошибка показала? Как устранить ошибку? Или есть ли лучшие способы справиться с этим. Спасибо за вашу помощь.