View all posts filed under 'Active Directory'

NameTranslate using PowerShell

Saturday, 14. March 2009 17:01

I had a need for translating Active Directory object names from any to any form. For instance lab\administrator to cn=administrator,cn=users,dc=lab,dc=local and back. I remembered having seen a cool function called NameTranslate somewhere to see if I could use it somehow.

When searching the internet I found some vbscript code which created an object called “Nametranslate”. Since I absolutely hate vbscript I decided to translate this script into a native PowerShell script. First step was to create a new ComObject like so:

[...]

Category:Active Directory, PowerShell | Comments (4) | Author: Dennis Damen

Find all computers in an OU

Monday, 2. February 2009 9:00

The snippet below will return all computer object is the specified OU. Just replace the LDAP query with the one you want. The “searchscope” property should be set to “subtree” if you want to do a recursive search.

$dirEntry = new-object directoryservices.directoryentry(“LDAP://ou=XXXX,dc=DOMAIN,DC=COM”)
$dirSearcher = new-object directoryservices.directorysearcher
$dirSearcher.searchroot = $dirEntry
$dirSearcher.Filter = “objectclass=Computer”
$dirSearcher.SearchScope = “base” (or “onelevel” or “subtree”)
$dirSeacher.FindAll()

Category:Active Directory, PowerShell | Comment (0) | Author: Dennis Damen

MemberOf

Thursday, 6. November 2008 13:55

Check if the current user is member of a certain group:

“*\domain users” | %{$grp = $_ ;  ([security.principal.WindowsIdentity]::GetCurrent()).Groups | %{$_.Translate([System.Security.Principal.NTAccount])} | where-object {$_ -like $grp} } | %{$true}

“builtin\users” | %{$grp = $_ ; ([security.principal.WindowsIdentity]::GetCurrent()).Groups | %{$_.Translate([System.Security.Principal.NTAccount])} | where-object {$_ -like $grp} } | %{$true}

“NT AUTHORITY\Authenticated Users” | %{$grp = $_ ; ([security.principal.WindowsIdentity]::GetCurrent()).Groups | %{$_.Translate([System.Security.Principal.NTAccount])} | where-object {$_ -like $grp} } | %{$true}

Category:Active Directory, PowerShell | Comment (0) | Author: Dennis Damen