Welcome › Forums › General PowerShell Q&A › Remotely modify configuration file on 20 servers
- This topic has 3 replies, 3 voices, and was last updated 1 month ago by
Participant.
Viewing 3 reply threads
-
AuthorPosts
-
-
December 16, 2020 at 8:44 am #280176
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.
-
This topic was modified 1 month ago by
Bojan Zivkovic.
-
This topic was modified 1 month ago by
Bojan Zivkovic.
-
This topic was modified 1 month ago by
Bojan Zivkovic.
-
This topic was modified 1 month ago by
Bojan Zivkovic.
-
This topic was modified 1 month ago by
-
December 16, 2020 at 10:18 am #280248
Hmm I tried it on localhost as admin and it worked.
-
December 16, 2020 at 2:20 pm #280314PowerShell12345678# Create new file with config change, remove old file, then rename new fileInvoke-Command -ComputerName $servers -ScriptBlock {$old = ‘C:\ProgramData\VMware\Log Insight Agent\liagent.ini’ ;$new = ‘C:\ProgramData\VMware\Log Insight Agent\liagent2.ini’ ;(Get-Content -Path $old) -replace “(?<=^hostname=).*”,”NewServerName.domainname.local” |Set-Content -Path $new -Force ; Remove-Item $old ;Rename-Item -Path $new -NewName liagent.ini}
-
December 17, 2020 at 7:28 am #280476
It worked. Thx.
-
-
AuthorPosts
Viewing 3 reply threads
- You must be logged in to reply to this topic.