?
Solved

A little confused on DSQuery

Posted on 2006-11-30
9
Medium Priority
?
764 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
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 1600 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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

by Batuhan Cetin In this article I will be guiding through the process of removing a failed DC metadata from Active Directory (hereafter, AD) using the ntdsutil tool in a Windows Server 2003 environment. These steps are not necessary in a Win…
Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

801 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