Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 776
  • Last Modified:

A little confused on DSQuery

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
spectragases
Asked:
spectragases
  • 4
  • 3
1 Solution
 
sirbountyCommented:
For what criteria?
Do you want to just iterate through all OUs, or specify an OU to query, or ?
0
 
spectragasesAuthor Commented:
all OU's
0
 
spectragasesAuthor Commented:
pretty much.. I need to do a company wide report.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
sirbountyCommented:
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
 
spectragasesAuthor Commented:
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
 
spectragasesAuthor Commented:
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
 
sirbountyCommented:
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now