
close
close
Over the last several weeks, I have been demonstrating how you can manage Active Directory with PowerShell. I have been doing so without relying on the Active Directory module that ships as part of Remote Server Administration Tools (RSAT). There is nothing inherently wrong or bad about using Get-ADUser but there may be situations where you do not have that toolset handy. One topic I still need to address is searching. For the sake of demonstration, all of my commands are being run on a domain-joined Windows 10 desktop. It is under an account that has domain admin privileges. For simple searching, you should be able to use a normal user account. You may do this differently if you have messed around with default permissions.
To begin, we need a searcher object:
$searcher = New-Object system.DirectoryServices.DirectorySearcher
You will end up with an object like this:
AD Searcher Object (Image Credit: Jeff Hicks)
advertisment
$searcher.filter = "samaccountname=jeff"
How do we use this? One step you can take is to use Get-Member. You can see the different methods that are available:
Getting Searcher Methods (Image Credit: Jeff Hicks)
Finding a Single AD Account (Image Credit: Jeff Hicks)
Search Result Properties (Image Credit: Jeff Hicks)
advertisment
Selecting Result Properties (Image Credit: Jeff Hicks)
$me.properties.PropertyNames | foreach -begin { [email protected]{} } -process { $value = $me.Properties.item($_) if ($value.count -eq 1) { $value = $value[0] } $h.add($_,$value) } -end { new-object psobject -property $h }
Converting to an Object (Image Credit: Jeff Hicks)
advertisment
$props = "Name","Title","Department","Samaccountname","DistinguishedName","DirectReports" $h = @{} foreach ($p in $props) { $value = $me.Properties.item($p) if ($value.count -eq 1) { $value = $value[0] } $h.add($p,$value) } new-object psobject -property $
Displaying Specific Properties (Image Credit: Jeff Hicks)
More in Windows 10
Microsoft to Start Notifying Windows 8.1 Users About Upcoming End of Support
Jun 24, 2022 | Rabia Noureen
Microsoft's Out-Of-Band Patch Fixes Microsoft 365 and Azure AD Sign-In Issues on ARM Devices
Jun 21, 2022 | Rabia Noureen
Microsoft is Investigating Sign-In Issues Affecting Microsoft 365 and Azure AD on ARM Devices
Jun 20, 2022 | Rabia Noureen
Microsoft to Fix Windows Bug Breaking Wi-Fi hotspots After Installing Latest Patch Tuesday Update
Jun 17, 2022 | Rabia Noureen
Microsoft's June 2022 Patch Tuesday Updates Fix Several Remote Code Execution Vulnerabilities
Jun 15, 2022 | Laurent Giret
New Report Shows 47% of Enterprise Windows 10 PCs Could Be Impacted by Internet Explorer's Retirement on June 15
Jun 14, 2022 | Rabia Noureen
Most popular on petri