PowerShell无法识别命令Resolve-DnsName

Moh*_*Ali 1 powershell powershell-2.0

电源shell脚本出错,

Import-Module DnsClient 
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
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

Bac*_*its 12

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

我建议在该类中使用[System.Net.Dns]::GetHostEntry($HostnameOrIP)或使用其他一些非过时的静态方法.但是,这仅适用于A,AAAA和PTR记录,并且.Net Framework CLR中没有用于通用DNS请求的类.您必须自己动手或使用ARSoft.Tools.Net等第三方库.