Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Active Directory / Get-ADUser: Find Active Directory User Info with PowerShell

April 3, 2023 Active DirectoryPowerShellWindows Server 2019

Get-ADUser: Find Active Directory User Info with PowerShell

The Get-ADUser PowerShell cmdlet allows you to get information about an Active Directory user, its attributes, and search among domain users. It is one of the more popular PowerShell cmdlets for getting information from AD. Using the Get-ADUser cmdlet, you can get the value of any attribute of an AD user account, list domain users with attributes, export user reports to CSV files, and use various criteria to select and filter domain users.

Contents:
  • Get-ADUser Cmdlet in Active Directory PowerShell Module
  • How to Find AD User and List Properties with Get-ADUser?
  • Get-ADUser -SearchBase: Getting Users from Specific OUs
  • How to Get a User’s Email Address from AD Using PowerShell?
  • Get-ADUser: Exporting Active Directory Users to CSV with PowerShell
  • Get-ADUser Filter Examples
  • PowerShell Get-ADUser Examples

Get-ADUser Cmdlet in Active Directory PowerShell Module

The Get-ADUser cmdlet is included in a special module for interacting with Active Directory – Active Directory Module for Windows PowerShell. The RSAT-AD-PowerShell module cmdlets enable you to perform various operations on AD objects.

Note. Previously, to get information about the attributes of AD user accounts, you had to use different tools: ADUC console (including saved AD queries), VBS scripts, dsquery, etc. All of these tools can be easily replaced by the Get-ADUser cmdlet.

In this example, we’ll show how to use the Get-ADUser PowerShell cmdlet to get information about the last time a user’s password was changed, when the password expires, and other users’ properties.

To use the RSAT-AD-PowerShell module, you need to run the elevated PowerShell console and import the module with the command:

Import-Module ActiveDirectory

The RSAT-AD-PowerShell module is installed by default on Windows Server 2012 (and newer) when you deployed the Active Directory Domain Services (AD DS) role. To install the module on a domain member Windows Server host, run the command:

Install-WindowsFeature -Name "RSAT-AD-PowerShell" –IncludeAllSubFeature

install RSAT-AD-PowerShell on Windows Server

In order to use the Get-ADUser cmdlet on desktop Windows 10/11, you need to install the appropriate version of RSAT. You can enable RSAT through Settings -> Apps -> Optional Features -> Add a feature -> RSAT: Active Directory Domain Services and Lightweight Directory Services Tools.

Install RSAT Active Directory PowerShell module on Windows 10 and 11

You can install the RSAT AD module on Windows 10 and 11 with PowerShell:

Add-WindowsCapability –online –Name "Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0"

If the RSAT-AD-PowerShell module is not installed on the computer, then when you run the Get-ADUser command, an error will appear:

Get-ADUser: The term 'get-aduser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Check that the module is installed, and if necessary, import it into your PowerShell session:

Import-Module ActiveDirectory

The term get-aduser is not recognized as the name of a cmdlet, function, script file

There is also a way to use the AD-PowerShell module without installing RSAT on your computer. It is enough to copy the main module files and import the module into the PowerShell session:

Import-Module "C:\PS\AD\Microsoft.ActiveDirectory.Management.dll"
Import-Module "C:\PS\AD\Microsoft.ActiveDirectory.Management.resources.dll"

A complete list of all the arguments of the Get-ADUser cmdlet can be obtained as follows:

help Get-ADUser

How to Find AD User and List Properties with Get-ADUser?

To use the Get-ADUser cmdlet, you don’t need to run it under an account with a domain administrator or delegated permissions. Any authorized AD domain user can run PowerShell commands to get the values of most AD object attributes (except for confidential ones, see the example in the article Local Administrator Password Solution – LAPS). If you need to run the Get-ADUser command under a different account, use the –Credential parameter.

To display the list of all domain user accounts, run this command:

Get-ADUser -filter *

