/build/static/layout/Breadcrumb_cap_w.png

Search for all users with a specific server name in the Profilepath

Using VBS, I would like to know how to return a list of all users whose profile directory begins with \\specificservername\Profile$

Currently, I am using this script:

set objRootDSE = getobject("LDAP://RootDSE")
strExportFile = "C:\temp\MyExport.xlsx"

strRoot = objRootDSE.GET("DefaultNamingContext")
strfilter = "(&(objectCategory=Person)(objectClass=User))"
strAttributes = "sAMAccountName,profilepath,homedirectory"
strScope = "subtree"

SET cn = CREATEOBJECT("ADODB.Connection")
SET cmd = CREATEOBJECT("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
cmd.ActiveConnection = cn

cmd.Properties("Page Size") = 1000

cmd.commandtext = "<LDAP://" & strRoot & ">;" & strFilter & ";" & _
strAttributes & ";" & strScope

SET rs = cmd.EXECUTE

SET objExcel = CREATEOBJECT("Excel.Application")
SET objWB = objExcel.Workbooks.Add
SET objSheet = objWB.Worksheets(1)

FOR i = 0 To rs.Fields.Count - 1
objSheet.Cells(1, i + 1).Value = rs.Fields(i).Name
objSheet.Cells(1, i + 1).Font.Bold = TRUE
NEXT

objSheet.Range("A2").CopyFromRecordset(rs)
objWB.SaveAs(strExportFile)
rs.close
cn.close
SET objSheet = NOTHING
SET objWB =  NOTHING
objExcel.Quit()
SET objExcel = NOTHING

Wscript.echo "Script Finished..Please See " & strExportFile

 

 

This takes all users in my AD and exports them to a spreadsheet.

What I really want to do is to export only users with a specific server name to this spread sheet.  Basically, I want to narrow don my results based on a particular server name.

 

Thanks.

 

-John


0 Comments   [ + ] Show comments

Answers (1)

Posted by: SMal.tmcc 12 years ago
Red Belt
1

Comments:
  • you can pipe dsquery and dsget to run together
    dsquery user -name steve* | dsget user -profile - SMal.tmcc 12 years ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