PowerShell无法识别命令Resolve-DnsName

时间:2018-07-19 12:57:00

标签: powershell powershell-v2.0

Power Shell脚本错误

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 个答案:

答案 0 :(得分:8)

Resolve-DnsName是Windows 8 / Windows 2012及更高版本中添加的命令之一。根据设计,无论您使用哪个版本的PowerShell,Windows之前的版本都不可用。该命令在Windows 7和Windows 2008 R2及更早版本上不可用。

我建议使用[System.Net.Dns]::GetHostEntry($HostnameOrIP)one of the other non-obsolete static methods in that class。但是,这仅适用于A,AAAA和PTR记录,并且.Net Framework CLR中没有用于通用DNS请求的类。您必须自己动手或使用第三方库,例如ARSoft.Tools.Net。