6

Why is Resolve-DnsName not recognized for PowerShell Core? So far as I recall it works fine with PowerShell itself.

Is this a .NET versus dotnet problem? That dotnet simply doesn't have this functionality?

thufir@dur:~/powershell/webservicex$ 
thufir@dur:~/powershell/webservicex$ dotnet --version
2.1.4
thufir@dur:~/powershell/webservicex$ 
thufir@dur:~/powershell/webservicex$ ./dns.ps1 
Resolve-DnsName : The term 'Resolve-DnsName' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At /home/thufir/powershell/webservicex/dns.ps1:3 char:1
+ Resolve-DnsName -Name localhost -Type ANY | Format-Table -AutoSize
+ ~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Resolve-DnsName:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

thufir@dur:~/powershell/webservicex$ 
thufir@dur:~/powershell/webservicex$ cat dns.ps1 
#!/usr/bin/pwsh -Command

Resolve-DnsName -Name localhost -Type ANY | Format-Table -AutoSize

thufir@dur:~/powershell/webservicex$ 

see closed question also, and technet.

3 Answers 3

2

There is a cross-platform module called DnsClient-PS, and the name of the command in that module is Resolve-Dns. It functions a bit differently from Resolve-DnsName:

> Find-Module -Name PowerShellGet | Install-Module
> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted              https://www.powershellgallery.com/api/v2

> Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Trusted              https://www.powershellgallery.com/api/v2

> Install-Module -Name DnsClient-PS
> Resolve-Dns google.com | Select-Object -Expand Answers

DomainName  TimeToLive RecordClass RecordType RecordData
----------  ---------- ----------- ---------- ----------
google.com. 401        IN          A          64.233.185.102
google.com. 401        IN          A          64.233.185.139
google.com. 401        IN          A          64.233.185.138
google.com. 401        IN          A          64.233.185.113
google.com. 401        IN          A          64.233.185.101
google.com. 401        IN          A          64.233.185.100

1

From the What's New In PowerShell Core 6.0 documentation, in the "Backwards Compatibility" section:

Most of the modules that ship as part of Windows (for example, DnsClient, Hyper-V, NetTCPIP, Storage, etc.) and other Microsoft products including Azure and Office have not been explicitly ported to .NET Core yet. The PowerShell team is working with these product groups and teams to validate and port their existing modules to PowerShell Core. With .NET Standard and CDXML, many of these traditional Windows PowerShell modules do seem to work in PowerShell Core, but they have not been formally validated, and they are not formally supported.

While Powershell Core is GA, it is still very much a work in progress.

-1

In order to get the cmdlet Resolve-DnsName to work in PS 6 you must first import it or install it.

You can first try Install-Module -Name DnsClient. It will use your default package manager to pull it down from the psgallery and install it.

Then, Import-Module -Name "DnsClient" to pull it in.

You Resolve-DnsName cmdlet should then function.

You can also you use the various parameters of Test-NetConnection to resolve within the NetTCPIP module as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .