Created
October 4, 2024 00:42
-
-
Save Jaid/0da15d0c1038531346a2d25d5f25a94d to your computer and use it in GitHub Desktop.
Get best local IPv4 address in PowerShell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex (Get-NetRoute -DestinationPrefix '0.0.0.0/0' | Where-Object { (Get-NetAdapter -InterfaceIndex $_.InterfaceIndex).InterfaceType -eq 6 } | Sort-Object Metric | Select-Object -First 1).InterfaceIndex | Where-Object { $_.IPAddress -notlike '127.*' }).IPAddress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment