From: Wolfie on
Hi,

I'm looking to write a script that will list the following information (as
showing in AD Users and Computers) for all users in our domain:

Display Name or Username
Login Script
Profile Path
Home Directory
Terminal Services Profile Path
Terminal Services Home Directory

We are in the process of replacing one of our servers that houses home
directories and profiles for some of our users so I need to identify which
accounts will need to be modified.

Can anyone tell me where to start? I looked around online and found several
that will give me some of the information but I couldn't figure out how to
piece them together nor could I figure out how to run them against all users
instead of a specific one.

Thanks in advance.
From: ekrengel on
On Dec 31, 9:40 am, Wolfie <Wol...(a)discussions.microsoft.com> wrote:
> Hi,
>
> I'm looking to write a script that will list the following information (as
> showing in AD Users and Computers) for all users in our domain:
>
> Display Name or Username
> Login Script
> Profile Path
> Home Directory
> Terminal Services Profile Path
> Terminal Services Home Directory
>
> We are in the process of replacing one of our servers that houses home
> directories and profiles for some of our users so I need to identify which
> accounts will need to be modified.
>
> Can anyone tell me where to start?  I looked around online and found several
> that will give me some of the information but I couldn't figure out how to
> piece them together nor could I figure out how to run them against all users
> instead of a specific one.
>
> Thanks in advance.

How about something like this: It will export all enabled users from
the domain into an excel spreadsheeet "C:\export.xls". There are
different adsi attributes that you can export and edit in the script.
A guide that I love to use which is more visual to find what I need is
here: http://www.selfadsi.org/user-attributes-w2k3.htm

Rlmuller's ADO search tips are also a great starting point for
learning how to properly search AD, and it will explain most of what
is done in the script. You can read up on it here:
http://www.rlmueller.net/ADOSearchTips.htm

If you need help editing, let me know...

Const Excel2007 = 12

sXLS = "C:\export.xls"

On Error Resume Next
Set objRootDSE = GetObject("LDAP://rootDSE")
If (Err.Number <> 0) Then
On Error GoTo 0
WScript.Echo "Domain not found!"
WScript.Quit
End If
On Error GoTo 0

strDNSDomain = objRootDSE.Get("defaultNamingContext")

'Start the ADO connection
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection

'Set the ADO connection query strings
StartNode = strDNSDomain
SearchScope = "subtree"

FilterString = "(&(objectCategory=person)(objectClass=user)" _
& "(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"

Attributes = "adspath"

'Create the LDAP-Query
LDAPQuery = "<LDAP://" & StartNode & ">;" & FilterString & ";" _
& Attributes & ";" & SearchScope

objCommand.CommandText = LDAPQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False

On Error Resume Next
Set objRecordSet = objCommand.Execute
If (Err.Number <> 0) Then
On Error GoTo 0
WScript.Echo "There was a problem searching AD! Check your
filter..."
WScript.Quit
End If
On Error GoTo 0

On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
On Error GoTo 0
WScript.Echo "Excel Application not found!"
WScript.Quit
End If
On Error GoTo 0

