Hello all, wanted to see about a hand on this script. I am trying to pass a couple variables into AD user attribute. It works when targeting one user, but when I add multiple it fails, or adds all values for each user. Not sure what I am missing, or if there is a better way to do this…thanks
#Establishing Search Base OU $Base = "OU=TST,OU=IT,DC=domain,DC=com #Query and Set Values Replacement Attributes $GivenName = (Get-ADUser -SearchBase $Base -Filter { (idautoPersonPreferredName -notlike "*") -and (idautoPersonPreferredLastName -notlike "*") -and (enabled -eq $true) } -Properties GivenName).GivenName; $SurName = (Get-ADUser -SearchBase $Base -Filter { (idautoPersonPreferredName -notlike "*") -and (idautoPersonPreferredLastName -notlike "*") -and (enabled -eq $true) } -Properties Surname).Surname; $User = (Get-ADUser -SearchBase $Base -Filter { (idautoPersonPreferredName -notlike "*") -and (idautoPersonPreferredLastName -notlike "*") -and (enabled -eq $true) } -Properties "Name").Name; #Set User Attributes ForEach-Object { Set-ADUser -Identity "$User" -Replace @{ idautoPersonPreferredName="$GivenName";idautoPersonPreferredLastName="$SurName" } }