Solved

A little confused on DSQuery

Posted on 2006-11-30
9
726 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
  • 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Preface Having the need * to contact many different companies with different infrastructures * do remote maintenance in their network required us to implement a more flexible routing solution. As RAS, PPTP, L2TP and VPN Client connections are no…
This may not be a text book method to resolve VSS backup issues but it seemed to have worked on few of the Windows 2003 servers we had issues while performing a Volume Shadow Copy backup. If you have issues while performing a shadow copy backup usin…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now