2
votes

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 

enter image description here

PS C:\Users\aquib> $PSVersionTable.PSVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1
1
Don't post images with code... and add more details to the question! - Avshalom
@MohammadAquibAli please do not post important information in the comments, but in your question. They'll be much easier to read. - Robert Dyjas
Welcome as a new user to SO. Please take the tour and also read How to Ask. Edit the question to include addtional information, I did it only this time for you - so please delete your comments. - user6811411
The error is probably because you don't have the DnsClient module installed. - SIGSTACKFAULT
@MohammadAquibAli You don't. The DnsClient module does not exist prior to Windows Server 2012. - Bacon Bits

1 Answers

15
votes

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.