Author Posts

October 16, 2017 at 12:42 pm

Hi,

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

October 17, 2017 at 8:05 am

Someone now something about this ?

October 18, 2017 at 3:39 pm

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}

October 20, 2017 at 9:39 am

Hi,

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: (:) [Set-ADUser], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.SetADUser