Configure Script to Show Date/Time in Output File

I need to have the script below modified to show the date/time included in the name of the" LOCAL_ADMIN_AUDIT.csv" file



strOutput = "LOCAL_ADMIN_AUDIT.csv"
strInput = "servers.txt"
strStartOfUserToRemove = "VHABALPageM"

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile(strInput, ForReading, False)
Set objOutput = objFSO.CreateTextFile(strOutput, True)
objOutput.WriteLine """ComputerName"",""GroupName"",""User Name"",""Type"",""Description"",""REMOVAL STATUS"""

While Not objInput.AtEndOfStream
      strComputer = Trim(objInput.ReadLine)
      If strComputer <> "" Then
            If Ping(strComputer) = True Then
                  On Error Resume Next
                  Set colGroups = GetObject("WinNT://" & strComputer & "")
                  If Err.Number = 0 Then
                        On Error Goto 0
                        colGroups.Filter = Array("group")
                        For Each objGroup In colGroups
                              If LCase(objGroup.Name) = "administrators" Then
                                    For Each objUser In objGroup.Members
                                          strStatus = ""
                                          strUserPath = Mid(objUser.aDSPath, 9)
                                          arrUserBits = Split(strUserPath, "/")
                                          If UBound(arrUserBits) = 2 Then
                                                strUserPath = arrUserBits(1) & "/" & arrUserBits(2)
                                          ElseIf UBound(arrUserBits) = 1 Then
                                                strUserPath = arrUserBits(0) & "/" & arrUserBits(1)
                                          Else
                                                strUserPath = arrUserBits(0)
                                          End If
                                          If UBound(arrUserBits) = 0 Then
                                                ' This identifies an instance where it only shows a SID
                                                strStatus = "UNKNOWN USER ACCOUNT"
                                                objOutput.WriteLine """" & strComputer & """,""" & objGroup.Name & """,""" & strUserPath & """,""" & objUser.Class & """,""" & objUser.description & """,""" & strStatus & """"
                                          Else
                                                If objUser.class = "User" Then
                                                'WScript.Echo vbTab & "USER:" & objUser.Name
                                                If StrComp(Left(objUser.Name, Len(strStartOfUserToRemove)), strStartOfUserToRemove, vbTextCompare) = 0 Then
                                                      'WScript.Echo "Removing " & objUser.Name & ": " & objUser.adsPath
                                                            objGroup.Remove(objUser.ADsPath)
                                                            strStatus = "REMOVED"
                                                      End If
                                          ElseIf objUser.class = "Group" Then
                                                'WScript.Echo vbTab & "GROUP:" & objUser.Name
                                          End If
                                          strGroupName = objGroup.Name
                                          strUserClass = objUser.Class
                                                On Error Resume Next
                                                strUserDescription = objUser.Description
                                                If Err.Number <> 0 Then strUserDescription = ""
                                                Err.Clear
                                                On Error Goto 0
                                                objOutput.WriteLine """" & strComputer & """,""" & strGroupName & """,""" & strUserPath & """,""" & strUserClass & """,""" & strUserDescription & """,""" & strStatus & """"
                                          End If
                                    Next
                              End If
                        Next
                  Else
                        objOutput.WriteLine """" & strComputer & """,""WMI ERROR " & Err.Number & ": " & Err.Description & """"
                        Err.Clear
                        On Error Goto 0
                  End If
            Else
                  objOutput.WriteLine """" & strComputer & """,""OFFLINE"""
            End If
vhaperbaugubAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try

strOutput = "LOCAL_ADMIN_AUDIT" & Format(Now(), "_yyyymmdd_hhmm") & ".csv"

Regards
0
vhaperbaugubAuthor Commented:
Getting this error:

Script:     c:\RemoveUsers
Line:        1
Char:       1
Error:       Type mismatch: 'Format'
Code:       800A000D
Source:    Microsoft VBScript runtime error
0
Rgonzo1971Commented:
Sorry VBS not VBA

strOutput = "C:\newfilename" & "_" & Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & "_" & Right("0" & Hour(Time), 2) & Right("0" & Minute(Time), 2) & ".csv"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vhaperbaugubAuthor Commented:
Thanks....its working now....one last thing....do you know what needs to be done to run this from Task Scheduler? I try to run it but it either doesnt run or I get errors.
0
Rgonzo1971Commented:
hi,

In Task Scheduler
Create task
Action tab / New / Start a program
Program/script: path to your batch script e.g. C:\test.bat
Add arguments (optional):
Start in (optional):
Click OK
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.