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
Answers (1)
You can use dsquery and dsget to get the info from AD
http://technet.microsoft.com/en-us/library/cc725702(v=ws.10).aspx
http://technet.microsoft.com/en-us/library/cc732535(v=ws.10).aspx
Comments:
-
you can pipe dsquery and dsget to run together
dsquery user -name steve* | dsget user -profile - SMal.tmcc 12 years ago