Powershell to Create AD Trust
- Launch Powershell cmd prompt from the programs menu.
- Inside the cmd prompt , type Get-ADTrust
- if it fails – do this first : import-module activedirectory
Once you have the module, you should be able to run all AD commands. This should show you all the currently trusted domains on this DC.
- If the required DC does not show up, try to create a new trust using the PS script below.
Create New Trust
# Change following parameters$strRemoteForest = "forestName1.something"
$strRemoteAdmin = "adminAccountName"
$strRemoteAdminPassword = "Heslo@123"
$remoteContext = New-Object -TypeName"System.DirectoryServices.ActiveDirectory.DirectoryContext" -ArgumentList @( "Forest",$strRemoteForest, $strRemoteAdmin, $strRemoteAdminPassword)
try {
$remoteForest =[System.DirectoryServices.ActiveDirectory.Forest]::getForest($remoteContext)
#Write-Host "GetRemoteForest: Succeeded for domain $($remoteForest)"
}
catch {
Write-Warning "GetRemoteForest: Failed:`n`tError: $($($_.Exception).Message)"
}
Write-Host "Connected to Remote forest: $($remoteForest.Name)"
$localforest=[System.DirectoryServices.ActiveDirectory.Forest]::getCurrentForest()
Write-Host "Connected to Local forest: $($localforest.Name)"
try {
$localForest.CreateTrustRelationship($remoteForest,"Inbound")
Write-Host "CreateTrustRelationship: Succeeded for domain $($remoteForest)"
}
catch {
Write-Warning "CreateTrustRelationship: Failed for domain$($remoteForest)`n`tError: $($($_.Exception).Message)"
}
Leave a Reply