qshinoの日記

Powershell関係と徒然なこと

HostName, IPアドレス by powershell

ホスト名、IPアドレス取得

ホスト名

  1. [Net.Dns]::GetHostName()
  2. $Env:COMPUTERNAME
  3. hostname
  4. (Get-CimInstance -Class Win32_ComputerSystem).Name

IPアドレス

  1. Get-NetIPAddress
  2. [Net.Dns]::GetHostAddresses(‘’).IPAddressToString
  3. [Net.Dns]::GetHostAddresses(‘’).IPAddressToString[1]
  4. ipconfig | where{$_ -match “IPv4 Address… … … . . : (?.*)”} | %{$Matches.ip}

その他

Get-NetIPAddress | where{$_.InterfaceAlias -eq "Ethernet"} | select -ExpandProperty IPAddress

(Get-NetIPAddress | where InterfaceAlias -eq "Ethernet" | select -ExpandProperty IPAddress)

(Get-NetIPAddress | where{$_.InterfaceAlias -eq "Ethernet"}).IPAddress

参考

http://tech.guitarrapc.com/entry/2013/06/17/190601