ClioSport.net

Register a free account today to become a member!
Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • When you purchase through links on our site, we may earn an affiliate commission. Read more here.

A little AD Powershell help, please?



Darren S

ClioSport Club Member
Chaps,

Just wondered if anyone could help me with a simple Powershell query out of AD? I've had a look online, but appear to be getting slightly contradictory feedback.

Essentially, I just want an export (csv would be great, though I'm happy enough with txt) of all usernames within the domain along with the 'Member Of' listings.

So ideally, I'd have something that displayed something like "Darren Smith | domain admins | IT Dept | Remote Desktop Users" etc.

Any help would be much appreciated!

Cheers,
D.
 

welshname

ClioSport Club Member
I'm dire at powershell but a a look on StackOverflow brings up this:

$memberOf = @{n='MemberOf';e={ ($_.MemberOf -replace '^CN=([^,]+).+$','$1') -join ';' }}

Get-QADUser -SizeLimit 0 | `
Select-Object Name,DN,SamAccountName,$memberOf | `
Export-Csv report.csv
 
  Cupra
I've got a .vbs that puts user names and group membership into Excel. You can probably tweak it to get the columns that you want.

Code:
On Error Resume Next

Dim objXL
Set objXL = WScript.CreateObject("Excel.Application")
objXL.Visible = True

objXL.WorkBooks.Add
objXL.Cells(1, 1).Value = "User Name"
objXL.Cells(1, 2).Value = "Groups"

Dim intIndex
intIndex = 2


 
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
 
Set objOU = GetObject _
   ("LDAP://OU=Users,OU=Amsterdam,DC=company,DC=corp,DC=local")
  
objOU.Filter= Array("user")
 
For Each objUser In objOU
    objXL.Cells(intIndex, 1).Value =objUser.cn
    'WScript.Echo vbTab & "Primary Group ID: " & _
    '    objUser.Get("primaryGroupID")
  
    arrMemberOf = objUser.GetEx("memberOf")
  
    If Err.Number <>  E_ADS_PROPERTY_NOT_FOUND Then
        For Each Group In arrMemberOf
            objXL.Cells(intindex, 2).Value = Group
			intIndex = intIndex + 1
			objXL.Cells(intIndex, 1).Select
        Next
    Else
        'WScript.Echo vbTab & "memberOf attribute is not set"
        Err.Clear
    End If
    'WScript.Echo 
Next

objXL.columns("A:A").EntireColumn.AutoFit
objXL.Columns("B:B").EntireColumn.AutoFit
 


Top