Remove a Specific SIDhistory


I’m tried to delete some specific SIDHistory after a lot of migrations. I have a problem with my script because if some objects has more than 1 SIDHistory, it clear all of them and I don’t want that.

$SID_Recherche = S-1-5-21-2952651426-2628096683-2210756013
$CheminArborescence = "OU=TOTO, OU=TOTO, OU=_TOTO, DC=TEST, DC=local"

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -Force

#Import du module AD
Import-Module ActiveDirectory
Import-Module SIDHistory

Get-SIDHistory -SearchBase $CheminArborescence –DomainSID $SID_Recherche | export-csv C:\Users\A003634\Desktop\ScopedSIDHistory.csv

Get-SIDHistory -SearchBase $CheminArborescence  –DomainSID $SID_Recherche  | Remove-SIDHistory | Export-CSV C:\Users\A003634\Desktop\RemovedSIDhistory.csv

For example, I want to choose object with this SIDHistory S-1-5-21-2952651426-2628096683-2210756013 but if the object got many SIDHistory, it delete all of them.
How can I do it better ?

Thank you

Someone now something about this ?

I haven’t tested this but would this work?

$SID_Recherche = S-1-5-21-2952651426-2628096683-2210756013
$CheminArborescence = "OU=TOTO, OU=TOTO, OU=_TOTO, DC=TEST, DC=local"

Get-aduser -filter * -SearchBase $CheminArborescence | Set-ADUser $_ -Remove @{SIDHistory=$SID_Recherche}


I can’t because I need an Identity Parameters :

Set-ADUser : Impossible de valider l’argument sur le paramètre « Identity ». L’argument est null. Indiquez un argument non-null et réessayez.
Au niveau de ligne : 12 Caractère : 66

  • Get-aduser -filter * -SearchBase $CheminArborescence | Set-ADUser <<<< $_ -Remove @{SIDHistory=$SID_Recherche} | export-csv C:\Users\A003634\Desktop\ScopedSIDHistory.csv
    • CategoryInfo : InvalidData: (:slight_smile: [Set-ADUser], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.SetADUser


Anyone ?