Important. It is not recommended to run this command in the Active Directory domains with a large number of user accounts. This can place a heavy load on the domain controller providing the AD information.

Get-ADUser -filter * - gel all users in domain

Use the Set-ADUser cmdlet to change Active Directory user attributes.

To display the properties of a specific user, use the –Identity parameter. Identity can be a username, login (SAMAccountName), DN (Distinguished Name), SID, or GUID.

The following PowerShell commands will return the same result for the same AD user account:

Get-ADUser –Identity b.smith
Get-ADUser –Identity "CN=Brian Smith,OU=Users,OU=Berlin,DC=woshub,DC=loc"
Get-ADUser –Identity "Brian Smith"

get-aduser by identity

By default, the Get-ADUser cmdlet returns only 10 basic user attributes (out of more than 120 user account properties): DistinguishedName, SamAccountName, Name, SID, UserPrincipalName, ObjectClass, account status (Enabled: True/False according to the UserAccountControl AD attribute), etc. In this case, the cmdlet’s output doesn’t contain information about the time of the last user password change.

To execute an AD query on a specific domain controller, use the -Server option:

Get-ADUser –Server DC01.woshub.com –Identity tstuser

If you need to get user data from another AD domain, you need to specify the domain controller name and credentials to access it:

$ADcred = Get-Credential
Get-ADUSer tstuser -Server DC01.contoso.com -Credential $ADcred

To display the detailed information about all available user attributes, run this command:

Get-ADUser -identity tuser -properties *

get-aduser list all user object properties

The Get-ADUser cmdlet with the Properties * switch lists all the AD user’s attributes and their values (including empty ones). A similar list of user attributes is available in the Active Directory Users and Computers graphical snap-in (dsa.msc) under the attribute editor tab.

Then we’ll go to the formatting of Get-ADUser output so that the necessary user attributes are displayed. For example, you want to display the values of the following user properties:

  • PasswordExpired
  • PasswordLastSet
  • PasswordNeverExpires
  • LastLogonTimestamp

Run the command:

Get-ADUser tuser -properties PasswordExpired, PasswordLastSet, PasswordNeverExpires, lastlogontimestamp

get-aduser - properties PasswordExpired, PasswordLastSet, PasswordNeverExpires, lastlogontimestamp

Now in the user data, there is the information about the account password status (Expired: True/False), the date of the last password changes, and the time of the last user logon to the domain (lastlogontimestamp attribute). To display this information in a more convenient table view and remove all unnecessary attributes use the Select-Object –Property and Format-Table:

Get-ADUser -filter * -properties PasswordExpired, PasswordLastSet, PasswordNeverExpires | ft Name, PasswordExpired, PasswordLastSet, PasswordNeverExpires

Get-ADUser get password info for all users with format-table

Get-ADUser -SearchBase: Getting Users from Specific OUs

To display users only from a specific domain container (Organizational Unit), use the –SearchBase parameter:

Get-ADUser -SearchBase 'OU=London,DC=woshub,DC=loc' -filter * -properties PasswordExpired, PasswordLastSet, PasswordNeverExpires | ft Name, PasswordExpired, PasswordLastSet, PasswordNeverExpires

If you need to select users from multiple OUs at once, use the following PowerShell script:

$OUs = "OU=NY,DC=woshub,DC=com","OU=LA,DC=woshub,DC=com","OU=MA,DC=woshub,DC=com"
$OUs | foreach {Get-ADUser -SearchBase $_ -Filter * |select Name, Enabled}

How to Get a User’s Email Address from AD Using PowerShell?

User email address is one of the user object attributes in Active Directory. To list the email addresses of users, you must add the EmailAddress field to the properties of the Get-ADUser cmdlet.

Get-ADUser -filter * -properties EmailAddress -SearchBase 'OU=Paris,OU-Fr,DC=woshub,DC=com'| select-object Name, EmailAddress

