Solved

A little confused on DSQuery

Posted on 2006-11-30
9
759 Views
Last Modified: 2008-01-09
I have found some links that help explain DSQuery and in someways I can get it to work but not the way I want it to output.

basically what I am looking to do is pull 5 data fields from active directory and outputs them to an excel spreedsheet.

the five pieces of information that I need is.

User ID, First name, Lastname, Account Active or disabled, and Dial-In (VPN) Access

I believe there is a program CSVDE or something of that nature that may do this but that seem more confusing than DSQuery.
0
Comment
Question by:spectragases
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18045204
For what criteria?
Do you want to just iterate through all OUs, or specify an OU to query, or ?
0
 

Author Comment

by:spectragases
ID: 18048839
all OU's
0
 

Author Comment

by:spectragases
ID: 18048843
pretty much.. I need to do a company wide report.
0
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
LVL 67

Expert Comment

by:sirbounty
ID: 18048862
It'll take me a bit to put something together and I've got to run out for now.
Will work on this when I get back in a few hours...
0
 

Author Comment

by:spectragases
ID: 18049334
I did some more digging and so far.. this kind of works

dsquery user -limit 0 | dsget user -samid -display -disabled > report.txt

now... just missing the VPN / Dialin access

0
 

Author Comment

by:spectragases
ID: 18053582
ok.... getting closer....

dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User))" -attr samAccountName name msNPAllowDialin -disabled -limit 0 > report2.txt

when I use the -disabled filter command, nothing shows up

0
 
LVL 67

Accepted Solution

by:
sirbounty earned 400 total points
ID: 18058068
sorry for the delay - had something come up.
I don't really care for dsget/dsquery, but here's a script that should accomplish what you're after:
It's a script I've used for something along those lines - slightly adjusted for your purposes.
Bear in mind it doesn't 'create' an Excel file, it creates a CSV file.  If you need it exported to a valid XLS, let me know and I'll adjust it.

'Begin code copy here
Dim objFSO, strFileName, RptFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
strFileName="C:\Output.csv"
Set RptFile = objFSO.CreateTextFile(strFileName)

Dim objRoot, objDomain
Set objRoot = GetObject("LDAP://RootDSE")
Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))

EnumOUs(objDomain.ADsPath)
RptFile.Close
Set RptFile=Nothing
Set objUsers=Nothing
Set objOUs=Nothing
Set objDomain=Nothing
Set objRoot=Nothing
Set objFSO=Nothing
wscript.quit

Sub EnumOUs(adspath)
    Dim objOUs, OU
    Set objOUs = GetObject(adspath)
    objOUs.Filter = Array("OrganizationalUnit")
    Call EnumUsers(objOUs.ADsPath)
    For Each OU In objOUs
        wscript.echo "Processing " & Replace(OU.Name, "OU=", "")
        RptFile.WriteLine Replace(Ucase(OU.Name), "OU=", "")
        Call EnumOUs(OU.ADsPath)
    Next
End Sub

Sub EnumUsers(adspath)
    Dim objUsers, User
    Set objUsers = GetObject(adspath)
    objUsers.Filter = Array("User")
    RptFile.WriteLine
    For Each User In objUsers
       RptFile.WriteLine User.sAMAccountName & "," & User.sn & "," & User.givenName & "," & _
         User.AccountDisabled & "," & User.msNPAllowDialin
    Next
    RptFile.WriteLine
End Sub
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Learn about cloud computing and its benefits for small business owners.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question