using powershell to list active directory trusts

this is an easy concept to do for the current domain:

$myLocalDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()


$myLocalDomain.GetAllTrustRelationships()


 

it’s a little different if you want to do it for another domain, such as the root domain, for example:

$myRootDirContext = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext('domain',"myDomain.com")


$myRootDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetDomain([System.DirectoryServices.ActiveDirectory.DirectoryContext]$myRootDirContext)


$myRootDomain.GetAllTrustRelationships()

Comments

  1. Great tip !! .. may i add this to my PowershellTips database ?

    regards,
    Bernard Flach

    ReplyDelete
  2. certainly, bernard. thanks for the comment!

    ReplyDelete
  3. Just added. Thanks !
    http://www.powershelltips.org/list-active-directory-trusts/

    ReplyDelete
  4. Just added. Thanks !
    http://www.powershelltips.org/list-active-directory-trusts/

    ReplyDelete
  5. nice tip, but...
    we have like over 80 trusts (including NT trusts) and via that script i got only 47 (Outbound/Bidirectional/Inbound). i know, there are also some "not valid anymore", but i suppose, all trusts should be listed. any idea, what could be reason? thanx, Jiri

    ReplyDelete
  6. just small update. seems, like NT trusts couldnt be retrieved. trying to figure it out.

    ReplyDelete
  7. don't have any more of those unfortunately so i'm not sure what that's about. :/

    ReplyDelete
  8. I have the same issue with NT4 trusts. I have also used C# to attempt to list all the trusts. It seems as there is an issue with .Net listing the NT trusts. Has anyone figured out a solution using PS or C#?

    ReplyDelete

Post a Comment