Hey all, so trying to see if can get an extra hand on this…I am trying to pass a few variables into AD user attributes. Works for one user, but when add multiple users, it won’t pass separate objects. Not sure what I am missing…or better way to do this!
#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" }
}