date variable in VBscript

Erdrick33
Erdrick33 used Ask the Experts™
on
Regarding a question I posted here: http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/2003_Server/Q_22602293.html
Chris gave me an excellent script to run, however I'm looking at automating it, however using a constant for the file name will not work.  I'm looking to use a date function to output the filename with the date as follows: mm-dd-yyyy

Thanks so much in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006

Commented:
Change

Const REPORT_FILE = "Users.csv"

to

Dim REPORT_FILE
Dim Today

REPORT_FILE =

Today = Date()
REPORT_FILE = Month(Today) & "-" & Day(Today) & "-" & Year(Today)
PowerShell Developer
Top Expert 2010
Commented:

Hey again :)

I hang out in this one a lot as well. Here's the upgrade:



' Correct this path so it matches the OU you're looking for

Const AD_OU = "OU=Fortworth,OU=SomeOtherOU,DC=YourDomain,DC=local"

Const ADS_UF_ACCOUNTDISABLE = &H2

Set objOU = GetObject("LDAP://" & AD_OU)
objOU.Filter = Array("user")

strDay = Day(Date)
If strDay < 10 Then
    strDay = "0" & strDay
End If
strMonth = Month(Date)
If strMonth < 10 Then
     strMonth = "0" & strMonth
End If
strYear = Year(Date)

strFileName = strMonth & "-" & strDay & "-" & strYear & ".csv"

Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.OpenTextFile(strFileName, 2, True, 0)

For Each objUser in objOU
     intUAC = objUser.Get("userAccountControl")
     If intUAC And ADS_UF_ACCOUNTDISABLE Then
          objFile.WriteLine objUser.Get("sAMAccountName") & "," &_
               objUser.Get("name") & ",Account Disabled"
     Else
          objFile.WriteLine objUser.Get("sAMAccountName") & "," &_
               objUser.Get("name") & ",Account Enabled"
     End If
Next

Set objFile = Nothing
Set objFileSystem = Nothing

Set objOU = Nothing

Author

Commented:
Appreciate it once again Chris,
I'm not that familiar with VB yet, and I was trying to do this calling WSH, using the shell command, something like retval = ("%date:/=-%.csv) and I couldn't get it to work.  Thanks again, you're a life saver.

Cheers,
Erdrick33
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Chris DentPowerShell Developer
Top Expert 2010

Commented:

You're welcome :)

Chris

Author

Commented:
Chris, sorry, forgot to ask you one other thing in that one... how would I go about changing the path to a server share in this program?

Author

Commented:
NM Chris, I figured it out... seems like the programming knowledge might be seeping back in.

Cheers
Chris DentPowerShell Developer
Top Expert 2010

Commented:

Just a case of prefixing it onto the File name variable. Something like this:

Const FILE_SERVER = "\\SomeServer\SomeShare\"

strFileName = FILE_SERVER & strMonth & "-" & strDay & "-" & strYear & ".csv"

Should work well enough.

Chris
Chris DentPowerShell Developer
Top Expert 2010

Commented:

:)

Just a slight note on the above. If it's running as an automated task I normally prefer to create the file locally, then move it onto the server as a separate step. Then if the server is unavailable you at least have the local copy to work with.

Chris

Author

Commented:
Thanks for the tip, but I'm running it from the server, so if it's down, I suppose it wont run anyhow :o)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial