-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGet-LDAPuserInfo.ps1
74 lines (71 loc) · 3.36 KB
/
Get-LDAPuserInfo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#===============================================================================
# NAME : Get-LDAPuserInfo.ps1
# LANGUAGE : Windows PowerShell
# AUTHOR : Bryan Dady
# DATE : 03/09/2010
# COMMENT : Query Active Directory through PowerShell, retrieving user attributes
#===============================================================================
#This code demonstrates how to search and retrieve User Object information from Active Directory
#without any plug-ins.
#
#To run this script within your environment you should only need to copy and paste this script into
#either Windows Powershell ISE or PowerGUI Script Editor,(http://powergui.org) with the following
#changes to the script which I have numbered below.
# 1.) Change the line, ($strUserName = "samAccountName"), so that you have a real User ID.
# 2.) You may also need to install Microsoft Update "http://support.microsoft.com/kb/968930".
#
#
#You can also search in a specific Active Directory OU By changing the second line of code
#From: "$objDomain = New-Object System.DirectoryServices.DirectoryEntry"
#To: "$objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=ASDF,DC=asdf,DC=asdf")"
$strUserName = $env:USERNAME
$objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://DC=GBCI,DC=GBCI,DC=GLACIERBANCORP,DC=local")
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$strFilter = "(&(objectCategory=User)(samAccountName=" + $strUserName + "))"
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{$objUser = $objResult.GetDirectoryEntry()
$objUser.adspath
"First Name: " + $objUser.FirstName
"Given Name: " + $objUser.givenName
"Last Name: " + $objUser.LastName
"initial: " + $objUser.initials
"Name: " + $objUser.name
"CN: " + $objUser.cn
"FullName: " + $objUser.FullName
"DisplayName: " + $objUser.DisplayName
"SamAccountName: " + $objUser.samAccountName
"UserPrincipalName: " + $objUser.UserPrincipalName
"badPwdCount: " + $objUser.badPwdCount
"Comment: " + $objUser.comment
"Company: " + $objUser.company
"Country Code: " + $objUser.countryCode
"Department: " + $objUser.department
"Description: " + $objUser.description
"Direct Reports: " + $objUser.directReports
"Distinguished Name: " + $objUser.distinguishedName
"facsimileTelephoneNumber: " + $objUser.facsimileTelephoneNumber
"physicalDeliveryOfficeName: " + $objUser.physicalDeliveryOfficeName
"TelephoneNumber: " + $objUser.TelephoneNumber
"mail: " + $objUser.mail
"wWWHomePage: " + $objUser.wWWHomePage
"streetAddress: " + $objUser.streetAddress
"postOfficeBox: " + $objUser.postOfficeBox
"City: " + $objUser.l
"State: " + $objUser.st
"postalCode: " + $objUser.postalCode
"Country: " + $objUser.c
"Title: " + $objUser.Title
"Info: " + $objUser.Info
#Vintela Authentication Service - uncomment the following lines if you have VAS installed and
#working within your Active Directory environment.
#"User ID (uid): " + $objUser.uidNumber
#"Primary Group ID(gid): " + $objUser.gidNumber
#"GECOS: " + $objUser.gecos
#"Login Shell: " + $objUser.loginShell
#"Unix Home Directory: " + $objUser.unixHomeDirectory
}