问题
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>
The FQDN for the system is actually dur.bounceme.net
, which would be the preferred output.
回答1:
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>
来源:https://stackoverflow.com/questions/48806507/how-to-get-the-hostname-from-powershell