PowerShell Get-AdUser: Getting Started

Windows PowerShell Get-AdUser Cmdlet PowerShell Get-AdUser

With Get-AdUser you can either focus on one active directory account, or else employ a filter to get a custom list of many users.

Before giving an example of Get-AdUser, I have detail instructions for getting started with PowerShell’s Active Directory module.

Topics PowerShell Get-AdUser


Preparation: Before You Use Get-AdUser

Quick Checklist:
Logon at a Domain Controller
Install Active Directory Module for Windows PowerShell
Get the ISE (Optional)
Set-ExecutionPolicy (Optional)

Fine Detail Instructions
Naturally, you need an Active Directory domain to use these AD cmdlets; furthermore, I prefer to logon at a domain controller, at least for my first attempt to master the syntax of Get-AdUser.

The act of creating a domain should install the Active Directory Module for Windows PowerShell, and this is what supplies the AD family of cmdlets that are not found on Windows 7 machines.  If there is a problem, check that your DC has the Active Directory Web Services as this is what triggers the requisite PowerShell module installation.

# PowerShell Check for Active Directory Services
Get-Service ad*

Plan B: For Member Servers

Import, and Install Active Directory Module using PowerShell itself:

# PowerShell Install Active Directory Module
Import-Module ServerManager
Add-WindowsFeature RSAT-AD-PowerShell

Note: It is also possible to get Remote Server Administration Tools (RSAT) feature on Windows 7 or later; then install via the ‘Turn Windows features on’ wizard.

PowerShell ISE for Windows Server

You can get ISE for Windows Server 2008 or later by using the ‘Add feature’ wizard.  To launch PowerShell just search for ‘Power’ and choose the ISE (or plain) version.  Alternatively you could add the ISE GUI by using PowerShell itself.

# Install PowerShell ISE
Import-Module ServerManager; Add-WindowsFeature PowerShell-ISE

Add the Active Directory Module to Windows PowerShell ISE

The trick to getting the AD cmdlets to work in the ISE is to employ the Import-Module cmdlet.  That said, I remember that when I play chess if I find a good move, I try to look for a better one, in this instance add this command to your PowerShell profile.

# Install PowerShell ISE
Import-Module activedirectory

These instructions will help you edit your profile and append: Import-Module activedirectory

# PowerShell command to edit profile
If ((Test-Path $Profile) -eq "True") {Notepad $Profile}
Else {Write-Host "Still no profile file"}

Note: See more about PowerShell’s profile.

Guy Recommends:  SolarWinds’ Free Bulk Import ToolFree Download Solarwinds Bulk Import Tool

Import users from a spreadsheet.  Just provide a list of the users with their fields in the top row, and save as .csv file.  Then launch this FREE utility and match your fields with AD’s attributes, click and import the users.

Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.

If you need more comprehensive application analysis software,
Download a free trial of SAM (Server & Application Monitor)

Problem with PowerShell Scripts not Running

To cure error messages concerning scripts not running, try this command:

# PowerShell command to edit profile
Set-ExecutionPolicy -remoteSigned

Note: See other options for Set-Execution policy

Example: Get-AdUser -filter -Like

# PowerShell Active Directory Syntax
Get-AdUser -filter ‘name -Like "Admin*" ‘

Note:  Get-AdUser needs a parameter.  In this case we call for -filter, rather than -identity, -searchbase or the -LDAPFilter parameter.  The speech marks are crucial for this command; therefore let us look at the single and double quotes in isolation, ‘name -Like’ with the value, "Admin*", then sequence them as in the script above.

With -filter you can use other operators such as -eq and -NotLike.  For certain LDAP properties -lt or -gt make sense.  It is also possible to create a more complex query through the use of these two classic joiners: -And, -or.

Note: See more examples of Get-AdUser -filter

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

Troubleshooting PowerShell’s Get-AdUser

Firstly make sure that you are using Active Directory Module for Windows PowerShell.  Check with Get-Module.

Secondly, to research Get-AdUser call for Get-Help and examine syntax and study the examples.

# PowerShell Active Directory Syntax
Get-Help Get-AdUser -full

Summary of PowerShell Get-AdUser Cmdlet

This page is designed to help you get started with PowerShell’s active directory cmdlets.  There are two aspects to master, making the activedirectory module available, and then mastering the syntax of the -filter parameter.

If you like this page then please share it with your friends


See more PowerShell Active Directory Cmdlets

PowerShell Home  • Get-AdUser -filter  • Get-AdUser  • New-AdUser  • Get-AdComputer

Export-CSV  • Import CSV  • PowerShell Active Directory  • New-AdComputer

PowerShell Codeplex  • PowerShell Ad Cmdlets  • Free Import User CSVDE Tool

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.