1

We have a Windows 2008 R2 Domain with multiple outgoing trusts. In this domain we add the users from the trusted domains to domain local security groups. It seems that some or all deleted accounts from the foreign domains remain in the groups after deletion (from the originating domain), leaving a SID in the group which cannot be resolved.

What is the easiest way to find such accounts and remove them from the groups?

0

I dont have a script handy. But personally I'd do something like this.

  1. Enumerate objects in the cn=foreignsecurityprincipals,dc=doamin,dc=com container to build list of FPO SIDs
  2. Use a batch file to iterate through each and do a psgetsid.exe (sysinternals) against SID to see if it resolves. 0 means can resolve and -1 means unavailable or possibly even cant contact correct DC
  3. If %errorlevel% is -1 write that "bad" SID to another file

you can go through the SIDs reported as -1 to see if you really want to delete the FPO represented. Deleting the FPO will clean up any membership its used in. YOu can use DSRM to script deleting the FPO later if desired using a for loop to iterate txt file.

  • Yeah, I figured out a similar approach, but I hoped for an easier way. Thanks – Tom Oct 20 '11 at 7:03
0

Here is a powershell script to remove orphan ForeignSecurityPrincipal for which the name cannot be resolved (which normally means the original object does not exist anymore).

But first ensure that if the ForeignSecurityPrincipal's name cannot be resolved it is not related to a communication problem with other domains.

If you are sure you want to remove all those principals, just remove the "-WhatIf" parameter from the Catch section, otherwise it just does a simulation.

$objForeignSecurityPrincipalList=Get-ADObject -Filter {ObjectClass -eq 'foreignSecurityPrincipal'}

foreach($objFSP in $objForeignSecurityPrincipalList)
{
    Try
    {
        $null=(New-Object System.Security.Principal.SecurityIdentifier($objFSP.objectSid)).Translate([System.Security.Principal.NTAccount])
    }
    Catch
    {
        Remove-ADObject -Identity $objFSP -WhatIf
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.