Enclose attribute (variable) in quotes ""
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Enclose attribute (variable) in quotes ""
My code works fine but I have not successfully been able to have each output variable be enclosed by quotes which is a late ask so I did not want to transfer this to ps. How can I ensure each variable/attribute be written as "username";"givenName" etc instead of username;givenName? Code attached. Thank you in advance for the help.
- Attachments
-
- code.txt
- (8.02 KiB) Downloaded 525 times
Re: Enclose attribute (variable) in quotes ""
Just add quotes.
VBScript Code
Double-click the code block to select all.qq="""" qc=""",""" line = qq & myvar1 & qc & myvar2 & qc & myvar3 & qqThat gives you quotes and commas.
Re: Enclose attribute (variable) in quotes ""
This is closer to what you want and is easier to manage.
You can do the header by looping the fields also. I will leave that to you.
You can do the header by looping the fields also. I will leave that to you.
VBScript Code
Double-click the code block to select all.set objFSO = CreateObject("scripting.filesystemobject") set objFile = objFSO.createtextfile(".\Review" & "_" & Year(Now()) & Month(Now()) & Day(Now()) & ".txt" , 2, True) strDNSDomain = GetObject("LDAP://RootDSE").Get("defaultNamingContext") strBase = "<LDAP://" & strDNSDomain & ">" strFilter = "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2))" strAttributes = "samaccountname,lastLogonTimeStamp,useraccountcontrol,pwdLastset,employeetype,company,mail,sn,givenName,modifyTimeStamp,initials,manager,title,department,employeeid,l,streetAddress,postalCode,postofficeBox,st,manager,co,TelephoneNumber,physicalDeliveryOfficeName,mobile" adoCommand.CommandText = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" Set adoCommand = CreateObject("ADODB.Command") adoCommand.ActiveConnection = adoConnection adoCommand.Properties("Page Size") = 500 Set adoRecordset = adoCommand.Execute Do Until adoRecordset.EOF With adoRecordset WriteField .Fields("givenName").Value WriteField .Fields("initials").Value WriteField .Fields("sn").Value WriteField .Fields("samaccountname").Value WriteField .Fields("mail").Value WriteField .Fields("employeeID").Value WriteField .Fields("streetAddress").Value WriteField .Fields("l").Value WriteField .Fields("st").Value WriteField .Fields("postalCode").Value WriteField .Fields("co").Value WriteField .Fields("physicalDeliveryOfficeName") WriteField .Fields("TelephoneNumber").Value WriteField .Fields("mobile").Value WriteField .Fields("company").Value WriteField .Fields("title").Value WriteField .Fields("department").Value WriteField .Fields("manager").Value WriteField .Fields("postOfficeBox").Value intUAC=.Fields("userAccountControl").Value If intUAC AND 2 Then 'ADS_UF_ACCOUNTDISABLE = 2 strStatus="DISABLED" Else strStatus="ENABLED" End If WriteField strStatus WriteField ConvertDate(.Fields("pwdLastSet").Value) ' specil handling for last column just close quotes strDate = ConvertDate(.Fields("lastLogonTimeStamp").Value) objFile.WriteLine """" & strDate & """" .MoveNext Loop Wscript.echo "Script Complete" objFile.Close Function WriteField( strValue ) If IsNull(strValue) Then objFile.Write "," 'just use comma for empty field Else objFile.Write strValue & """," ' close quote and add comma. End If End Function Function ConvertDate( adDate ) If (TypeName(adDate) = "Object") Then Set objDate = .Fields("pwdLastSet").Value dtmPwdLastSet = Integer8Date(objDate, lngBias) Else dtmPwdLastSet = #1/1/1601# End If End Function