Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 257 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Powershell: Get FQDN Hostname

#11
to get the fqdn corresponding to the first IpAddress, it took this command:

```
PS C:\Windows\system32> [System.Net.Dns]::GetHostByAddress([System.Net.Dns]::GetHostByName($env:computerName).AddressList[0]).HostName
WIN-1234567890.fritz.box
```

where `[System.Net.Dns]::GetHostByName($env:computerName).AddressList[0]` represents the first IpAddress-Object and `[System.Net.Dns]::GetHostByAddress` gets the dns-object out of it.

If I took the winning solution on my standalone Windows, I got only:

```
PS C:\Windows\system32> (Get-WmiObject win32_computersystem).DNSHostName+"."+(Get-WmiObject win32_computersystem).Domain
WIN-1234567890.WORKGROUP
```

that's not what I wanted.
Reply

#12
(Get-ADComputer $(hostname)).DNSHostName
Reply

#13
Here's the method that I've always used:
```
$fqdn= $(ping localhost -n 1)[1].split(" ")[1]
```
Reply

#14
If you have more than one network adapter and more than one adapter is active (f.e WLAN + VPN) you need a bit more complex check. You can use this one-liner:

```powershell
[System.Net.DNS]::GetHostByAddress(([System.Net.DNS]::GetHostAddresses([System.Environment]::MachineName) | Where-Object { $_.AddressFamily -eq "InterNetwork" } | Select-Object IPAddressToString)[0].IPAddressToString).HostName.ToLower()
```
Reply

#15
How about: `"$env:computername.$env:userdnsdomain"`

This actually *only* works if the user is logged into a domain (i.e. no local accounts), logged into the same domain as the server, and doesn't work with disjointed name space AD configurations.

Use this as referenced in another answer:

$myFQDN=(Get-WmiObject win32_computersystem).DNSHostName+"."+(Get-WmiObject win32_computersystem).Domain ; Write-Host $myFQDN

Reply

#16
This worked in PS and PS Core on Windows (Tested on Versions 5.1 and 7.2)
```powershell
[System.Net.Dns]::Resolve($null).HostName
```
Reply

#17
# A cleaner format FQDN remotely
[System.Net.Dns]::GetHostByName('remotehost').HostName
Reply

#18
Using [Resolve-DNSName](

[To see links please register here]

) command this way works for **PowerShell 5.1** and **7.3** in my case.

```
(Resolve-DnsName -Name 'hostname').Name
```

## Supporting Resource

- [Resolve-DNSName](

[To see links please register here]

)


> **Description**
>
> The `Resolve-DnsName` cmdlet performs a DNS query for the specified
> name. This cmdlet is functionally similar to the nslookup tool which
> allows users to query for names.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through