?
Solved

Exporting the description field of a user account ?

Posted on 2010-01-08
6
Medium Priority
?
573 Views
Last Modified: 2012-05-08
Hi,

I want someone to help me regarding the below script. The below script should export a user account's "Description" field but it doesn't work. All other attributes are exported successfully. The "Description" field is returned blank.

Please note that i am working on a sub OU called "Sales" under the "People" OU so i put the "Sales" OU first then "People" OU (inside Out approach).

Appreciate your fast response.
On Error Resume Next

SET objRootDSE = GETOBJECT("LDAP://RootDSE")
strExportFile = "C:\MyExport.xls" 
 
strRoot = "OU=sales,OU=people,dc=domain,DC=com"
strfilter = "(&(objectCategory=Person)(objectClass=User))"
strAttributes = "sAMAccountName,userPrincipalName,givenName,sn," & _
                                "initials,displayName,physicalDeliveryOfficeName," & _
                                "telephoneNumber,mail,wWWHomePage,profilePath," & _
                                "scriptPath,homeDirectory,homeDrive,title,department," & _
                                "company,manager,homePhone,pager,mobile," & _
                                "facsimileTelephoneNumber,ipphone,info," & _
                                "streetAddress,postOfficeBox,l,st,postalCode," & _
                                "extensionAttribute1,extensionAttribute4,description,c"
strScope = "onelevel"
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

Open in new window

0
Comment
Question by:amyassein
5 Comments
 
LVL 31

Expert Comment

by:gowflow
ID: 26276573
Well a quick thought as we'r sunday and can only test this on monday AD is not active in week end.
1) try increasing page size from 1000 to 1200
2) Are you sure about syntax of field 'description' ? if yes try 'Description'

Let me know
rgds/gowflow
0
 
LVL 22

Expert Comment

by:dan_blagut
ID: 26276735
The field name is OK. IS the extensionattribute4 empty or trunked? If yes look at page size or use a dinamical array.

Dan
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 26277969
This what you need?
Set objSysInfo = CreateObject("ADSystemInfo") 
Set objUser = GetObject("LDAP://" & objSysInfo.UserName) 
MsgBox objUser.Description

Open in new window

0
 
LVL 1

Accepted Solution

by:
amyassein earned 0 total points
ID: 26291271
Hi guys,

No problem ... i found a simple DSQuery and DSGet commands to do this job.

Appreciate your prompt action always.

Thx
0
 
LVL 31

Expert Comment

by:gowflow
ID: 26292423
Fine and for the benefit of us and for future refrence, could you pls be kind enough to post the solution here in detail as this issue may serve others as well
rgds/gowflow
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question