Get-ADUser EmailAddress

The list of enabled user accounts with e-mail addresses:

Get-ADUser -Filter {(mail -ne "null") -and (Enabled -eq "true")} -Properties Surname,GivenName,mail | Select-Object Name,Surname,GivenName,mail | Format-Table

To get the list of Active Directory users with no Email address:

Get-ADUser -Filter * -Properties EmailAddress | where -Property EmailAddress -eq $null

The following example allows you to export a company email list from AD to a CSV file. Later, you can import this CSV address list into desktop email clients such as Outlook or Mozilla Thunderbird:

Get-ADUser -Filter {(mail -ne "null") -and (Enabled -eq "true")} -Properties Surname,GivenName,mail | Select-Object Name,Surname,GivenName,mail | Export-Csv -NoTypeInformation -Encoding utf8 -delimiter "," $env:temp\adress_list.csv

Get-ADUser: Exporting Active Directory Users to CSV with PowerShell

The resulting list of domain users with attributes can be exported to a text file:

Get-ADUser -filter * -properties PasswordExpired, PasswordLastSet, PasswordNeverExpires | ft Name, PasswordExpired, PasswordLastSet, PasswordNeverExpires > C:\temp\users.txt

Or you can export the AD users list to a CSV file:

Get-ADUser -filter * -properties PasswordExpired, PasswordLastSet, PasswordNeverExpires | where {$_.name –like "*Dmitry*"} | sort-object PasswordLastSet | select-object Name, PasswordExpired, PasswordLastSet, PasswordNeverExpires | Export-csv -path c:\tmp\user-passwords-expires.csv -Append -Encoding UTF8

The AD user list can be exported directly to an Excel file using PowerShell.

Get-ADUser Filter Examples

Using the –Filter switch, you can filter the list of user accounts by one or more attributes. This is useful for searching AD users whose attributes match specified criteria. Values for specific attributes of Active Directory users can be specified as arguments to this parameter. When you use the –Filter parameter, the Get-ADUser cmdlet will only display users that match the filter criteria.

For example, I want to list active (Enabled) user accounts whose name contains “Dmitry”. The example below uses multiple filters; you can combine conditions using the logical PowerShell comparison operators. In this example, user attributes must satisfy both filter conditions (-and):

Get-AdUser -Filter "(Name -like '*Dmitry*') -and (Enabled -eq 'True')" -Properties * |select name,enabled

Get-AdUser with filter

All PowerShell logical operators can be used to select values for user attributes (-eq, -ne, -gt, -ge, -lt, -le, -like, -notlike, -and, -or, etc.)

Additionally, you can sort the resulting list of users by a specific user attribute with the Sort-Object cmdlet. You can also use the Where-Object cmdlet to specify multiple filtering criteria at once.

Get-ADUser -filter * -properties PasswordExpired, PasswordLastSet, PasswordNeverExpires -SearchBase 'OU=NY,DC=woshub,DC=com'| where {$_.name –like "*Dmitry*" -and $_.Enabled -eq $true} | sort-object PasswordLastSet | select-object Name, PasswordExpired, PasswordLastSet, PasswordNeverExpires

Get-ADUser - filtering with Where-Object and Sort-Object

Thus, you can get a list of users with any necessary Active Directory attributes.

To search for users by several attributes at once (legacyExchangeDN, proxyAddresses, SAMAccountName, Surname, DisplayName, SamAccountName, physicalDeliveryOfficeName, RDN, and msExchMailNickname), you can use the Ambiguous Name Resolution (ANR) feature:

Get-ADUser -Filter {anr -eq 'John'} | select Name

Hint. When looking up Active Directory users using Get-ADUser, from a performance perspective, specifying the criteria using the Filter attribute is preferable to using the pipeline to the Where-Object cmdlet. In this case, the filtering of the selection results will be performed on the domain controller, and a smaller set of data will be transferred to your computer over the network.

