Solved

A little confused on DSQuery

Posted on 2006-11-30
9
736 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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