PowerShell.exe -nologo -command "(Invoke-WebRequest -UseBasicParsing -TimeoutSec 25 -UseDefaultCredentials -Uri "https://www.zabbix.com/robots.txt" -ErrorAction Ignore -MaximumRedirection 0).StatusCode"
This example shows how to execute powershell command with pipe inside system.run[] key.Turns out pipe did not work out of the box. Instead I need to substitute every "
|" situations with "^|":
simulate curl via powershell:zabbix_agentd.exe -c zabbix_agentd.conf -t "system.run[PowerShell.exe -nologo -command \"(Invoke-WebRequest -TimeoutSec 25 -UseDefaultCredentials -Uri \"https://www.zabbix.com/robots.txt\" -ErrorAction Ignore -MaximumRedirection 0).StatusCode\"]"
test with agent:cd c:\zabbix
zabbix_agentd.exe -c zabbix_agentd.conf -t "system.run[PowerShell.exe -nologo -command \"Get-NetAdapter -Physical ^| % { $_.MacAddress }\"]"
Invoking PowerShell from UserParameter:UserParameter=get.software.version,PowerShell.exe -nologo -command "get-item \"C:\\Program Files (x86)\\ATOMI\\ActivePresenter\\ActivePresenter.exe\" | Select -ExpandProperty VersionInfo | Select FileVersion | ft -hidetableheaders"
To put the key at the server side:system.run[PowerShell.exe -nologo -command "$when=get-date; $when.addseconds(-600)"]
system.run[PowerShell.exe -nologo -command "(Get-ScheduledTask -TaskName \"CacheTask\" | % { $_.State })"]
Top CPU processes:PowerShell -nologo -command "Get-Process | Sort CPU -descending | Select -first 5"
Network adapters:Get-WmiObject -Namespace root\cimv2 -Query "select Name,Description,NetConnectionID,Speed,AdapterTypeId,NetConnectionStatus from win32_networkadapter where PhysicalAdapter=True and NetConnectionStatus > 0"