Skip to content

Instantly share code, notes, and snippets.

@kskmori
Created November 16, 2018 05:39
Show Gist options
  • Save kskmori/0665459c702003d7141ddaf0943b7615 to your computer and use it in GitHub Desktop.
Save kskmori/0665459c702003d7141ddaf0943b7615 to your computer and use it in GitHub Desktop.
# invoke as:
# powershell -NoProfile -ExecutionPolicy Unrestricted -NonInteractive .\findif.ps1
#
Param(
[Parameter(Mandatory=$True,Position=1)][string]$IPAddress,
[Parameter(Mandatory=$True,Position=2)][string]$InterfaceAddress
)
# check if the ipaddr is already assigned
$ifindex = (Get-NetIPAddress | where IPAddress -eq $IPAddress).InterfaceIndex
Write-Host "ifindex = " $ifindex
if ($ifindex -eq $null) {
# find the interface by InterfaceAddress
$ifindex = (Get-NetIPAddress | where IPAddress -eq $InterfaceAddress).InterfaceIndex
Write-Host "ifindex = " $ifindex
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment