Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $domain = $args[0]
- $username = $args[1]
- $password = $args[2]
- $ObjFilter = "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2))"
- #Build the directory object with a SecureSocketLayer connection. You might have to modify the domain\username combination. The example below will fail if the ".com" is passed in with #the domain\username ie: testlab.com\admin
- $Directory=New-Object System.DirectoryServices.DirectoryEntry ("LDAP://$domain", (($domain -replace ".com")+'\'+$username), $password,[System.DirectoryServices.AuthenticationTypes]::SecureSocketsLayer)
- $Searcher=New-Object System.DirectoryServices.DirectorySearcher
- $Searcher.SearchRoot=$Directory
- $Searcher.PageSize = "1000"
- $Searcher.Filter = $ObjFilter
- $Searcher.SearchScope = "Subtree"
- $Searcher.PropertiesToLoad.Add("sAMAccountName") |Out-Null
- $Searcher.PropertiesToLoad.Add("memberOf") | Out-Null
- #$Searcher.PropertiesToLoad.Add("name") |Out-Null
- $Results = $Searcher.FindAll()
- $adusers=@()
- foreach($result in $results){
- $Group=$Result.Properties.memberof
- $Admins = $Result.Properties.samaccountname | Where {$Group -like "*Domain Admins*" -or $Group -like "*Enterprise Admins*" -or $Group -like "*Administrators"}
- foreach ($admin in $admins){
- $ObjUser = New-Object -TypeName PsObject;
- $ObjUser | Add-Member -MemberType NoteProperty -Name Resource -Value $env:USERDNSDOMAIN;
- $ObjUser | Add-Member -MemberType NoteProperty -Name UserName -Value $Admin;
- $ObjUser | Add-Member -MemberType NoteProperty -Name Enabled -Value $True;
- $adusers += $ObjUser;}
- }
- Return $adusers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement