小编Am *_* Ba的帖子

等待状态服务Powershell

我已经编写了一个脚本来停止任何服务器上的服务!但是我得到了错误:

      YMethod invocation failed because[System.ServiceProcess.ServiceControllerStatus] does not contain a method   named 'WaitForStatus'.
    At C:\Admin\Scripts\JBoss_StartStopp\stoppa_alla_IX2 och IX3.ps1:18 char:7
    +       $getservicestatus.WaitForStatus("Stopped")
    +       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
Run Code Online (Sandbox Code Playgroud)

当您退出服务器上的服务时,我要等到该服务停止后再转到下一个服务器上的下一个服务!

   $serverlist = Get-Content “.\server.txt”
   $servicename = "JBoss_cambio"

   $serverlistIX3 = Get-Content “.\ix3.txt”
   $servicenameIX3 = "Laskopia_Cosmic"


  foreach ($server in $serverlist) {

$getservicestatus = (Get-Service -Name $servicename -ComputerName $server).status
if ($getservicestatus -eq "Running") {
  Set-Service -Name $servicename -ComputerName $server -Status Stopped

  $getservicestatusIX3.WaitForStatus("Stopped")

  Write-Host "$server $servicename Stoppad!" -ForegroundColor Green
  }
else …
Run Code Online (Sandbox Code Playgroud)

powershell scripting

1
推荐指数
1
解决办法
3667
查看次数

标签 统计

powershell ×1

scripting ×1