OpsaC - Operating as PowerShell code
published: February 2, 2016 author: Tinu tags: Active Directory categories: Active Directory
Import-Module ActiveDirectory
$TrustedDomains = Get-ADTrust -Filter * | % {
$domain += $_.Target
[PSCustomObject]@{
Source=$_.Source
Target=$_.DistinguishedName
Name=$_.Name
TrustType=$_.TrustType
Direction=$_.Direction
}
}
$TrustedDomains | sort Name | ft -AutoSize
Import-Module ActiveDirectory
$domain = @()
Get-ADTrust -Filter * | select Source, Target, TrustType, Direction | % {
$domain += $_.Target
[PSCustomObject]@{
Source=$_.Source
Target=$_.Target
TrustType=$_.TrustType
Direction=$_.Direction
}
}
$domain |% {
Write-Output `n$_
try{
Get-ADDomain -Identity $_ | select -ExpandProperty ReplicaDirectoryServers -EA SilentlyContinue |% {
$dc= $_
}
}
catch [Exception]{
$dc= $($_.Exception.Message)
}
Write-Output $dc
}
netdom trust TrustingDomain.com /D:TrustedDomain.com /verify
netdom query /d:devgroup.example.com DOMAIN /verify
TCP Port Requirements for the Active Directory Domain Service:
UDP Port Requirements for the Active Directory Domain Service:
Active Directory and Active Directory Domain Services Port Requirements## Test Communication to Domain Controllers
#Download and install PsNetTools
$ZipFile = "https://github.com/tinuwalther/PsNetTools/releases/download/v0.7.5/PsNetTools.zip"
$OutFile = "$($env:USERPROFILE)\Downloads\PsNetTools-v0.7.5.zip"
Invoke-WebRequest -Uri $ZipFile -OutFile $OutFile
$ExpandFolder = "$($env:USERPROFILE)\Downloads\PsNetTools"
if(-not(Test-Path $ExpandFolder)){$null = mkdir $ExpandFolder}
Expand-Archive -Path $OutFile -OutputPath $ExpandFolder -Force
Copy-Item -Path $ExpandFolder -Destination "C:\Program Files\WindowsPowerShell\Modules" -Recurse -Force -PassThru
#Test ports with PsNetTools
$TargetDC = 'your target Domain Controller'
$TcpPort = @(389,636,3268,3269,88,53,445,25,135,5722,464,9389,139,49152..65535)
Test-PsNetTping -Destination $TargetDC -TcpPort $TcpPort -MaxTimeout 1000 | Format-Table
$UdpPort = @(389,88,53,445,123,464,138,67,2535,137,49152..65535)
Test-PsNetUping -Destination $TargetDC -TcpPort $UdpPort -MaxTimeout 1000 | Format-Table