Re: Exporting user info
"Glenn Clark" <NOSPAMPLEASEglenn.btn@gmail.comNOSPAMPLEASE> wrote in message
news:uAsNCasKJHA.5460@TK2MSFTNGP03.phx.gbl...
> Hi All
>
> I am about to do an upgrade form sbs2000 to 2003 and need to export AD
> user data. I have managed to find a script which tells me all the email
> addresses but I need to export a full list of users which tell me their
> drive letter and location for mapped home folder and what login script is
> set for them. Is there an easy way I can get this information exported
>
> Many thanks
>
> Glenn
>
The attribute values you refer to are homeDrive, homeDirectory, and
scriptPath. You also want distinguishedName (or DN) and sAMAccountName
(pre-Windows 2000 logon name). You can use Joe Richards' free adfind command
line utility to export these values for all users.
http://www.joeware.net/freetools/tools/adfind/index.htm
You could also use the command line tools dsquery and dsget. Otherwise, the
following VBScript program outputs the values for all users. It should be
run at a command prompt with the output redirected to a text file. For
example, if the code is saved in a text file called GetUsers.vbs, you could
use the command:
cscript //nologo GetUsers.vbs > report.csv
This assumes you are in the folder were GetUsers.vbs is saved. Otherwise,
you must also specify the path to the *.vbs file. The output is saved in
report.csv, which can be read into a spreadsheet. The VBScript program
follows:
=========
Option Explicit
Dim objRootDSE, strDNSDomain, adoCommand, adoConnection
Dim strBase, strFilter, strAttributes, strQuery, adoRecordset
Dim strDN, strNTName, strHomeDir, strHomeDrive, strScript
Dim arrAttrValues
' Determine DNS domain name.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"
' Search for all users.
strFilter = "(&(objectCategory=person)(objectClass=user))"
' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName,sAMAccountName," _
& "homeDirectory,homeDrive,scriptPath"
' Construct the LDAP query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
' Output heading line.
Wscript.Echo """Distinguished Name"",""NT Name"",""Home Directory""," _
& """Home Drive"",""Logon Script"""
' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve single-valued strings.
strDN = adoRecordset.Fields("distinguishedName").Value
strNTName = adoRecordset.Fields("sAMAccountName").Value
strHomeDir = adoRecordset.Fields("homeDirectory").Value
strHomeDrive = adoRecordset.Fields("homeDrive").Value
strScript = adoRecordset.Fields("scriptPath").Value
' Create array of string values to display.
arrAttrValues = Array(strDN, strNTName, strHomeDir, _
strHomeDrive, strScript)
' Display array of values in a comma delimited line, with each
' value enclosed in quotes.
Wscript.Echo CSVLine(arrAttrValues)
' Move to next record in recordset.
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
adoConnection.Close
Function CSVLine(ByVal arrValues)
' Function to convert array of values into comma delimited
' values enclosed in quotes.
Dim strItem
CSVLine = ""
For Each strItem In arrValues
' Replace any embedded quotes with two quotes.
If (strItem <> "") Then
strItem = Replace(strItem, """", """" & """")
End If
' Append string values, enclosed in quotes,
' delimited by commas.
If (CSVLine = "") Then
CSVLine = """" & strItem & """"
Else
CSVLine = CSVLine & ",""" & strItem & """"
End If
Next
End Function
=========
If you have Exchange, email addresses are in the multi-valued attribute
proxyAddresses. This can also be exported, but you say you have already have
a script that does this. Email addresses can also be in the mail attribute.
The above script is based on the following example, which also shows how to
handle multi-valued attributes (like proxyAddresses):
http://www.rlmueller.net/DocumentUsers.htm
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--