Difference between revisions of "Zabbix scripts"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
+ | # Get primary interface ip | ||
+ | ``` | ||
+ | (Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes).Name[-1] | ||
+ | (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq "$primaryInt"}).IPAddress | ||
+ | ``` | ||
+ | |||
+ | |||
+ | # Other | ||
``` | ``` | ||
powershell.exe -NoProfile -NoLogo -ExecutionPolicy Bypass -c "restart-service \"My Service\"" | powershell.exe -NoProfile -NoLogo -ExecutionPolicy Bypass -c "restart-service \"My Service\"" |
Revision as of 22:53, 23 May 2023
Get primary interface ip
(Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes).Name[-1] (Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq "$primaryInt"}).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;}}