PowerShell is very useful for automating Active Directory. It allows to quickly and relatively easy automate mundane actions or perform same operations with many objects.
PowerShell provides very broad set of methods to work with Active Directory. There is some of them:
002
003
004
$Searcher.Filter = '(&(objectCategory=person)(anr=gusev))'
$Searcher.SearchRoot = 'LDAP://OU=Laptops,OU=Computers,DC=contoso,DC=com'
$Searcher.FindAll()
Filter property of the Searcher object uses standard LDAP query syntax. You can also use FindOne() method to receive just first found object.
$UAC = $User.UserAccountControl[0] -bor 65536
$User.Put("userAccountControl",$UAC)
$User.SetInfo()
$Members = $Group.Member | ForEach-Object {[ADSI]"LDAP://$_"}
Same way, groups in which AD object is directly included are contained in its MemberOf property.
$Groups = $User.MemberOf | ForEach-Object {[ADSI]"LDAP://$_"}
PS C:\> $Object = [ADSI]"LDAP://cn=Administrator,cn=Users,dc=Contoso,dc=Com" PS C:\> $Object.class user PS C:\> $Object.objectclass top person organizationalPerson user
Very nice, great help to get you started
Great so we have multiples way for using the powershell for AD.