PowerShell to get AD domain user attributes

1. View the specified user information

Get-ADUser -Identity zhangsan

# 显示
DistinguishedName : CN=zhang san,OU=SHA,DC=msh,DC=local
Enabled           : True
GivenName         : zhang
Name              : zhang san
ObjectClass       : user
ObjectGUID        : 7aa0a36a-4e9f-48b8-87dd-d41606b0dbe9
SamAccountName    : zhangsan
SID               : S-1-5-21-1999284519-599392543-677991306-1108
Surname           : san
UserPrincipalName : [email protected]

 2. Get all attributes of the specified user

Get-ADUser -Identity zhangsan -Properties *

3. Obtain the specified attributes: display name, whether the password expires, SAN account name, UPN account name, creation time, modification time

Get-ADUser -Identity zhangsan -Properties * | FT Name,PasswordExpired,SamAccountName,UserPrincipalName,whenCreated,whenChanged

# 显示
Name      PasswordExpired SamAccountName UserPrincipalName   whenCreated           whenChanged          
----      --------------- -------------- -----------------   -----------           -----------          
zhang san           False zhangsan       [email protected] 2/17/2023 12:22:54 AM 2/19/2023 11:46:40 PM

4. Fuzzy query users starting with li

Get-ADUser -Filter 'Name -like "li*"' | Format-Table Name,SamAccountName,UserPrincipalName

# 显示
Name   SamAccountName UserPrincipalName
----   -------------- -----------------
li shi lishi          [email protected]

5. Get all users under the specified OU

Get-ADUser -Filter * -SearchBase "OU=SHA,DC=msh,DC=local"

6. Export users

Get-ADUser -Filter * -SearchBase "OU=SHA,DC=msh,DC=local" | ft name > member.csv

7. Obtain which users have set "password never expires"

Get-ADUser -Filter 'PasswordNeverExpires -eq $true' -Server DC1 | select name

Guess you like

Origin blog.csdn.net/mshxuyi/article/details/130340120