?
Solved

Powershell script to list AD users

Posted on 2013-06-21
8
Medium Priority
?
522 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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 1400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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.
Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

764 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