With objExcel
.Application.DisplayAlerts = False
.Visible = True
.Workbooks.Add
.Cells(1,1).Value = "Alias"
.Cells(1,2).Value = "First Name"
.Cells(1,3).Value = "Last Name"
.Cells(1,4).Value = "Address"
.Cells(1,5).Value = "City"
.Cells(1,6).Value = "State"
.Cells(1,7).Value = "Zip"
.Cells(1,8).Value = "Phone"
.Cells(1,9).Value = "Department"
.Cells(1,10).Value = "Office"
.Cells(1,11).Value = "Title"
xRow = 1 : yColumn = 1
Do Until yColumn = 12
With .Cells(xRow,yColumn)
.Font.Bold = True
.Font.Size = 11
.Interior.ColorIndex = 11
.Interior.Pattern = 1
.Font.ColorIndex = 2
.Borders.LineStyle = 1
.WrapText = True
End With
yColumn = yColumn + 1 : Loop
x = 2 : y = 1
If NOT objRecordSet.eof Then
objRecordSet.MoveFirst
While Not objRecordset.EOF
Set objUser = GetObject(objRecordSet.Fields("AdsPath").Value)
strAlias = objUser.samAccountName
strFirst = objUser.givenName
strLast = objUser.sn
strAddress = objUser.streetAddress
strCity = objUser.l
strState = objUser.st
strZip = objUser.postalCode
strPhone = objUser.telephoneNumber
strDepartment = objUser.department
strOffice = objUser.physicalDeliveryOfficeName
strTitle = objUser.title
y1 = y
.Cells(x,y1).Value = strAlias
y1 = y1 + 1
.Cells(x,y1).Value = strFirst
y1 = y1 + 1
.Cells(x,y1).Value = strLast
y1 = y1 + 1
.Cells(x,y1).Value = strAddress
y1 = y1 + 1
.Cells(x,y1).Value = strCity
y1 = y1 + 1
.Cells(x,y1).Value = strState
y1 = y1 + 1
.Cells(x,y1).Value = strZip
y1 = y1 + 1
.Cells(x,y1).Value = strPhone
y1 = y1 + 1
.Cells(x,y1).Value = strDepartment
y1 = y1 + 1
.Cells(x,y1).Value = strOffice
y1 = y1 + 1
.Cells(x,y1).Value = strTitle
x = x + 1
objRecordSet.MoveNext
Wend
End If
.Columns("A:K").Select
.Selection.HorizontalAlignment = 3 'center all data
.Selection.Borders.LineStyle = 1 'apply borders
.Columns("A:AH").EntireColumn.AutoFit 'autofit all columns
appVerInt = split(objExcel.Version, ".")(0)
If appVerInt-Excel2007 >=0 Then
.ActiveWorkbook.SaveAs(sXLS), 56 'office 2007
Else
.ActiveWorkbook.SaveAs(sXLS), 43 'office 2003
End If
.Quit
End With
Set objExcel = Nothing

msgbox "Done!"
WScript.Quit



From: Richard Mueller [MVP] on

"Wolfie" <Wolfie(a)discussions.microsoft.com> wrote in message
news:A2485AC7-DBDA-46CE-A952-E22A2D0D0708(a)microsoft.com...
> Hi,
>
> I'm looking to write a script that will list the following information (as
> showing in AD Users and Computers) for all users in our domain:
>
> Display Name or Username
> Login Script
> Profile Path
> Home Directory
> Terminal Services Profile Path
> Terminal Services Home Directory
>
> We are in the process of replacing one of our servers that houses home
> directories and profiles for some of our users so I need to identify which
> accounts will need to be modified.
>
> Can anyone tell me where to start? I looked around online and found
> several
> that will give me some of the information but I couldn't figure out how to
> piece them together nor could I figure out how to run them against all
> users
> instead of a specific one.
>
> Thanks in advance.

The attributes you want (I believe) are:

cn,sAMAccountName,displayName,scriptPath,profilePath,homeDirectory,msTSProfilePath,msTSHomeDirectory

I have an example VBScript program that uses ADO to retrieve the values of
specified attributes for all users in the domain linked here:

http://www.rlmueller.net/GenericADO.htm

The program prompts for the base of the search (if you enter nothing, the
base is the entire domain), the LDAP syntax filter to use, and a comma
delimited list if attribute values to retrieve. The filter for all user
objects would be:

(&(objectCategory=person)(objectClass=user))

You would run the script at a command prompt and redirect the output to a
text file. Another option is Joe Richards' free adfind utility. See this
link:

http://www.joeware.net/freetools/tools/adfind/index.htm

You would use the same filter and attribute list as above.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 | 
Pages: 1
Prev: SPAM
Next: How to get the path of the vbs files