Difference between revisions of "Zabbix scripts"
Jump to navigation
Jump to search
Line 5: | Line 5: | ||
``` | ``` | ||
+ | ``` | ||
+ | (Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes).Name[-1] | ||
+ | (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq "$primaryInt"}).IPAddress | ||
+ | |||
+ | (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq ((Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes).Name[-1])}).IPAddress | ||
+ | ``` | ||
# Other | # Other |
Revision as of 23:32, 23 May 2023
Get primary interface ip
$primaryInt=(Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes).Name[-1] (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq "$primaryInt"}).IPAddress
(Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes).Name[-1] (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq "$primaryInt"}).IPAddress (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq ((Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes).Name[-1])}).IPAddress
Other
powershell.exe -NoProfile -NoLogo -ExecutionPolicy Bypass -c "restart-service \"My Service\""
powershell.exe -NonInteractive -NoProfile -Command "$keySet = @{};:loop while ($true){$adapters = Get-NetAdapter -Physical | Get-NetAdapterStatistics;foreach ($adapter in $adapters){if (-not $keySet.ContainsKey($adapter.Name)) {$null = $keySet.Add($adapter.Name,$adapter.ReceivedBytes)};if ($adapter.ReceivedBytes -ne $keySet[$adapter.Name]) {$myip = Get-NetIPAddress -InterfaceAlias $adapter.Name -AddressFamily ipv4;Write-Output -InputObject $myip.IpAddress;Break loop;}}}"
$ints=$((Get-NetAdapter -Physical | Get-NetAdapterStatistics).Name) foreach ($int in $ints){ (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq "$int"}).IPAddress }
$keySet = @{}; loop while ($true){$adapters = Get-NetAdapter -Physical | Get-NetAdapterStatistics;foreach ($adapter in $adapters){if (-not $keySet.ContainsKey($adapter.Name)) {$null = $keySet.Add($adapter.Name,$adapter.ReceivedBytes)};if ($adapter.ReceivedBytes -ne $keySet[$adapter.Name]) {$myip = Get-NetIPAddress -InterfaceAlias $adapter.Name -AddressFamily ipv4;Write-Output -InputObject $myip.IpAddress;Break loop;}}