对于FQDN
这台机器:
thufir@dur:~$
thufir@dur:~$ hostname --fqdn
dur.bounceme.net
thufir@dur:~$
是的...直接使用powershell
可以:FQDN
dur.bounceme.net
thufir@dur:~/powershell$
thufir@dur:~/powershell$ pwsh
PowerShell v6.0.1
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /home/thufir/powershell>
PS /home/thufir/powershell> [System.Net.Dns]::GetHostByName((hostname)).HostName
dur.bounceme.net
PS /home/thufir/powershell>
但是如果我想遍历一个数组呢?我如何获得FQDN
显示为dur.bounceme.net
?
thufir@dur:~/powershell$
thufir@dur:~/powershell$ ./hostname.ps1
dur.bounceme.net
beginning loop
google.com
Exception calling "GetHostEntry" with "1" argument(s): "No such device or address"
At /home/thufir/powershell/hostname.ps1:14 char:3
+ $fqdn = [System.Net.Dns]::GetHostEntry($i).HostName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ExtendedSocketException
google.com
localhost
end
thufir@dur:~/powershell$
脚本:
#!/usr/bin/pwsh -Command
#hostname is a reserved variable name?
[System.Net.Dns]::GetHostByName((hostname)).HostName
"beginning loop"
$hosts = ("google.com", "hostname", "localhost")
foreach($i in $hosts) {
$fqdn = [System.Net.Dns]::GetHostEntry($i).HostName
write-host $fqdn
}
"end"
我尝试从周围删除引号hostname
并添加美元符号$
。这是保留字?
解释所涉及术语的奖励积分。