如何从PowerShell中获取主机名?

编程入门 行业动态 更新时间:2024-10-14 20:23:23
本文介绍了如何从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中获取主机名?

本文发布于:2023-11-28 13:45:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642649.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主机名   PowerShell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!