我如何获得 hostname对于来自 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>
系统的 FQDN 实际上是 dur.bounceme.net
,这将是首选输出。
最佳答案
感谢 bluuf 让我加入 right track :
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>
关于linux - 如何从 powershell 获取主机名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48806507/