Solved

Powershell script to list AD users

Posted on 2013-06-21
8
514 Views
Last Modified: 2013-06-26
I need a Powershell script to list all users in AD with their OU location and basic account info. Currently I only need to know if the password is set to never expire but you can add other useful columns. The output shout go to txt or csv file. Thanks!
0
Comment
Question by:MisUszatek
8 Comments
 
LVL 68

Expert Comment

by:Qlemo
ID: 39266427
Is this Windows 2008R2 (or later)? If so, we can use the ActiveDirectory module and its Get-AD* cmdlets. If not, I recommend to get Quest ActiveRoles (free), and use their Get-QAD* cmdlets.
0
 

Author Comment

by:MisUszatek
ID: 39266436
It is 2008R2. I don't know much about PS so I need the exact script...
0
 
LVL 24

Expert Comment

by:Sandeshdubey
ID: 39266444
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 39266493
Import-Module ActiveDirectory
Get-ADUser -Filter * -Properties *

Open in new window

will list all info for all AD objects (groups and users). To get a specific property, like the Password Never Expires setting, put that instead of the * after -Properties:
Get-ADUser -Filter * -Properties PasswordNeverExpires | Select Name, Pass*

Open in new window

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 68

Expert Comment

by:Qlemo
ID: 39266499
It is always a good idea to ask PS for help:
  Get-Help Get-ADUser -detailed
or
 Get-Help Get-AD*
and to get the available properties
 Get-ADUser ExistingADUserHere -Properties *| get-member
(replace the user name, of course).
0
 

Author Comment

by:MisUszatek
ID: 39266671
@qlemo
What do I need to do to have a column that shows an OU where the user is located?
0
 

Expert Comment

by:willie0-360
ID: 39267085
I think you can get it by doing this on PowerShell V3 (might work on PowerShell v3):

Get-ADUser -Identity lastnameFirstInitial -Properties DistinguishedName

To get all the properties of a user:

Get-ADUser -Identity lastnameFirstInitial -Properties *

where lastnameFirstInitial is the username the user uses to log on to the Network.

If you are running Windows 2008 R2, you will need to import the AD  module by running:

import-module servermanager

Add-WindowsFeature -Name "RSAT-AD-PowerShell" -IncludeAllSubFeature



Thanks.
--Willie
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 350 total points
ID: 39268091
The OU is not available directly, only as part of the complete path.
CanonicalName is something like domain.com/TestOU/SubOU/UserName
DistinguishedName is then CN=UserName,OU=SubOU,OU=TestOU,DC=domain,dc=com
I will use CanonicalName, and add that to the command I showed already:
Get-ADUser -Filter * -Properties PasswordNeverExpires, CanonicalName | Select Name, Pass*, @{n='OU'; e={($_.CanonicalName -split '/')[-2]}}

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Synchronize a new Active Directory domain with an existing Office 365 tenant
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now