在不更改源文件的情况下传递新值,但添加到远程服务器的安装

时间:2017-02-15 18:11:04

标签: elasticsearch powershell-v3.0

更改winlogbeat.yml中的值,因为它传递给多个远程服务器。这是要更改的值> hosts:localhost:5044,当脚本在远程服务器上启动时,它将更改为> lp-index-QA.QA.com:9999

这是我写的脚本..没有失败,但没有将新值传递给远程服务器>>

#ExecutionPolicy 
     Set-ExecutionPolicy -Force Unrestricted

#DC = (facter datacenter) | Out-String
    $DC = 'parpr1'

    $QAhost = @("hosts: lp-index-QA.QA.com:9999", "`r`nhosts: localhost:5044")
    $PRODhost = @("hosts: lp-index-PROD.PROD.com:9999", "`r`nhosts:   localhost:5044")
    $file = 'C:\winlogbeat-1.2.3-windows\winlogbeat.yml'

    if ($DC -eq "QA")
 {
     Write-Host "Datacenter is $DC"

     Add-Content -PassThru -Path "$file" -Value "hosts: lp-index-QA.QA.com:9999"   
 }

      if ($DC -eq "PROD")

 {
      Write-Host "Datacenter is $DC"

      Add-Content -PassThru -Path "$file" -Value "hosts: lp-index- PROD.PROD.com:9999"   
 }


# delete service if it already exists
      if (Get-Service winlogbeat -ErrorAction SilentlyContinue) {
      $service = Get-WmiObject -Class Win32_Service -Filter     "name='winlogbeat'"
      $service.StopService()
      Start-Sleep -s 1
      $service.delete()
}

    $workdir = Split-Path $MyInvocation.MyCommand.Path

# create new service
    New-Service -name winlogbeat `
      -displayName winlogbeat `
      -binaryPathName "`"$workdir\\winlogbeat.exe`" -c   `"$workdir\\winlogbeat.yml`""

#pause 5s
    Start-Sleep -s 10

#Startingserver 

    Start-service winlogbeat

0 个答案:

没有答案