List Attributes of any Active Directory object

To view the attrributes of an object .Supply the object’s distinguished name as parameter.

Script

<#
.SYNOPSIS
This script can be used to list all attributes of any active directory object.
.DESCRIPTION
This script can be used to list all attributes of any active directory object.
.EXAMPLE
C:\PS> C:\Script\Attributes_of_an_object.ps1 “CN=Administrator,CN=Users,DC=xchange,DC=com”
Lists all attributes of user Administrator.
#>

param([String]$dname)
#Fetches the object for which attributes has to be listed.

$obj = [ADSI](“LDAP://” + “$dname”)
#Fetches a collection of all attributes of the object.

$colObjProps = $obj | get-member
#Lists the attributes one by one.

foreach ($prop in $colObjProps)
{
write-host $prop.Name -nonewline
write-host “: ” -nonewline
write-host $obj.($prop.Name)
}

 

Output
Attributes_of_object

Leave a Reply