Error on power shell script,
Import-Module DnsClient
Import-Module : The specified module 'DnsClient' was not loaded because no valid module file was found in any module directory. At line:1 char:1 + Import-Module DnsClient + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (DnsClient:String) [Import-Module], FileNotFoundException + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Resolve-DnsName
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 line:1 char:1 + Resolve-DnsName + ~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Resolve-DnsName:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\aquib> $PSVersionTable.PSVersion Major Minor Build Revision ----- ----- ----- -------- 2 0 -1 -1
Best Answer
Resolve-DnsName
is one of the commands added in Windows 8/Windows 2012 and later. By design, it is not available on versions of Windows prior to that regardless of which version of PowerShell you use. The command is unavailable on Windows 7 and Windows 2008 R2 and earlier. Most sources I've read say that the underlying WinAPI functions that the command depends upon were added in Windows 8/2012.I would recommend using
[System.Net.Dns]::GetHostEntry($HostnameOrIP)
or one of the other non-obsolete static methods in that class. However, that only works for A, AAAA, and PTR records, and there isn't a class in the .Net Framework CLR for generic DNS requests. You'd have to roll your own or use a third-party library like ARSoft.Tools.Net.