You can use an LDAP filter in Get-ADUser queries. An LDAP filter is specified using the –LdapFilter attribute.

Get-ADUser -LDAPFilter '(&(department=it)(title=sysops))'

PowerShell Get-ADUser Examples

Let’s show some more useful PowerShell command examples for querying Active Directory users with various filters. You can combine them to get the required list of AD user objects:

Display AD users, whose name starts with Joe:

Get-ADUser -filter {name -like "Joe*"}

You can use PowerShell to calculate the total number of user accounts in the Active Directory:

Get-ADUser -Filter {SamAccountName -like "*"} | Measure-Object

Find disabled Active Directory user accounts:

Get-ADUser -Filter {Enabled -eq "False"} | Select-Object SamAccountName,Name,Surname,GivenName | Format-Table

You can check the Active Directory user account creation date with the command:

get-aduser -Filter * -Properties Name, WhenCreated | Select name, whenCreated

You can get the list of newly added Active Directory users created in the last 24 hours:


$lastday = ((Get-Date).AddDays(-1))
Get-ADUser -filter {(whencreated -ge $lastday)}

List the accounts with an expired password (you can configure password expiration options in the domain password policy):

Get-ADUser -filter {Enabled -eq $True} -properties name,passwordExpired| where {$_.PasswordExpired}|select name,passwordexpired

You can use the Get-ADUser and Add-ADGroupMember cmdlets to create dynamic AD user groups (depending on city, job title, department, etc.).

Task: for the list of user accounts that are stored in a text file (one account per line), you need to get the user’s company name from AD and save it to a CSV file (you can easily import this CSV file into Excel).

Import-Csv c:\ps\users_list.csv | ForEach {
Get-ADUser -identity $_.user -Properties Name, Company |
Select Name, Company |
Export-CSV c:\ps\users_ad_list.csv -Append -Encoding UTF8
}

The users who haven’t changed their domain passwords in the last 90 days:

$90_Days = (Get-Date).adddays(-90)
Get-ADUser -filter {(passwordlastset -le $90_days)}

Find inactive user accounts (not logged on to the domain for more than 180 days). The lastLogonTimestamp attribute is used to get the user’s logon history to the domain:

$LastLogonDate= (Get-Date).AddDays(-180)
Get-ADUser -Properties LastLogonTimeStamp -Filter {LastLogonTimeStamp -lt $LastLogonDate } | ?{$_.Enabled –eq $True} |  Sort LastLogonTimeStamp| FT Name, @{N='lastlogontimestamp'; E={[DateTime]::FromFileTime($_.lastlogontimestamp)}} -AutoSize

To get a user’s photo from Active Directory and save it to a jpg file, run the following commands:

$usr = Get-ADUser sjoe -Properties thumbnailPhoto
$usr.thumbnailPhoto | Set-Content sjoe.jpg -Encoding byte

To get a list of AD groups which the user account is a member of:

Get-AdUser sjoe -Properties memberof | Select memberof -expandproperty memberof

List the users from the OU that are members of a specific domain security group:

Get-ADUser -SearchBase 'OU=Rome,OU=Italy,DC=woshub,DC=com' -Filter * -properties memberof | Where-Object {($_.memberof -like "*CEO*")}

List users from the OU that are members of a specific domain security group:

Get-ADUser -SearchBase 'OU=Rome,OU=Italy,DC=woshub,DC=com' -Filter * -properties memberof | Where-Object {($_.memberof -like "*CEO*")}

List all users from the OU, except for members of a specific group:

$Users = Get-ADUser -filter * -SearchBase ‘OU=Berlin,DC=woshub,DC=com’ -properties memberOf
ForEach ($User In $Users)
{
$Groups = -join @($User.memberOf)
If ($Groups -notlike '*Domain Admins*')
{
$User.Name
}
}

Exporting a list of AD users with the Organizational Unit name to the Out-GridView table:

