![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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)::" } } } #-- |
![]() |
| 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 |