Active Directory Query Groups

jason2

New Member
Joined
Apr 2, 2009
Messages
6
I have been working on some code to get Excel to retrieve every group that a user is a member of in AD. This will be for comparing users permission and I was looking to get the code onto an excel spreadsheet so I could sort the data. I have been successful using cmd to get the info into a txt file and pasting it into excel but I want to do this automatically so that others can use it. I'm happy to put it to a txt file using VBA and then I can copy in and sort using VBA.

I can run the below in a command prompt and it comes back with the complete list.
Code:
dsquery user -name "Users Name" |dsget user -memberof> "C:\temp\members.txt"

I have tried running the below as part of my script and the cmd prompt flashes and disappears.

Code:
Sub RetreiveGroups1()
    Dim objShell As Object
    Dim objWshScriptExec As Object
    Dim objStdOut As Object
    Dim rline As String
    Dim strline As String
    Dim User1 As String
    Dim command As String
    User1 = Sheets("cover").Range("B4")
    Set objShell = CreateObject("WScript.Shell")
    command = "cmd.exe /S /C ruby dsquery user -name " & User1 & " |dsget user -memberof> C:\temp\members.txt"
    Set objWshScriptExec = objShell.Exec(command)
    Worksheets("Sheet1").Activate
    Call CopyText
    Call Sort
   
End Sub
I also tried the chr(34) to sort the quotes issue.

I ran a cmd.exe /S /K which leaves the command prompt box on the screen but even when ran from there won't accept the command that usually works.

I would appreciate it if someone could point out where I'm going wrong as this is more advanced stuff than I normally do in VBA.

Thanks in advance,

Jason
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top