Я пытаюсь запустить команду PowerShell, чтобы удалить WinPcap, но, попробовав разные методы, мне все еще не удалось? - PullRequest
0 голосов
/ 18 июня 2020

Ниже приведен сценарий, который я запускаю, который всегда выдает либо программную ошибку, либо The term 'x86' is not recognized as the name of a cmdlet error. Служба останавливается, но, похоже, проблема связана с Invoke-Command.

$Servers = Get-Content "C:\DTServerScript\Servers.txt"

ForEach ($Server in $Servers) {
  $Status = ""
  do 
  {
  #Stopping Service
    $ServiceAgent = Get-Service -ComputerName $Server | Where {$_.Name -like "*oneagent*"}
    Write-Host "Pending Stop on $Server"
    Stop-Service $ServiceAgent
    sleep 1
    $Status = $ServiceAgent.Status    
  } until ($Status -eq "Stopped")

  Write-Host "Service state is $Status on $Server"

  # Execute config change

  # Invoking Commands on Server
  Invoke-Command -ComputerName $Server {cmd.exe/ c:\Program Files (x86)\WinPcap\uninstall.exe /S }

  write-host "Service is starting on $Server"

  # Starting Service

  Start-Service $ServiceAgent
  $ServiceAgent = Get-Service -ComputerName $Server | Where {$_.Name -like "*oneagent*"}
  $Status = $ServiceAgent.Status
}

1 Ответ

0 голосов
/ 19 июня 2020

Попробуйте указать путь в кавычки и заключить в фигурные скобки имя, содержащее () ..

Invoke-Command -ComputerName $Server { & $Env:ComSpec /C "${Env:ProgramFiles(x86)}\WinPcap\uninstall.exe" /S }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...