Is there an easy way in powershell 3.0 Windows 7 to get the local computer\'s ipv4 address into a variable?
I recently had the same issue. So I wrote a script to parse it from the ipconfig /all
output. This script is easily modifiable to obtain any of the parameters of the interfaces and it works on Windows 7 also.
LineNumber | Line
format$ip_config = $(ipconfig /all | % {$_ -split "
rn"} | Select-String -Pattern ".*" | select LineNumber, Line)
ipconfig
output) in LineNumber | Line
format$interfaces = $($ip_config | where {$_.Line -notmatch '^\s*$'} | where {$_.Line -notmatch '^\s'}) + $($ip_config | Select -last 1)
$LAN = $($interfaces | where {$_.Line -match 'Wireless Network Connection:$'})
$i = $interfaces.IndexOf($LAN)
$start = $LAN.LineNumber
$end = $interfaces[$i+1].LineNumber
start..end
$LAN = $ip_config | where {$_.LineNumber -in ($start..$end)}
$LAN_IP = @($LAN | where {$_ -match 'IPv4.+:\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'})
$LAN_IP = &{If ($LAN_IP.Count -gt 0) {$Matches[1]} Else {$null}}