Skip to main content

Posts

Showing posts from August, 2009

Get your current IP Address with Powershell

There are lots of ways to do this, but I haven't found an elegant one that works well. Here is my approach that queries the registry: [array] $IPArray = @() $Adapters = Get-Childitem "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Adapters" foreach ($uid in $Adapters) { if ($uid.PSChildName -ne "NdisWanIp") { $Interface = "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" + $uid.PSChildName ## Write-Host "Checking: $Interface" $IPs = Get-ItemProperty $Interface $IPArray += $IPs.DhcpIPAddress } } $IPArray You can change "$IPs.DhcpIPAddress" to "$IPs.IPAddress" if you have a static IP.