powershell 命令扫描window 2012/2016/2019 windows 10 的电脑IP,DNS配置。

此脚本功能是为了扫描环境中的Windows server 2012,2016,2019 服务器的IP地址,DNS地址所生成的。功能比较实用简单。

 

是本人测试了多次,形成的一个脚本,值得收藏

 

$servers = Get-ADComputer -SearchBase "OU=Server,DC=123,DC=abc,DC=def,DC=com" -Filter * | where-Object{ $_.name -like "*youknow*" } | select -ExpandProperty name

$cred = Get-Credential

$scriptblock = {

$hostName = hostname

$sevDNSServerInfo = Get-DnsClientServerAddress -AddressFamily IPv4 -InterfaceAlias Ethernet | select -ExpandProperty ServerAddresses

$serArrayDNSinfo = ""

foreach($dns in $sevDNSServerInfo){ $serArrayDNSinfo = $serArrayDNSinfo + $dns + ";" }


$serverIPV4addr = (Get-NetIPConfiguration | select -ExpandProperty IPv4Address).IPAddress

$servercheckinfo = -Join( "$hostName",";", "$serverIPV4addr",";", "$serArrayDNSinfo")

$servercheckinfo
}

foreach($pc in $servers){
Invoke-Command -ComputerName $pc -ScriptBlock $scriptblock -Credential $cred
}

posted @ 2019-06-19 09:27  muchi  阅读(278)  评论(0)    收藏  举报