Created
February 12, 2018 15:07
-
-
Save jabez007/99251140e9a2b7aa65744c6fb7d117c2 to your computer and use it in GitHub Desktop.
Powershell script I found for searching AD without the AD Module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-BasicADObject | |
{ | |
<# | |
.SYNOPSIS | |
Function allow to get AD object info without AD Module. | |
.DESCRIPTION | |
Use Get-BasicADObject to get information about Active Directory objects. | |
.PARAMETER Filter | |
Filter objects, default search information about users. | |
.PARAMETER Ldap | |
LDAP Path to object. | |
.EXAMPLE | |
Get-BasicADObject -Ldap 'dc=domain,dc=com'| Export-Csv C:\ADObj.csv -NoTypeInformation | |
.NOTES | |
Author: Michal Gajda (https://gallery.technet.microsoft.com/scriptcenter/Export-AD-Users-properties-eea93c89) | |
More Info on ADSISEARCHER: https://blogs.technet.microsoft.com/heyscriptingguy/2010/08/24/use-the-powershell-adsisearcher-type-accelerator-to-search-active-directory/ | |
#> | |
[CmdletBinding( | |
SupportsShouldProcess=$True, | |
ConfirmImpact="Low" | |
)] | |
param | |
( | |
[String]$Ldap = "dc="+$env:USERDNSDOMAIN.replace(".",",dc="), | |
[String]$Filter = "(&(objectCategory=person)(objectClass=user))" | |
) | |
Begin{} | |
Process | |
{ | |
if ($pscmdlet.ShouldProcess($Ldap,"Get information about AD Object")) | |
{ | |
$searcher=[adsisearcher]$Filter | |
$Ldap = $Ldap.replace("LDAP://","") | |
$searcher.SearchRoot="LDAP://$Ldap" | |
$results=$searcher.FindAll() | |
$ADObjects = @() | |
foreach($result in $results) | |
{ | |
[Array]$propertiesList = $result.Properties.PropertyNames | |
$obj = New-Object PSObject | |
foreach($property in $propertiesList) | |
{ | |
$obj | add-member -membertype noteproperty -name $property -value ([string]$result.Properties.Item($property)) | |
} | |
$ADObjects += $obj | |
} | |
Return $ADObjects | |
} | |
} | |
End{} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment