/bundles/itninjaweb/img/Breadcrumb_cap_w.png

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   [ - ] Hide Comments

Comments

Please log in to comment

Answer this question or Comment on this question for clarity

Answers

1
Answered 08/28/2012 by: SMal.tmcc
Red Belt

  • you can pipe dsquery and dsget to run together
    dsquery user -name steve* | dsget user -profile
Please log in to comment
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja

Share