本文介绍了如何从PowerShell中获取主机名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从Powershell中为dur获取主机名?
How do I get the hostname for dur from powershell?
PS /home/thufir/powershell> PS /home/thufir/powershell> ./hostname.ps1 google localhost PS /home/thufir/powershell> PS /home/thufir/powershell> cat ./hostname.ps1 $hosts = ("google", "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,这将是首选输出.
The FQDN for the system is actually dur.bounceme, 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 PS /home/thufir/powershell> PS /home/thufir/powershell> hostname dur PS /home/thufir/powershell>更多推荐
如何从PowerShell中获取主机名?
发布评论