get-aduser -filter * -Properties cn,canonicalname | select name,userprincipalname,@{Name="OU";expression={$_.Canonicalname.substring(0,$_.canonicalname.length-$_.cn.length)}}| Out-GridView

powershell: export active directory user list to out-gridview table

Check that the AD user account exists:
$SamAccountName='jbrown'
if (@(Get-ADUser -Filter { SamAccountName -eq $SamAccountName }).Count -eq 0)
{  Write-Host "User $SamAccountName doesn’t exist"}

List the domain computers the user is allowed to sign in (logon restriction through the LogonWorkstations AD attribute).

Get-ADUser jbrown -Properties LogonWorkstations | Format-List Name, LogonWorkstations

Tip. The Get-ADComputer cmdlet is used to get computer properties or search for multiple computers from Active Directory.

30 comments
4
Facebook Twitter Google + Pinterest
previous post
Configuring UserPrincipalName and UPN Suffixes in Active Directory
next post
Get User or Group Creation Date in Azure AD (or MS365) with PowerShell

Related Reading

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

How to Query and Change Teams User Presence...

October 8, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

30 comments

Farhan July 21, 2016 - 8:26 am

Thanks for this useful information. I’m trying the following script, it works fine on powershell, but when i try to export it to csv, its not readable text in it. Some strings are there only.
PS C:\> Get-ADUser -filter * -properties PasswordExpired, PasswordLastSet, PasswordNeverExpires | ft Name, PasswordExpired, PasswordLastSet, PasswordNeverExpires
PS C:\> Get-ADUser -filter * -properties PasswordExpired, PasswordLastSet, PasswordNeverExpires | ft Name, PasswordExpired, PasswordLastSet, PasswordNeverExpires | Export-Csv -Path c:\temp\password-change.csv
 
Please help.

Reply
Peter January 6, 2020 - 7:29 pm

You can use:
PS C:\> Get-ADUser -filter * -properties PasswordExpired, PasswordLastSet, PasswordNeverExpires | ft Name, PasswordExpired, PasswordLastSet, PasswordNeverExpires > c:\temp\password-change.csv

Reply
Omar Campos July 24, 2020 - 2:22 pm

So I need to get some info for our auditors and have little time to do so. Certain properties they want need a False or True output and I don’t know how to do that. Here is my command which did not work with the properties that needed a true or false output:

Get-ADUser -Filter * -Properties * | Select-Object samaccountname, isPreAuthNotRequired, isActive, isPwdEncryptedTextAllowed, displayname, isPwdNotRequired, userprincipalname, isDisabled, isExpired, distinguishedname | export-csv -path c:\export\allusers.csv

The objects like samaccountname came out fine; it’s just the ones that needed that true or false output. Please advise.

Reply
admin July 28, 2020 - 3:23 am

You are using non-existent AD attributes: isPreAuthNotRequired, isActive, isPwdEncryptedTextAllowed, isPwdNotRequired, isDisabled, isExpired
The state of an AD account is described using the UserAccountControl bit mask attribute. Each bit of the attribute is a separate flag (enabled or disabled)
In this article, there is a small Powerhell script that allows you to get information from the UserAccountControl attribute in a simple way. https://woshub.com/decoding-ad-useraccountcontrol-value/

Reply
Mark September 29, 2016 - 4:11 pm

Very good information thanks

Reply
Singh October 5, 2016 - 6:47 am

you are using ft Name, you have to use Select statement for same object properties.

Reply
Garry December 2, 2016 - 9:54 am

I want to combine two of these reports into one, but I don’t know how to format the command:

Using the “List all active AD accounts”, I want to add password info (password last set, password expired, passwordneverexpires flag set) so I get a list of active AD accounts, logon name, user name and password info.

Reply
admin December 7, 2016 - 6:25 am

