If you can create a CSV file with relevant userdata from the students you want to get the cardnumbers for, something like this:
"SamAccountName", "PossibleOtherData"
"jdoe", "something worth knowing"
"jtrump", "no. 1 snooker player"
You can use that to do the following:
$users = Import-Csv -Path 'PathToYourCsvFile' | Select-Object -ExpandProperty SamAccountName
# or shorter: $users = (Import-Csv -Path 'PathToYourCsvFile').SamAccountName
$students = Get-ADUser -Filter "extensionAttribute11 -like '*'" -Properties DisplayName, extensionAttribute11 |
Where-Object { $users -contains $_.SamAccountName } |
Select-Object DisplayName, @{Name = 'CardNumber'; Expression = { $_.extensionAttribute11}}
# display on screen
$students
# write to new CSV file
$students | Export-Csv -Path 'PathToYourOutputCsvFile' -UseCulture -Encoding UTF8 -NoTypeInformation
Worth knowing is that the Get-ADUser cmdlet will by default return objects with these properties: DistinguishedName, Enabled, GivenName, Name, ObjectClass, ObjectGUID, SamAccountName, SID, Surname, UserPrincipalName. All extra properties you need to ask for using the -Properties parameter.
Also, you can make the code faster if you have a searchbase OU to look for the students. If all students are in a dedicated OU, you can add for instance this -SearchBase "OU=Students,OU=UserAccounts,DC=YourCompany,DC=org" to the Get-ADUser cmdlet
If you have located all your students inside a dedicated OU or Group, there should be no need to create a CSV file first and below should do it:
In case all your students can be found in the same OU:
# put the DistinguishedName of the OU here
$ouDN = "OU=Students,OU=UserAccounts,DC=YourCompany,DC=org"
$students = Get-ADUser -Filter "extensionAttribute11 -like '*'" -SearchBase $ouDN -Properties DisplayName, extensionAttribute11 |
Select-Object DisplayName, @{Name = 'CardNumber'; Expression = { $_.extensionAttribute11}}
# display on screen
$students
# write to new CSV file
$students | Export-Csv -Path 'PathToYourOutputCsvFile' -UseCulture -Encoding UTF8 -NoTypeInformation
If all students are members of an AD group like for instance "Students", you could do:
$students = Get-ADGroupMember -Identity "Students" -Filter "objectClass -eq 'user'" |
Get-ADUser -Properties DisplayName, extensionAttribute11 |
Where-Object { $_.extensionAttribute11 -like '*' }
Select-Object DisplayName, @{Name = 'CardNumber'; Expression = { $_.extensionAttribute11}}
# display on screen
$students
# write to new CSV file
$students | Export-Csv -Path 'PathToYourOutputCsvFile' -UseCulture -Encoding UTF8 -NoTypeInformation