-1

I am writing a script in vbscript, and I got this error:

800A000D Format mismatch:

This is the code:

Set objOU = GetObject("LDAP://OU=Usuarios,OU=xxx,DC=yyy,DC=uru,DC=zzz")

objOU.Filter = Array("group")

Dim ts, fso, parentFolder, folder, folderDirectory
    ts = CStr(Format(Now(),"#dd-mm-yyyy#")) 
    Set fso = CreateObject("Scripting.FileSystemObject")
    set parentFolder = fso.GetParentFolderName(WScript.ScriptFullName)
    folderDirectory = parentFolder & ts

Dim outputFileName
    outputFileName = ts & ".csv"

set outputFile = fso.CreateTextFile(outputFileName, TRUE)
For Each objGroup In objOU
  If InStr(1, objGroup.cn, "MIS_") = 1 Then
      For Each objMember In objGroup.Members
        outputFile.WriteLine objGroup.cn & ";" & objMember.sAMAccountName & ";" & objMember.displayname
      Next
  End If
Next

Thanks!

1 Answers1

0

This is caused by the function Format, which is not known by VBScript.

You can use FormatDateTime instead, but with limited formatting: https://www.w3schools.com/asp/func_formatdatetime.asp

Tip: Don't use Now() but Date() to avoid it outputs the time part too.

To gain your requested format you could try to use one of the defined formats of FormatDateTime and exchange . by - by using the Replace function.

If none fits you would have to create your own function which then splits the date into separate values for

  • year: Year(Date())
  • month: Month(Date())
  • day: Day(Date())

and concatenates them as you want/need.

AHeyne
  • 3,377
  • 2
  • 11
  • 16