Other Posts in this Series:
- Use ADSI to List Nested Members of an AD Group (Updated)
- Use ADSI and FromFileTime to Convert Datetime Attributes in Active Directory
- Use ADSI to Find Logon Workstations in Active Directory
- Search Active Directory using PowerShell ADSISearcher Filters
- Use PowerShell ADSI to Search Users in Active Directory
This post provides an example of how we can use ADSI to find logon workstations in Active Directory.
I recently needed to search through all users in Active Directory and find logon workstations for those accounts that had them. Logon workstations for a user account essentially restricts what workstations a specific user account can log on to.
A lot of this code example is based on using the ADSI Searcher to find user accounts in Active Directory.
$Root = [ADSI]"LDAP://OU=users,DC=alkanesolutions,DC=co,DC=uk"
$Searcher = new-object System.DirectoryServices.DirectorySearcher($Root)
$Searcher.filter = "(&(objectCategory=person)(objectClass=user))"
$Searcher.PageSize = 200
$Searcher.FindAll() | % {
$user = [adsi]$_.Properties.adspath[0]
$ErrorActionPreference = "silentlycontinue"
If (($user.get("userWorkstations")) -ne $null)
{
$workstations = $user.get("userWorkstations")
$workstationsArray = $workstations.split(",")
foreach($ws in $workstationsArray) {
write-host $samaccount $ws
}
}
}