[英]how to get the HostName from powershell?
How do I get the hostname for dur
from powershell?如何从powershell获取dur
的主机名?
PS /home/thufir/powershell>
PS /home/thufir/powershell> ./hostname.ps1
google.com
localhost
PS /home/thufir/powershell>
PS /home/thufir/powershell> cat ./hostname.ps1
$hosts = ("google.com", "localhost")
foreach($i in $hosts) {
$fqdn = [System.Net.Dns]::GetHostEntry($i).HostName
write-host $fqdn
}
PS /home/thufir/powershell>
PS /home/thufir/powershell> hostname
dur
PS /home/thufir/powershell>
The FQDN for the system is actually dur.bounceme.net
, which would be the preferred output.系统的 FQDN 实际上是dur.bounceme.net
,这将是首选输出。
Thanks to bluuf for setting me on the right track :感谢 bluuf 让我走上正轨:
PS /home/thufir/powershell>
PS /home/thufir/powershell> [System.Net.Dns]::GetHostByName((hostname)).HostName
dur.bounceme.net
PS /home/thufir/powershell>
PS /home/thufir/powershell> hostname
dur
PS /home/thufir/powershell>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.