PowerShellã§ã¯ãHostName ã IP Address ãåå¾ããã®ã«ããã¤ãããæ¹ãèãããã¾ãã ä»åãPSRemotingä¸ã«åå¾ããã«å½ãã£ã¦ãã©ã®æ¹æ³ãæãå®è¡é度ãéãã®ãã測ã£ã¦ã¿ãã®ã§å ¬éãã¾ãã
Â
æ¤è¨¼ç°å¢
以ä¸ã åä¸Zoneã® Public VPCããPrivate VPC x2 ã«åãã¦10åå®è¡ããçµæã§ãåä¸ã¤ã³ã¹ã¿ã³ã¹ã«å¯¾ãã¦æãé ãã£ãæé(ms)ãåå¾ãã¦ãã¾ãã (ååã®DNS解決ã¯ICMPã§å¦çæ¸ã¿)
- PS Remoting æ¥ç¶å ãµã¼ãã¼ (Public VPC)
Amazon AWS EC2 ã¤ã³ã¹ã¿ã³ã¹ (m1.large) with Windows Server 2012
- PS Remoting æ¥ç¶å ãµã¼ãã¼ x 2 (Private VPC)
Amazon AWS EC2 ã¤ã³ã¹ã¿ã³ã¹ (m1.medium) with Windows Server 2012
HostName ãåå¾ãã
ã±ã£ã¨æãã¤ãããæ¹ã§4ã¤ããã¾ãã
- CIM (WMI) ããåå¾ãã
- ç°å¢å¤æ° $Env:COMPUTERNAME ããåå¾ãã
- Net.Dnsã§GetHostName()ã¡ã½ãããå©ç¨ãã
- hostnameã³ãã³ãããåå¾ãã
å®è¡ã³ãã³ãä¾
ãããããã®ããã«åå¾ã§ãã¾ãã
- CIM (WMI) ããåå¾ãã
(Get-CimInstance -Class Win32_ComputerSystem).Name
- ç°å¢å¤æ° $Env:COMPUTERNAME ããåå¾ãã
$Env:COMPUTERNAME
- Net.Dnsã§GetHostName()ã¡ã½ãããå©ç¨ãã
[Net.Dns]::GetHostName()
- hostnameã³ãã³ãããåå¾ãã
hostname
HostName åå¾å®è¡çµæ
ããããmeasure-commandã§ã®åå¾çµæã§ãã
CIM | Environment Variables | .NET | hostname |
(Get-CimInstance -Class Win32_ComputerSystem).Name | $Env:COMPUTERNAME | [Net.Dns]::GetHostName() | hostname |
389.68ms | 147.0818ms | 121.98ms | 165.8101ms |
.NETãæéã§ããã
Â
IP Address ãåå¾ãã
ã±ã£ã¨æãã¤ãããæ¹ã§3ã¤ããã¾ãã
- Get-NetIPAddress ããåå¾ãã
- Net.Dnsã§GetHostAddresses('').IPAddressToStringãå©ç¨ãã
- ipconfig ã³ãã³ãããåå¾ãã
å®è¡ã³ãã³ãä¾
å°ç´°å·¥ã3ã¤è¶³ãã¦ããããããã®ããã«åå¾ã§ãã¾ãã
- Get-NetIPAddress ããåå¾ãã
# 1. Ethernetã¨ã¢ããã¿åã®ã¤ããã®ãé¸æãã¦ãã¾ãã (Get-NetIPAddress | where{$_.InterfaceAlias -eq "Ethernet"}).IPAddress # 2. IP Addressã ããåå¾ããã渡ãã¨ãã«ã PowerShell V3.0 ã®çç¥è¨æ³ã§æ¸ã㨠(Get-NetIPAddress | where InterfaceAlias -eq "Ethernet" | select -ExpandProperty IPAddress) # 3. IP Addressã ããåå¾ããã渡ãã¨ãã«ã PowerShell V2.0 ã®è¨æ³ã§æ¸ã㨠Get-NetIPAddress | where{$_.InterfaceAlias -eq "Ethernet"} | select -ExpandProperty IPAddress
- Net.Dnsã§GetHostAddresses('').IPAddressToStringãå©ç¨ãã
#4. çºãã¦åå¾ [Net.Dns]::GetHostAddresses('').IPAddressToString #5. ãã ãããã§ã¯ãIPãè¤æ°åãã¦ãã¾ãã®ã§ãèªåã®IPã ããåå¾ãã¾ãã [Net.Dns]::GetHostAddresses('').IPAddressToString[1]
- ipconfig ã³ãã³ãããåå¾ãã
#6. æååæä½ (ç½ç® ipconfig | where{$_ -match "IPv4 Address. . . . . . . . . . . : (?.*)"} | %{$Matches.ip}
IP Address åå¾å®è¡çµæ
ããããmeasure-commandã§ã®åå¾çµæã§ãã PowerShellã³ãã³ãã¬ãããã
Summary | PowerShell | ||
Command | Get-NetIPAddress | Get-NetIPAddress V3è¨æ³ | Get-NetIPAddress V2è¨æ³ |
Duration | 1183.11 ms | 1200.11 ms | 1233.11 ms |
ç¶ãã¦ã.NET
Summary | .NET | |
Command | [Net.Dns]::GetHostAddresses() | [Net.Dns]::GetHostAddresses() [1] |
Duration | 189.55 ms | 289.31 ms |
æå¾ã«ipconfig
Summary | ipconfig |
Command | ipconfig |
Duration | 386.26 ms |
ã¾ããã¦ã.NETãæéã§ããã
ã¾ã¨ã
é度éè¦ãªã .NET å©ç¨ãæéã§ããã å¤é¨ã³ãã³ãããæ©ãã®ã¯æµç³ã§ããã PipeLine ã§ã¤ãªããããããã£ã¨åå¾ãããªã PowerShell Cmdletãªã®ã§ãããé度çã«ã¯ã¢ã¬ãªã®ã¯ä½æãã®éãã§ãã