Getting the computer host name?

Trying to export a file that has the computer name and description for all workstations on our company’s AD list.

Import-module ActiveDirectory
get-aduser -filter * -Properties ???,description |
select ???,description |
export-csv "c:\temp\workstations.csv" -NoTypeInformation

That’s the code I have so far, which works great, except that I have no idea what to put in that ??? space to get the computer name. I’ve tried everything I could think of, but nothing has worked. Help?

The User object does not have have an attribute for the user’s computer. There are methods for updating one of the other attributes to store this information using, for example, one of the ExtensionAttributes.

If you know that your organisation stores this data in the User object, you’ll have to identify which attribute you’re using yourself. The easiest way to do this is to find a user that you know has that attribute set then run:

Get-ADUser <username> -properties * | Select *

You can then identify from all the displayed properties which attribute(s) you’re using to store this data.

I see what you mean, but trying to do anything with <username> with literally any username only gets me RedirectionNotSupported errors.

<username> is a placeholder, you should replace it with the username of a user in your organisation. I used it to demonstrate that you want to get the attributes of a single user, not all users (-filter *) as you were doing previously.


Edit: to be clear, you should replace the whole thing, including the ‘<>’ with the username. As <> are redirection operators.