Powershell get ipv4 address into a variable

后端 未结 12 2291
长情又很酷
长情又很酷 2021-01-31 08:23

Is there an easy way in powershell 3.0 Windows 7 to get the local computer\'s ipv4 address into a variable?

12条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-31 09:11

    Another variant using $env environment variable to grab hostname:

    Test-Connection -ComputerName $env:computername -count 1 | Select-Object IPV4Address
    

    or if you just want the IP address returned without the property header

    (Test-Connection -ComputerName $env:computername -count 1).IPV4Address.ipaddressTOstring
    

提交回复
热议问题