linux - 如何从 powershell 获取主机名?

标签 linux powershell powershell-core

我如何获得 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/

相关文章:

linux - 如何在 Emacs lisp/config 中使用 unix 登录用户名?

c++ - 如何编译我的 C++ 项目?

javascript - 允许我通过网络浏览器编辑本地文件的 (Node.js) 应用程序?

Git 子模块命令在 Windows 10 上非常慢

powershell - 删除 HTML 中的区域

linux - 从本地到 Heroku 服务器的 SCP 文件

database - Powershell:Backup-Sqldatabase 无法解析路径

windows - 检查Powershell中是否存在多个目录,然后执行命令

regex - 在Powershell -match中,$ Match是否可以重用?

linux - 自定义提示在 Ubuntu 上的 PowerShell Core 6.0 中打印两次