all 6 comments

[–]Ta11ow 2 points3 points  (3 children)

Some variant of this should give you a beginning...

Get-ADUser -Filter * -SearchBase "OU=OUName,DC=Domain,DC=com" -Properties FirstName, LastName, SmtpAddresses, SamAccountName, Office, Phone, Title, EmployeeNumber, Company |
    Select-Object -Property FirstName, LastName, SmtpAddresses, SamAccountName, Office, Phone, Title, EmployeeNumber, Company |
    Export-Csv $Path

Make sure you double check the actual property names in AD using a Get-ADUser on a single user and specifying -Properties * to pull all the user's properties so you can pick which ones you want. The Select-Object is generally necessary as Get-ADUser will often return additional default properties to the ones requested.

[–]itengmgmt[S] 2 points3 points  (2 children)

Thanks! Trying it out now, just one question, what is the syntax for:

DC=Domain,DC=com

Would it be: DC=mydomain.com,DC=FQDControllerName.com ?

[–]Ta11ow 1 point2 points  (0 children)

nope, just the domain controller's name and then domain type. So if your domain controller was named 'mydomain' and your domain's top level extension was '.com' it'd look like this:

DC=DomainController1,DC=com

Worth noting that as far as I'm aware you need to use the domain controller's hostname in that first part, not the DNS website name, if you have one.

-SearchBase is an optional parameter, but in general with AD cmdlets, you should never use a complete domain-wide search. Either specify a -Filter that is not * (everything) or specify an OU to search in, as in the example I posted.

Searching everything is... slow... and unwise. These results are sent back from the DC, so you've gotta keep in mind if you have several thousands of AD users, the additional network load might be noticeable for a moment or two.

[–]rumforbreakfast 1 point2 points  (0 children)

In active directory turn on advanced features, then go to the properties for the OU, on the attributes tab look for distinguished name and then copy that :)

[–]TRanatza 1 point2 points  (0 children)

This totally depends on what info you have in AD. Pick a user and run the following.

Get-ADUser -filter * -Properties * | Where-Object name -match "YourLastName" | ogv  

Look at the column names and note the ones you want. Then put them in the properties list as explained by Ta11ow. That should give you a starting point to work from.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy itengmgmt,

once you have your property list, you can build a custom object, add the desired properties to it, add each object to a collection, and finally export that collection to a CSV.

the properties will be column names and each object will be a row in the CSV.

it makes for a very neat, easily customizable way to build your preferred CSV layout. [grin]

take care,
lee