You can use the following query:
Get-ADUser -Filter {Enabled -eq “True”} -properties name,SamAccountName,PasswordExpired, PasswordLastSet, PasswordNeverExpires| Select-Object name,SamAccountName,PasswordExpired, PasswordLastSet, PasswordNeverExpires | Format-Table

Reply
Garry December 7, 2016 - 8:29 am

Thanks. With a little tweaking I can now show the columns in the order I want and sort the list by name (actually any column I choose), and I can even export the results. Still a lot to learn but this site is a great resource.

Reply
mohamed Dardeer January 10, 2017 - 12:33 pm

i have a csv file contain company attribute for a large number about 2000 users i want to get the domain users login accounts for these users exported in csv file that contain the login users and the company filed for etch user in the csv file

Reply
Max January 11, 2017 - 1:13 pm

Suppose you have a file userlist.csv that contain a list of users in the following format:
SamAccountName
user1
user2
user3
user4

And run this script:
Import-Csv C:\Ps\userlist.csv | ForEach {
Get-ADUser -Identity $_.SamAccountName -properties samaccountname,company | `
select samaccountname,company | `
Export-CSV C:\ps\output.csv -notype -encoding UTF8 -Append
}

Reply
ZM February 1, 2022 - 3:30 pm

Hi- I am sure script is fine but not sure why am i getting error below.

Get-ADUser : Cannot validate argument on parameter ‘Identity’. The argument is null or an element of the argument
collection contains a null value.
At line:2 char:22
+ Get-ADUser -Identity $_.SamAccountName -properties samaccountname,com …
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Reply
Moaxl March 15, 2017 - 3:13 pm

thank you very much for this awesome information.
and lots of samples!

helped me a lot!

Reply
venkatesh May 2, 2017 - 3:46 pm

i want to export my domain user details with following column

username / login id / mail id / description / manager name

please share the script

Reply
admin May 3, 2017 - 7:44 am

Get-ADUser -filter * -properties displayName, sAMAccountName, mail,description, manager| ft displayName, sAMAccountName, mail,description, manager | Export-csv -path c:\ps\adusers.csv

Reply
Amar April 15, 2018 - 10:18 am

I want to export ad users which is not used from last 365 days. And after that wants to delete the same.
so pleas share the script separately of both queries.

Reply
Max April 16, 2018 - 9:11 am

