如何从powershell获取dur
的{{3}}?
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
,这将是首选输出。
答案 0 :(得分:1)
感谢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>