Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating columns in excel with vbscript

Status
Not open for further replies.

matrix101

MIS
Jun 5, 2007
60
US
Hello, I have a script that will take all disabled accts in AD and place them into a .csv file and it work fine. I actaully need to be able to create an xls file instead. I changed the .cvs to .xls and it created the excel file but the information isn't in columns, any ideas on what code I might need to change or add???

I appreciate the help! Below is the code I'm using.



' List All the Disabled User Accounts in Active Directory

Const ADS_UF_ACCOUNTDISABLE = 2
constForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
set oShell= Wscript.CreateObject("WScript.Shell")
Script = Wscript.ScriptFullName
ScriptPath = objFSO.GetFolder(Script & "\..").Path
qut = Chr(34)
Set ReportFile = objFSO.CreateTextFile( ScriptPath & "\Corp-DisableAccountReport.xls")

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<GC://" & strDNSDomain & ">;(objectCategory=User)" & _
";userAccountControl,displayName,sAMAccountName,modifyTimeStamp,distinguishedName;subtree"
Set objRecordSet = objCommand.Execute

intCounter = 0
Do Until objRecordset.EOF
intUAC=objRecordset.Fields("userAccountControl")
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
ReportFile.WriteLine objRecordset.Fields("displayName") & "," & objRecordset.Fields("sAMAccountName") & "," & objRecordset.Fields("modifyTimeStamp")
intCounter = intCounter + 1
End If
objRecordset.MoveNext
Loop

ReportFile.WriteLine VbCrLf & "A total of " & intCounter & " accounts are disabled."

objConnection.Close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top