#v0.1 - Initial build $version = "0.1" $scriptname = "ADPortTester" #import our logging module $Modules = @( "Media/ScriptRepository/Powershell$DevPath/Shared_Modules/Logging_Module.psm1" "Media/ScriptRepository/Powershell$DevPath/SQL_Installer_QC/QC_Module.psm1" "Media/ScriptRepository/Powershell$DevPath/Shared_Modules/Questions_Module.psm1" ) Import-MediaServerModule $Modules #Get the adapter config $PublicNic = Get-PublicNic -Quiet #Set the DNS address $FoundDNSAddress = $PublicNic.DNSServerSearchOrder[0] #Prompt user for DNS server $DNSAddress = Ask-Question -Question "Enter AD server IP address (For DNS address from Public adapter just hit enter)" -Default $FoundDNSAddress -RegexMatch "^\b(?:\d{1,3}\.){3}\d{1,3}\b" -Regex #Function for testing ports Function Test-ADPorts { Param ( [Parameter(Mandatory=$true)]$IP ) $Ports = 389,53,88,445,3268,135,139,636,464 ForEach ($Port in $Ports) { $result = $NULL $result = Test-TCPPort -IP $IP -Port $Port If ($result) { Write-Host "TCP Port $Port on $IP is contactable from $ENV:COMPUTERNAME" -ForegroundColor Green } ELSE { Write-Host "TCP Port $Port on $IP is NOT contactable from $ENV:COMPUTERNAME!!" -ForegroundColor Red } } } <# .Synopsis Short description .DESCRIPTION Long description .EXAMPLE Example of how to use this cmdlet .OUTPUTS Output from this cmdlet (if any) .NOTES General notes #> Function Test-TCPPort { Param ( #IP of device being tested. [Parameter(Mandatory=$true, Position=0)] [String]$IP, # Port to test. [Parameter(Mandatory=$true, Position=1)] [Int]$Port, # Timeout Value for test [Parameter(Position=2)] [Int]$Timeout = 1000 ) [Switch]$PortTest = $Null $ticksPerMilliSecond = 10000 $client = New-Object net.sockets.tcpclient $client.BeginConnect($IP,$port,$null,$null) > $null if ($client.Connected) {$client.Close();return $true} $startTimeout = Get-Date while ((Get-Date).Ticks - $startTimeout.Ticks -le $timeout * $ticksPerMilliSecond) { if ($client.Connected) { $client.Close() return $true } } $client.Close() return $false } #Test ports and output to screen Test-ADPorts -IP $DNSAddress #Call home to appstats New-AppStatsLogFile -scriptname $scriptname -version $version -device $env:COMPUTERNAME