Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Critique my Active Directory script

Closed Thread
 
Thread Tools Display Modes
Old 12-01-2006   #1 (permalink)
phappyman@gmail.com
Guest


 

Critique my Active Directory script

I've got this script working, but I have the feeling that I've done a
lot of this wrong. My GOAL for this script was to:
* Grab a list of all the groups sitting in a particular OU
* From these groups, list all *enabled* users
* Get this list into Excel, somehow (CSV or similar is fine)

Anyway, it works, but I think I did some doublework. Specifically, I
don't think I should have had to run another LDAP query to grab each
user object, and I think I could have reconfigured this somehow to use
the "export-csv" cmdlet.

Did I miss anything obvious? (script below)

#--
$adOU = [ADSI]"LDAP://ou=subsub,ou=sub,ou=mainou,dc=example,dc=com"

foreach ($adGroup in $adOU.psbase.children)
{
$name = $adGroup.Name

foreach ($user in $adGroup.psbase.invokeget("member"))
{
#P&P group naming convention:
#* each department's group begins with the prefix "CORPP&PDept"
#* Full administrative group (with access to all folders) is
"CORPP&PFullAdmins"
$grpName = [string]$adGroup.Name
if ($grpName.Contains("CORPP&PDept"))
{
$grpName = $grpName.replace("CORPP&PDept","")
}
else
{
$grpName = $grpName.replace("CORPP&P","")
}

if ([string]$user -and $grpName)
{

$u = [ADSI]"LDAP://$($user)"
if ((([int][string]$u.userAccountControl) -band 2) -eq 0)
{
##if account is enabled, then go ahead and display the record
echo "$($grpName):$($u.name):$($u.sAMAccountName)"
}
else
{
echo "$($grpName)::"
}
}
else
{
#no user, just echo the groupname
echo "$($grpName)::"
}
}
}
#--

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
active directory Walser Mark PowerShell 4 04-22-2008 08:55 AM
MIIS provisioning Active Directory with powershell script MA Alex PowerShell 0 05-25-2007 07:16 PM
Active Directory Dyawlak Vista security 3 05-24-2007 05:15 AM
Active Directory Lothar PowerShell 7 12-14-2006 09:29 AM
active directory Cameron Murray PowerShell 4 11-16-2006 11:01 AM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50