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...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
```
+
Replace Line in config
 
```
 
```
 
$file = "C:\app\zabbix\zabbix_agent2.win.conf"
 
$file = "C:\app\zabbix\zabbix_agent2.win.conf"
Line 6: Line 6:
 
$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`""
 
$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)
 
$newcontent = ($content -replace "$startString.*?.*",$newString)
write-output $newcontent > $file
+
Set-Content -Path $file -Value $newcontent
```
+
restart-service "zabbix Agent 2"
 +
get-content .\zabbix_agent2.log -tail 10
 +
get-service "zabbix Agent 2"
 
```
 
```

Latest revision as of 19:39, 26 July 2023

Replace Line in config

$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)
Set-Content -Path $file -Value $newcontent
restart-service "zabbix Agent 2"
get-content .\zabbix_agent2.log -tail 10
get-service "zabbix Agent 2"