Get-ADObjectAttribute.psm1
<#
.Synopsis The cmdlet enables you to fetch AD attributes from ADSIEDIT of the given object .DESCRIPTION Usually inorder to search/ fetch AD attributes one need to have AD modules installed. This cmdlet allows you to fetch without any modules. What all you need is PowerShell .PARAMETER ObjectClass Specifies the object class type. For example if you wish to search an user then the ObjectClass should be user and for a group then its Group, OU and so on. When you are not sure then you can give '*' .PARAMETER Property Specifies the property name using which you wish to search. Let say mail, userprincipalname, distinguishedname..etc .PARAMETER Value Specifies the Value of the 'Property' that you inputted .EXAMPLE Get-ADObjectAttribute -ObjectClass * -Property mail -Value User@CloudComputee.com Path Properties ---- ---------- GC://CN=User\, K,OU=Employees,OU=Users,OU=Small Locations,OU=Other CountriesDC=CloudComputee,DC=com {c, department, msexchrecipienttypedetails, prim... When you don't know the type of the object class then you can give '*' .EXAMPLE Get-ADObjectAttribute -ObjectClass user -Property mail -Value User@CloudComputee.com Path Properties ---- ---------- GC://CN=User\, K,OU=Employees,OU=Users,OU=Small Locations,OU=Other CountriesDC=CloudComputee,DC=com {c, department, msexchrecipienttypedetails, prim... When you are certain about the object class type then you can specify .INPUTS ObjectClass,Property using which you want to search and it's value .OUTPUTS System.DirectoryServices.SearchResult .NOTES .COMPONENT AD, ADSIEDIT .ROLE Domain User. Usually everyone in an organization would have read access to AdsiEdit .FUNCTIONALITY Fetching/ finding an object in AD based on the value and property you have #> function Get-ADObjectAttribute { [CmdletBinding()] Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, ValueFromRemainingArguments=$false, Position=0, ParameterSetName='SET1')] [ValidateNotNull()] [ValidateNotNullOrEmpty()] [Alias("class")] [String]$ObjectClass, [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, ValueFromRemainingArguments=$false, Position=0, ParameterSetName='SET1')] [ValidateNotNull()] [ValidateNotNullOrEmpty()] [String]$Property, [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, ValueFromRemainingArguments=$false, Position=0, ParameterSetName='SET1')] [ValidateNotNull()] [ValidateNotNullOrEmpty()] [Alias("val")] [String]$Value ) $RootDSE = [ADSI]"LDAP://rootDSE" $RootDNS = $RootDSE.RootDomainNamingContext $Root=[ADSI]"GC://$RootDNS" $searcher = new-object System.DirectoryServices.DirectorySearcher($Root) $searcher.filter = "(&(objectClass=$ObjectClass)($Property=$Value))" $result = $searcher.findall() if($result) { Return ($result)} else{ Return $null } } |