Remotely modify configuration file on 20 servers

Welcome Forums General PowerShell Q&A Remotely modify configuration file on 20 servers

Viewing 3 reply threads
  • Author
    Posts
    • #280176
      Participant
      Topics: 41
      Replies: 47
      Points: 115
      Rank: Participant

      Hi, configuration file for Log Insight Agent product (liagent.ini) contains a line:

      hostname=OldServerName.domainname.local

      I want to modify it with new server name remotely with:

      Invoke-Command -ComputerName $servers -ScriptBlock {
      (Get-Content -Path ‘C:\ProgramData\VMware\Log Insight Agent\liagent.ini’) -replace “(?<=^hostname=).*”,”NewServerName.domainname.local” | Set-Content -Path ‘C:\ProgramData\VMware\Log Insight Agent\liagent.ini’ -Force
      }

      However as end result I got empty liagent.ini file. Doing this locally works fine. Any help would be appreciated.

       

    • #280248
      js
      Participant
      Topics: 32
      Replies: 852
      Points: 2,780
      Helping Hand
      Rank: Community Hero

      Hmm I tried it on localhost as admin and it worked.

    • #280314
      Participant
      Topics: 5
      Replies: 349
      Points: 632
      Helping Hand
      Rank: Major Contributor
    • #280476
      Participant
      Topics: 41
      Replies: 47
      Points: 115
      Rank: Participant

      It worked. Thx.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.