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.
I have tried running the below as part of my script and the cmd prompt flashes and disappears.
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
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 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