This script follows these steps :

  • scan the Active Directory domain
  • retrieve all Server names (OS name like “Windows*Server*”)
  • ping the server name to check if it is alive
  • if the ping is successfull, a WMI request get the following informations about the network configuration of the server :
    • Netbios over TCP/IP option
    • LMHost lookup option
    • WINS Servers (primary and secondary)

I have written this script to identify all servers with Netbios over TCP/IP enabled or LMHost lookup enabled or with WINS servers configured. The purpose is to dismiss the WINS environment and standardize the server network configuration without Netbios over TCP/IP (use only the TCP port 445 and not the TCP port 137,138 and 139)

Script (with Microsoft Active Directory module loaded : import-module activedirectory) :

$server_list =Get-Adcomputer -LDAPFilter "(operatingsystem=Windows*Server*)"
ForEach($ServerName In $server_list){
	$hostname = $ServerName.Name
	$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$hostname'" | Select-Object StatusCode
	If ($PingStatus.StatusCode -eq 0){
		write-host $hostname " : "-NoNewline
		$QueryString = Gwmi Win32_NetworkAdapterConfiguration -Comp $hostname -Filter "IPEnabled=TRUE and DHCPEnabled=FALSE"
		if (($QueryString.TcpipNetbiosOptions -eq 0) -or ($QueryString.WINSEnableLMHostsLookup -eq "True") -or ($QueryString.WINSPrimaryServer) -or ($QueryString.WINSSecondaryServer)) {
			write-host $QueryString.TcpipNetbiosOptions "`t" $QueryString.WINSEnableLMHostsLookup "`t" $QueryString.WINSPrimaryServer "`t" $QueryString.WINSSecondaryServer -ForegroundColor Red
		}
		else {
			write-host "Network configuration OK" -ForegroundColor Green
		}
	}
}

Script (with Quest Active Directory module) :

$server_list = Get-QADComputer -OSName "Windows*Server*"
ForEach($ServerName In $server_list){
	$hostname = $ServerName.Name
	$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$hostname'" | Select-Object StatusCode
	If ($PingStatus.StatusCode -eq 0){
		write-host $hostname " : "-NoNewline
		$QueryString = Gwmi Win32_NetworkAdapterConfiguration -Comp $hostname -Filter "IPEnabled=TRUE and DHCPEnabled=FALSE"
		if (($QueryString.TcpipNetbiosOptions -eq 0) -or ($QueryString.WINSEnableLMHostsLookup -eq "True") -or ($QueryString.WINSPrimaryServer) -or ($QueryString.WINSSecondaryServer)) {
			write-host $QueryString.TcpipNetbiosOptions "`t" $QueryString.WINSEnableLMHostsLookup "`t" $QueryString.WINSPrimaryServer "`t" $QueryString.WINSSecondaryServer -ForegroundColor Red
		}
		else {
			write-host "Network configuration OK" -ForegroundColor Green
		}
	}
}
Get server network configuration using WMI

Leave a Reply

Your email address will not be published.