You can filter active users using LastLogon attribute. To export this list to a CSV file, use Export-CSV cmdlet:
$IncativeDays = (Get-Date).adddays(-365)
Get-ADUser -Filter {LastLogon -lt $IncativeDays -and enabled -eq $true} -properties displayName, company, LastLogon | select-object displayName, company,@{n='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}} | Export-CSV c:\ps\users_ad_list.csv -Append -Encoding UTF8
To delete these Active Directory user accounts, you can use pipe to Remove-ADUser
Get-ADUser -Filter {LastLogon -lt $IncativeDays -and enabled -eq $true} -properties displayName, company, LastLogon | Remove-ADUser

Reply
Nico December 21, 2018 - 4:52 pm

how do you get-user -filter {name -like “name*”} | select-object samaccount,name,surname, | format-table but also include the -member of and search for a particular group and see if he has it in their member of. I have their first and last name and want to cut the the time by looking up their username, therefore I have first and last name but last name will suffice

Reply
B.Y.Vamsi Krishna August 29, 2019 - 2:51 pm

Hello

I am looking to fetch all the user details from AD for the below columns and export it to .csv file.

Please help

First Name
Last Name
User Created Date
Type – Group / User
Role
Last password Change
Las Modified Date
Description

Thanks In Advance

Reply
Vijay Shekar Ede October 23, 2019 - 5:23 am

#Powershell script to fetch AD user details including AD Group membership into csv.
# Input file is a csv with list of samaccountnames and header as ‘samaccountname’
#BEGIN SCRIPT
Import-Module ActiveDirectory

$usersList = Import-Csv -Path C:\Temp\samaccountname_usersIN.csv
# Loop through CSV and get users if the exist in CVS file

foreach ($user in $usersList) {
$SamAccountName = $user.SamAccountName
Get-ADUser -Filter {SamAccountName -like $SamAccountName} -Properties * | Select-Object UserPrincipalName,EmailAddress,mail,SamAccountName,@{“name”=”MemberOf”;”expression”={$_.MemberOf}},Street,CanonicalName,DistinguishedName,@{“name”=”proxyaddresses”;”expression”={$_.proxyaddresses}},Name,GivenName,Surname,DisplayName,LastLogonDate,Enabled,EmployeeID | export-csv -Append C:\Temp\UserDetails_Out.csv -noType

}
#END SCRIPT

Reply
MASON July 23, 2020 - 6:40 am

How can we fetch report of members in each group of specific OU with timestamp?

Reply
Revanth June 6, 2021 - 6:20 pm

I am getting timeout error upon connecting to other server, how can I overcome this problem?

Reply
Ajit Khandelwal October 6, 2021 - 7:12 am

I am looking for a powershell command that can help me with all the enabled users in my AD from all the OU’s with attributes namely EmployeeID, Employeenumber, email ID, managers name, department, job title, phone number, state, country, logon name.

Can anybody help me with this command.

Reply
Eshan December 2, 2021 - 3:38 pm

i want to search two multiple samaccount like “srv.” and “service”
Its worked for single samaccount but not for double. Please help

Get-ADUser -Filter {anr -eq ‘srv.’} | select Name

Reply
Jhadeswar MURMU April 5, 2022 - 7:41 pm

I want to give an alias for a property name.
For instance,
Get-ADUser -Filter {name -like “*son*” | Properties Name, msDS-cloudExtensionAttribute1
How can I set an alias for msDS-cloudExtensionAttribute1 ?
Please suggest.

Reply
admin April 7, 2022 - 8:20 am

Get-ADUser -Filter {name -like “*son*”} -properties msDS-cloudExtensionAttribute1 | select Name, @{name='youralias';expression={$_.msDS-cloudExtensionAttribute1}}

Reply
Jhadeswar MURMU April 7, 2022 - 5:06 pm

Thank you for prompt reply.

Reply
Gabriele June 25, 2022 - 1:15 pm

Hello,

thanks for this really useful page! 🙂 I tried to modify a script but it works just for half columm:

$LastLogonDate= (Get-Date).AddDays(-180)
Get-ADUser -Properties LastLogonTimeStamp -Filter {LastLogonTimeStamp -lt $LastLogonDate } | ?{$_.Enabled –eq $True} | Sort LastLogonTimeStamp| FT Name, @{N=’lastlogontimestamp’; E={[DateTime]::FromFileTime($_.lastlogontimestamp) | Export-csv -path c:\AD\Reports\Inactive_users.csv -Append -Encoding UTF8}} -AutoSize

And I didn’t understand how to put it in multiple line by Visual Studio Code with PS extension…

Reply
Mukil January 6, 2023 - 12:09 pm

I want script to get list of AD users modified with their modification date for past 9months. Please help me to get the same.

Reply
admin January 9, 2023 - 4:41 am

$date = ((get-date).addmonths(-9))
Get-ADUser -Filter * -Properties whenChanged| Where-Object {$_.whenChanged -ge $date} | select name

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Configure Google Chrome Settings with Group Policy
  • How to Find the Source of Account Lockouts in Active Directory
  • How to Disable or Enable USB Drives in Windows using Group Policy
  • Get-ADComputer: Find Computer Properties in Active Directory with PowerShell
  • Deploy PowerShell Active Directory Module without Installing RSAT
  • Configuring Proxy Settings on Windows Using Group Policy Preferences
  • Managing User Photos in Active Directory Using ThumbnailPhoto Attribute
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top