Solved

Powershell script to list AD users

Posted on 2013-06-21
8
517 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 69

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 69

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 69

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 69

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 …

786 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