Solved

Powershell script to list AD users

Posted on 2013-06-21
8
520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 70

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 70

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
 
LVL 70

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 70

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

688 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