Difference between revisions of "Zabbix scripts"

From UVOO Tech Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
# Get primary interface ip
 
# Get primary interface ip
 +
```
 +
powershell.exe -NonInteractive -NoProfile -Command '(Get-NetIPAddress -AddressFamily ipv4 | Where-Object {$_.InterfaceAlias -eq ((Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes)[-1]).Name }).IPAddress'
 +
```
 +
 +
or using double quotes
 +
```
 +
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"
 +
```
 +
 +
# More
 +
```
 +
powershell.exe -NonInteractive -NoProfile -Command '(Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq ((Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes).Name[-1])}).IPAddress'
 +
```
 +
 
```
 
```
 
$primaryInt=(Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes).Name[-1]
 
$primaryInt=(Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes).Name[-1]

Latest revision as of 00:41, 24 May 2023

Get primary interface ip

powershell.exe -NonInteractive -NoProfile -Command '(Get-NetIPAddress -AddressFamily ipv4 | Where-Object {$_.InterfaceAlias -eq ((Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes)[-1]).Name }).IPAddress'

or using double quotes

 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"

More

powershell.exe -NonInteractive -NoProfile -Command '(Get-NetIPAddress | Where-Object {$_.InterfaceAlias -eq ((Get-NetAdapter -Physical | Get-NetAdapterStatistics | Sort-Object -Property SentBytes).Name[-1])}).IPAddress'
$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;}}