本文介绍了如何从PowerShell中获取主机名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Powershell中为dur获取主机名?

How do I get the hostname for dur from powershell?

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,这将是首选输出.

The FQDN for the system is actually dur.bounceme.net, which would be the preferred output.

推荐答案

感谢bluuf将我设置在正确的轨道上:

Thanks to bluuf for setting me on the 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>

这篇关于如何从PowerShell中获取主机名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 11:08