I am new to PowerShell and trying to accomplish few things here:
- I have a zabbix agent configuration file and I want to be able to change the zabbix_agent_win.conf.
- Hostname
- ServerActive
- HostMetaDataItem
My ultimate goal is to be have a powershell script that will change the Hostname based on "$env:ComputerName" and ServerActive is to change with given parameter, HostMetaData with given parameter either env variable that can be populated with given cmdlet. I started playing around and came across with the following script:
$path = "C:\test.conf"
$word = $(Hostname)
$replacement = $("$env:ComputerName")
$text = get-content $path
$newText = $text -replace $word,$replacement
$newText > $path
However this script is not working for me and different combination which I have tried is not changing the value of hostname based on ("$env:ComputerName”).
I found another suggested option:
(Get-Content C:\test.conf -Raw).Replace('\$Hostname$\','\"$env:ComputerName"\') |
Set-Content C:\test.conf
No luck yet,
Any help appreciated.
Thanks, Katherine