The FQDN
for this machine:
thufir@dur:~$
thufir@dur:~$ hostname --fqdn
dur.bounceme.net
thufir@dur:~$
Yes...working directly with powershell
gives the FQDN
of dur.bounceme.net
okay:
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>
but what if I want to iterate over an array? How do I get the FQDN
to show as 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$
script:
#!/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"
I've tried removing quote marks from around hostname
and prepending the dollar sign $
. This is a reserved word?
Bonus points for explaining the terminology involved.