用于检查远程服务器的DNS IP的powershell脚本 [英] powershell script to check DNS IPs of remote server

查看:154
本文介绍了用于检查远程服务器的DNS IP的powershell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一些远程服务器,我想找到哪些是脚本中指定的主DNS和辅助DNS的远程服务器..我有写了一个powershell脚本来提取详细信息,但它给出了一些错误。你们能帮助我吗?我有
将所有远程服务器保存在.txt文件中,脚本将逐个选择并检查DNS并返回相同的内容。

I have some set of remote servers and I want to find which are the remote servers having primary and secondary DNS as specified in script.. i have written a powershell script to pull the details but it's giving some error. Would you guys help me. i have kept all the remote servers in a .txt file, script will pick one by one and check the DNS and return the same.

*****脚本启动***********

*****script start***********

$ ServerList = Get-Content" D:\ ***** \ Server.txt"
$


foreach($ Server in $ ServerList)

{

   ;  $ Info = Get-WmiObject Win32_networkadapterconfiguration -Computer $ Server

    if(($ Info.DNSServerSearchOrder -contains" XXX.XXX.XXX.XXX") - 或($ Info.DNSServerSearchOrder -contains" XXX.XXX.XXX.XXX"))

  ;      {

           $ Result + = Write-Output" $ server'n"

       }
}



写主机$结果

$ServerList = Get-Content "D:\*****\Server.txt"

foreach ($Server in $ServerList)
{
    $Info=Get-WmiObject Win32_networkadapterconfiguration -Computer $Server
    if(($Info.DNSServerSearchOrder -contains "XXX.XXX.XXX.XXX") -or ($Info.DNSServerSearchOrder -contains "XXX.XXX.XXX.XXX"))
       {
           $Result += Write-Output "$server 'n"
       }
}

Write-Host $Result

************脚本结束***************

************Script End***************

错误消息:

Get-WmiObject:无法验证参数'ComputerName'上的参数。参数为null或空。提供一个非空或空的参数

 然后再次尝试该命令。

在D:\ *** \DNS_List.ps1:5 char :68

+     $ Info = Get-WmiObject Win32_networkadapterconfiguration -Computer<<<<<  $ Server

    + CategoryInfo          :InvalidData :( :) [Get-WmiObject],ParameterBindingValidationException

    + FullyQualifiedErrorId:ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument
 that is not null or empty and then try the command again.
At D:\***\DNS_List.ps1:5 char:68
+     $Info=Get-WmiObject Win32_networkadapterconfiguration -Computer <<<<  $Server
    + CategoryInfo          : InvalidData: (:) [Get-WmiObject], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand

推荐答案

要避免该错误,您只需要消除空白行在您的文件中,或编写您的代码以忽略它们。 此外,您对Get-WmiObject的调用可能会返回多个结果,因此您可能需要另外一个循环。 试试这个:

To avoid that error, you just need to either eliminate the blank lines in your file, or write your code to ignore them.  Also, your call to Get-WmiObject may return multiple results, so you'll probably want another loop there.  Try this:


result = Get-Content" D:\ ***** \ Server。 TXT" |
ForEach-Object {
result = Get-Content "D:\*****\Server.txt" | ForEach-Object {


server =


这篇关于用于检查远程服务器的DNS IP的powershell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