Find AD users with specific AD attribute NOT null
I'm looking for a script/Powershell command that will list all AD users that have a value not NULL in the teletexterminalidentifier attribute, so they must have a value set.
By default this attribute is not set but we have an app that modifies this attribute (to contain a hexadecimal string), so I'm looking for a list of all users that have this attribute set to something.
Thanks!
23 Answers
You should be able to get the users by using:
Get-ADUser -Filter 'teletexterminalidentifier -like "*"'You can then filter what you need by piping the command:
Get-ADUser -Filter 'teletexterminalidentifier -like "*"' | Select-Object name,teletexterminalidentifier | Export-Csv file.csvWhere Select-Object lets you select what fields you want to get the info from by name.
I think what you're looking for is the Where-Object cmdlet. Here's some pseudo code to help you:
Get-ADUser -Filter * | Where-Object {$_.teletexterminalidentifier -ne $null} | Export-Csv c:\list.csv 2 If you want to filter users based on this property, you have to add the -properties switch to the Get-ADuser Cmdlet. Indeed, without this switch, it loads only basic properties (members) for user objects.
Thus, here is the full command to achieve what you want :
Get-ADUser -filter * -Properties * | ? {$_.teletexterminalidentifier -ne $null} | Select-Object CN,SamAccountName,TeletexterminalidentifierIt will produce this kind of result :
Then you will be able to export the result into the desired format.
Hope this helps !