webmourek
webmourek

Reputation: 59

GetADusers - with selected fields

I am trying to get all AD users into table in which the columns will be these fields:

samaccountname, name, useraccount control, employeeid, employeetype, distinguishedtype, title, department, manager, enabled, lockedout, passwordexpired, passwordlastset, passwordneverexpires, lastlogondate, whencreateddate, whenchanged, modified, accountexpirationdate, mail)

Then save it into excel/csv file

I tried this:

Get-ADUser -Filter | samaccountname, name, useraccount control, employeeid, employeetype, 
distinguishedtype, title, department, manager, enabled, lockedout, passwordexpired, 
passwordlastset, passwordneverexpires, lastlogondate, whencreateddate, whenchanged, 
modified, accountexpirationdate, mail

but i did not work well. Can someone help me with this script please?

Upvotes: 0

Views: 434

Answers (1)

Steven
Steven

Reputation: 7057

There are a few things. First you need to populate the -Filter argument. Second you need to tell Get-ADUser which properties to return. Third, you need to output it to a csv file.

Also "WhenCreatedDate" should just be "WhenCreated" and "DistinguishedType" should probably be "DistinguishedName". I fixed those but left you casing.

Something like below should get you close:

$Properties =
@(
    "samaccountname"
    "name"
    "useraccountcontrol"
    "employeeid"
    "employeetype"
    "distinguishedname"
    "title"
    "department"
    "manager"
    "enabled"
    "lockedout"
    "passwordexpired"
    "passwordlastset"
    "passwordneverexpires"
    "lastlogondate"
    "whencreated"
    "whenchanged"
    "modified"
    "accountexpirationdate"
    "mail"
)

Get-ADUser -Filter * -Properties $Properties | 
Select $Properties |
Export-Csv -Path "c:\temp\Accounts.csv" -NoTypeInformation

I'm not in a live environment, but tell me if this helps. Thanks.

Upvotes: 4

Related Questions