I'm trying to get the SamAccountName or Name attribute of AD users given by a fixed list of EmployeeNumbers attribute, for which I made an Array, then I want to print all of the SamAccountName attributes on screen to copy them to a web program.
$EmpID=(57885,57718,57806,57607,59281,57790,60097,61103,60552,57862,60698,61321,57730,57402,58546,57871,57886,57669,55878,52052,57811,60106,60741,61050,59279,61053,60735,50718,51459,57805,52343,57716,60618,57908,58356,60619,50937,61204,61099,60517,61015,61123,56078,54103,57947,57861,57991,60547,57915,58559,57010,59285,61003,61016,51620,56383,60621)
foreach($usr in $EmpID){get-aduser -filter "EmployeeNumber -eq '$($usr).EmployeeNumber'" -properties Name}
So I get one of this error for each value in the $EmpID array.
Get-ADUser : No se encuentra ningún parámetro de posición que acepte el argumento 'EmployeeNumber = '60621''.
En línea: 3 Carácter: 2
+ {get-aduser where "EmployeeNumber = '$usr'" -Properties Name}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser