locked
How to Get Duplicate Filed in AD Object {Description} ? RRS feed

  • Question

  • Hello,

    In our environment, users are being created through systems which writes directly into our AD in a specific OU. These accounts are created and have different SAMAccountName, different email ID "Personal" and the Description field is populated with the Student ID.

    When the Applicants "user's created through Apply Online System"  become students, we create AD-Object with SAMAccountName same as StudentID and we populate the Description Field with the StudentID.But the only different is the SAMAccountName from the AD-Object created via the Apply Online System.

    The purpose of this is to delete the AD-Objects created by the Apply Online System. How can I get the duplicate object that was created by the Apply Online System..?

    I have a full list of the New-Intake Students, and using the StudentID "Which we created" to find the AD-Object with Description ID similar to the StudentID and fetch the SamAccountName of it..!!!

    $MCPSTU = Import-Csv Path C:\Scripts\1920MCP.csv
    $Live = Import-csv -Path "C:\Scripts\AllQuercsuLive.csv"
    
    
    #Compare-Object $MCPSTU $Live -property Description | Export-Csv -NoTypeInformation -Path "C:\Scripts\MCP-DUP.csv" -IncludeEqual | where-object {($_.SideIndicator -eq "=>") -or ($_.SideIndicator -eq "<=") } | Export-csv C:\Output\Difference.csv –NoTypeInformation
    
    

    $Path = "C:\Scripts"
    $UserList = Import-Csv -Path "$($path)\AllQuercsuLive.csv"
    $UserData = Import-Csv -Path "$($path)\1920MCP.csv"
    
    foreach ($User in $UserList)
    {
        ForEach ($Data in $UserData)
        {
            If($User.SamAccountName -eq $Data.SamAccountName)
            {
              
                $Data
            }
        }
    }
    

    But I'm not able to make it.. !!

    Appreciate your help on this please.

    Regards,

    Tuesday, November 5, 2019 12:33 PM

Answers

  • Problem Solved;

    This Code reads the CSV File which contains two header;

    Description and SamAccountName


    #CSV File contains Description and SamAccountName

    $Stud = Import-Csv C:\Scripts\FY2020.csv ForEach($User in $Stud) {

    #Hold the Description Array $Stud.Description $Stud.SamAccountName

    #Get User from the SearchRoot Location and retrive the found account that's similar to the one in the CSV File

    Get-QADUser -SizeLimit 0 -Properties * -SearchRoot "Domain/DomainUsers/Quercus/Live Users" | Where {$_.Description -Like $Stud.Description} | Select Name, Description, SamAccountName,CanonicalName }




    • Edited by hms_24 Wednesday, November 6, 2019 9:18 AM Removed | Select Description
    • Marked as answer by hms_24 Thursday, November 7, 2019 9:25 AM
    Wednesday, November 6, 2019 8:48 AM

All replies

  • You said the Student ID is put in the description field from the online application, so why not search that field for the student ID and delete that object? Also, why create new user objects and delete the others? Just move them to the proper OU and change the SamAccountName to be the student ID.

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''


    • Edited by clayman2 Tuesday, November 5, 2019 12:50 PM typo
    Tuesday, November 5, 2019 12:49 PM
  • Hi,

    Thanks for your question.

    Do you mean you want to delete the ad users created by the Apply Online System? And the aduser's samaccountname same as the student id.

    If you have the student ID list, you can try the script below:

    get-content c:\StudentId.txt | foreach-object {get-aduser $_ 
     | remove-adobject -confirm:$false}

    Best regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, November 6, 2019 6:31 AM
  • You said the Student ID is put in the description field from the online application, so why not search that field for the student ID and delete that object? Also, why create new user objects and delete the others? Just move them to the proper OU and change the SamAccountName to be the student ID.

    I have the ID for those becomes students... I need to find the duplicated account that was created by the Apply Online System which belongs to each one and delete it.

    The reason why I can't use the Object that was created via the Apply Online System, because its not created properly and I can't create email account for it. When I try to replicate it to o365, all of them returns error related to SID identifier. That's the reason, creating a fresh object worth all the  time to resolve other SID issues.


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''



    Wednesday, November 6, 2019 6:54 AM
  • Hi,

    Thanks for your question.

    Do you mean you want to delete the ad users created by the Apply Online System? And the aduser's samaccountname same as the student id.

    If you have the student ID list, you can try the script below:

    get-content c:\StudentId.txt | foreach-object {get-aduser $_ 
     | remove-adobject -confirm:$false}

    Best regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Hi Lee,

    This will find the existing users and delete them :)

    I would rather use something like this, but it doesn't work..

    Get-Content -Path C:\Scripts\MCP2020.txt | ForEach-Object{Get-QADUser -SearchScope "Domain.Com/DomainU
    sers/Quercus/Live Users" -Identity $_}

    The MCP2020.txt file contains the actual students Objects "The one which we created".

    I need to find similar Student ID in the SearchScope location "Different OU". Then I can fetch the SamAccountName, and delete the unwanted objects.

    Regards,

    Wednesday, November 6, 2019 7:05 AM
  • Hi All,

    $UsrDesc = Get-QADUser -SizeLimit 0 | Select Description, SamAccountName

    In another word, how can I find AD-Object with same Description Field.. If($upn.Description -eq '$UsrDesc') = Out Result the duplicated object and get it's samAccountName.

    Appreciate your help.

    Regards,

    Wednesday, November 6, 2019 7:38 AM
  • You have to use the SearchBase parameter to set Active Directory path to search under and provide distinguished name (DN) of the OU instead of canonical path.

    Get-Content -Path C:\Scripts\MCP2020.txt | ForEach-Object {
    Get-ADUser -SearchBase "OU=Live Users,OU=Quercus,OU=DomainUsers,DC=Domain,DC=COM" -Identity $_  | Remove-ADObject -confirm:$false
    }
    Wednesday, November 6, 2019 7:43 AM
  • Sorry, it doesn't work..

    Regards,

    Wednesday, November 6, 2019 7:55 AM
  • Problem Solved;

    This Code reads the CSV File which contains two header;

    Description and SamAccountName


    #CSV File contains Description and SamAccountName

    $Stud = Import-Csv C:\Scripts\FY2020.csv ForEach($User in $Stud) {

    #Hold the Description Array $Stud.Description $Stud.SamAccountName

    #Get User from the SearchRoot Location and retrive the found account that's similar to the one in the CSV File

    Get-QADUser -SizeLimit 0 -Properties * -SearchRoot "Domain/DomainUsers/Quercus/Live Users" | Where {$_.Description -Like $Stud.Description} | Select Name, Description, SamAccountName,CanonicalName }




    • Edited by hms_24 Wednesday, November 6, 2019 9:18 AM Removed | Select Description
    • Marked as answer by hms_24 Thursday, November 7, 2019 9:25 AM
    Wednesday, November 6, 2019 8:48 AM
  • that's real strange... When more than one user account is populated, its longer to process..

    Wednesday, November 6, 2019 9:10 AM