Difference between revisions of "Zabbix agent powershell scripts"

From UVOO Tech Wiki
Jump to navigation Jump to search
(Created page with "``` ``` $file = "C:\app\zabbix\zabbix_agent2.win.conf" $content = Get-Content $file -Encoding UTF8 -Raw $startString = "UserParameter=zbx.getIpaddr" $newString = "UserParamete...")
(No difference)

Revision as of 15:30, 26 July 2023

<br /><pre>$file = "C:\app\zabbix\zabbix_agent2.win.conf"
$content = Get-Content $file -Encoding UTF8 -Raw
$startString = "UserParameter=zbx.getIpaddr"
$newString = "UserParameter=zbx.getIpaddr,powershell.exe -NonInteractive -NoProfile -Command `"(Get-NetIPAddress -AddressFamily ipv4 | Where-Object -Property InterfaceAlias -EQ ((Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes)[-1]).Name ).IPAddress`""
$newcontent = ($content -replace "$startString.*?.*",$newString)
write-output $newcontent > $file