Advertisement
Advertisement
| 08.27.2008 at 08:52AM PDT, ID: 23682491 | Points: 500 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: |
fully code, ive played about with it a little bit, but the main problem is the above
'**********************************************************************************************************
'
' File: AllUsersLastLogon.vbs
' Created: July 2003
' Version: 1.2 (the first version is also at the cwahington site)
' Author: Christian Graversen (graver@doktor.dk)
'
' DESCRIPTION:
' This script gets the argument from a HTML site. The argument is the name of the W2K domain.
' It will take the first DC from the OU 'Domain Controllers' to check every users lastlogon.
' Every users last logon is checked on all DC's, and is written into an array. The array is
' then taken apart, isolating the date-time-year and the DC. Every element's date of the Array
' is then check against the other element's date for the same user, to get which date is the latest.
' The latest date is then checked to see if it is older than 30 days.
' At the same time the script checks to see if the Account is disabled, when it is created, and if it
' has ever logged on.
' The following data is written to an excel sheet (the following represents a column in excel);
' * User-ID
' * Last Logon server
' * Date and Time of last logon
' * Logon older than 30 days
' * Has never logged on at all.
' * Account Disabled
' * Account created at
' * Flag error Code
' (The following column has been added in this version. They could come in handy.)
' * Users Full name
' * OU path
' * LDAP path
' * Special Error codes
'
' Beside the excel sheet, a status report is written and presentet in HTML format.
' Be aware that the script might take some hours depending on the number of users and DC's
' in your AD.
'
' SUPPORT:
' No support for this script is implied. If you find ways to
' improve the script or find a bug with it let me know. If I can fix it, I
' will, if I can't I won't. You should test this script before using
' in your own production environment. Use at your own risk.
' If you like I could send you the HTML file for Domain input as well.
'
' CREDITS:
' Thanks to cwashington.netreach.net for some of the scripting
' clips that helped to make this utility.
' Thanks also to the microsoft.puplic.scripting.wsh and the
' microsoft.public.active.directory.interfaces news groups for the
' continued help.
' A special thanks to Adrian Mink, which script this is based on.
'
' USAGE:
' Usage: cscript AllUsersLastLogon.vbs DomainName
' Usage: AllUsersLastLogon.vbs DomainName
' Usage: Get the Domain name from an HTML page, that then call AllUsersLastLogon.vbs
'
' (You can get the HTM page and CSS file, by contacting me)
'
'**********************************************************************************************************
'Option Explicit
Public DomainName, DomainName2, strDN, concat, obj
Dim objExcel, ws, WriteFile, WriteFilePath
Dim oConnection, oCommand, oRoot, strDomain
Dim strPath, strQuery, oResults, sPosition
Dim CRLF
Dim FolderPath
Dim fso, WshShell
Dim User, DC, ShowResult
Dim Pos1, Pos2, Pos3, Pos4, Pos5, Pos6
Dim OldYearTime, OldYearTimeLen, DateTimeCounter
Dim NewYearTime, NewYear, OldYear, CompareYear, NewYearVal, OldYearVal
Dim NewDate, NewDateTime, NewMonth, OldDate, OldDateTime, OldMonth, NewDay, NewDayVal, OldDay, OldDayVal
Dim NewTime, NewTimeVal, OldTime, OldTimeVal
Dim LogonDC, intButton
Dim i, x, c, UserObj
Dim UserLastLogonArray()
Dim MyArraySize
Dim MyDateAndTimePos, MyPeriodPos, a, MessageVal
Dim Flag, CodeAccDis, Code
Dim DCName, UserInDomain, DomainString, userName, iElement, UserVal
Dim strWhenCreated, objUser, DateTimeVal
Dim Users30DaysNo
Dim UserInDomainNo
Dim UsersNoLogonNo
Dim AccountDisNo, FileTime, ExcelPath, NoLastLoginCounter, UserNeverLoggedOn
'**********************************************************************************************************
' Preliminary work and functions
'**********************************************************************************************************
Function ControlSyntax()
' If WScript.arguments.Count <> 1 Then
' MsgBox "Syntax error. Usage: cscript badauths.vbs loginname"
' Exit Sub
' End If
' DomainName = "dc=" & WScript.arguments(0) & ",dc=dk"
' DomainName2 = WScript.arguments(0) & ".dk"
End Function
'Creates the folder if necssesary
Function MakeFolder()
If Not fso.FolderExists(FolderPath) Then
fso.CreateFolder ("C:\Temp")
End If
End Function
'Creates the file if necssesary, and writes the headers of the rows
Function MakeFile()
If (fso.FileExists(WriteFilePath + ".htm")) Then
fso.DeleteFile (WriteFilePath + ".htm")
End If
Set WriteFile = fso.OpenTextFile(WriteFilePath & "_" & FileTime & ".htm", 8, True, -2)
WriteFile.Write "<html>" & vbCrLf & "<head>" & vbCrLf
WriteFile.Write "<link rel='stylesheet' TYPE='text/css' HREF='http://dkweb:12345/css/default.css'>" & vbCrLf
WriteFile.Write "</head>" & vbCrLf & "<body bgcolor='#98FB98'>" & vbCrLf
WriteFile.Write "<script language='vbscript'>" & vbCrLf
WriteFile.Write "Set WShell = CreateObject(" & Chr(34) & "WScript.Shell" & Chr(34) & ")" & vbCrLf
WriteFile.Write "</script>" & vbCrLf
WriteFile.Write "<h1 class='H4'>User last logon was ...</h1>" & vbCrLf
WriteFile.Write "<hr color='#6B8E23' width='100%'><br>" & vbCrLf
WriteFile.Write "<font class='LogText'>Script startet at " & Date & " " & Time & vbCrLf
WriteFile.Write "<br><hr color='#6B8E23' width='100%'><br><font class='LogText'>" & vbCrLf
WriteFile.Write "<br><br><h3>STATUS:" & vbCrLf & vbCrLf
Set objExcel = CreateObject("EXCEL.application")
objExcel.Visible = True
objExcel.Workbooks.Add
Set ws = objExcel.Worksheets(1)
objExcel.ActiveSheet.Name = "Last Logon"
ws.Cells(1, 1).Value = "User-ID"
ws.Columns(1).ColumnWidth = 15
ws.Cells(1, 2).Value = "Last logged on Server"
ws.Columns(2).ColumnWidth = 20
ws.Cells(1, 3).Value = "At date and time"
ws.Columns(3).ColumnWidth = 20
ws.Cells(1, 4).Value = "Older than 30 days"
ws.Columns(4).ColumnWidth = 25
ws.Cells(1, 5).Value = "Has Never Logged On"
ws.Columns(5).ColumnWidth = 25
ws.Cells(1, 6).Value = "Account Disabled"
ws.Columns(6).ColumnWidth = 20
ws.Cells(1, 7).Value = "Account Created at"
ws.Columns(7).ColumnWidth = 18
ws.Cells(1, 8).Value = "Flag Error Code"
ws.Columns(8).ColumnWidth = 15
ws.Cells(1, 9).Value = "Users Full Name"
ws.Columns(9).ColumnWidth = 35
ws.Cells(1, 10).Value = "OU path"
ws.Columns(10).ColumnWidth = 30
ws.Cells(1, 11).Value = "LDAP path"
ws.Columns(11).ColumnWidth = 70
ws.Cells(1, 12).Value = "Special Error codes"
ws.Columns(12).ColumnWidth = 20
objExcel.Range("A1:L1").Select
objExcel.Selection.Font.Bold = True
objExcel.Selection.Interior.ColorIndex = 5
objExcel.Selection.Interior.Pattern = 2
objExcel.Selection.Font.ColorIndex = 2
objExcel.ActiveSheet.Range("A1").Activate
ws.Cells(1, 1).Select
intButton = WshShell.Popup("Working, please wait...", , "Working !", 64)
End Function
'**********************************************************************************************************
' Get All Users for all DC's
'**********************************************************************************************************
Function GetDCforDomain()
Set oConnection = CreateObject("ADODB.Connection")
Set oCommand = CreateObject("ADODB.Command")
oConnection.Provider = "ADsDSOObject"
oConnection.Open = "Active Directory Provider"
Set oCommand.ActiveConnection = oConnection
Set oRoot = GetObject("LDAP://RootDSE")
strDomain = oRoot.get("DefaultNamingContext")
DomainName = oRoot.get("dnsHostName")
concat = "LDAP://OU=Domain Controllers," & strDomain 'OU for Domain Controllers
Set obj = GetObject(concat)
For Each DCName In obj
UserInDomainNo = UserInDomainNo + 1
Next
For Each DCName In obj
UserInDomain = DCName.Name
Exit For
Next
Call ForAllUsers
End Function
Function ForAllUsers()
Dim UsersOU, UserFullName, MyPos1, MyPos2, TopOU, SearchName, BadSymbol
Dim counter, BadName, NoGo, UserGotNoOU
counter = 0
NoGo = 0
'Set DomainObj = GetObject("winnt://" & DomainName)
Set DomainObj = GetObject("WinNT://" & DomainName)
DomainObj.Filter = Array("user")
' List all users
For Each UserObj In DomainObj
userName = UserObj.Name
Call GetUserLastLogon
NoGo = 0
If c = 40 Then 'If you only want to check a specific number of users for a start
Exit Function 'then undo the remark and type the number of users you want to check
End If
Next
End Function
'**********************************************************************************************************
' Get All Users LastLogin for all DC's
'**********************************************************************************************************
Function GetUserLastLogon() 'Check all users LastLogin at all DC's
i = 2
x = 0
For Each DCName In obj 'For each DC in DC-collection, go check ...
strQuery = "SELECT name, distinguishedName, AdsPath, ou FROM 'LDAP://" & _
strDomain & "'WHERE sAMAccountName = '" & userName & "'"
oCommand.CommandText = strQuery
Set oResults = oCommand.Execute
strDN = oResults.Fields("distinguishedName")
strPath = DCName.Name & "." & DomainName2 & "/" & strDN
'Remove the initial CN= from the distinguished name, put it back in strPath.
sPosition = InStr(1, strPath, "=", 1)
strPath = Mid(strPath, sPosition + 1)
Pos1 = InStr(1, strPath, "/", 1)
DC = Left(strPath, (Pos1 - 2))
Set User = GetObject("WinNT://" & DC & "/" & userName & ",user") 'userName = User-ID
UsersOU = oResults.Fields("AdsPath")
UserFullName = User.FullName
'-------- Checking validity of users FullName and OU membership --------
MyPos1 = ""
MyPos2 = ""
UserGotNoOU = False
MyPos1 = InStr(4, UsersOU, "OU=", 1)
If MyPos1 = 0 Then 'If user is not a member of a manually created OU, then ... (ex. member of default OU Users)
UserGotNoOU = True
MyPos1 = InStr(9, UsersOU, "CN=", 1) 'Search for the next 'CN=' in the AdsPath
MyPos2 = InStr(MyPos1, UsersOU, "DC=", 1)
TopOU = Mid(UsersOU, (MyPos1 + 3), ((MyPos2 - 1) - (MyPos1 + 3))) 'Gets a default OU, ex. OU=Users (It's really called CN=Users)
Else
MyPos2 = InStr(MyPos1, UsersOU, "DC=", 1) 'Capture the users OU
TopOU = Mid(UsersOU, (MyPos1 + 3), ((MyPos2 - 1) - (MyPos1 + 3))) 'Gets the OU path, ex. OU=TEST2,OU=TEST1,OU=TEST
End If
MyPos1 = ""
MyPos2 = ""
MyPos1 = InStr(4, UsersOU, "CN=", 1) 'Capture the users Full Name
MyPos2 = InStr(MyPos1, UsersOU, ",OU=", 1) 'Capture the users Full Name
If MyPos2 = 0 Then 'If user is not a member of a manually created OU, then ... (ex. member of default OU Users)
UserGotNoOU = True
MyPos2 = InStr(MyPos1, UsersOU, ",CN=", 1) 'Capture the users Full Name
SearchName = Mid(UsersOU, (MyPos1 + 3), (MyPos2 - (MyPos1 + 3))) 'Capture the users Full Name
ws.Cells(c, 9).Value = SearchName
ws.Cells(c, 10).Value = TopOU
ws.Cells(c, 11).Value = UsersOU
Else
SearchName = Mid(UsersOU, (MyPos1 + 3), (MyPos2 - (MyPos1 + 3))) 'Capture the users Full Name
ws.Cells(c, 9).Value = SearchName
ws.Cells(c, 10).Value = TopOU
ws.Cells(c, 11).Value = UsersOU
End If
'-------- End of 'Checking validity of users FullName and OU membership' --------
Flag = UserObj.UserFlags 'User Flag Code Set
On Error Resume Next
ShowResult = User.LastLogin 'Gets the last login date and time for the user
If Err.Number <> 0 Then 'Capture any no-LastLogin events
OldYearTime = " - "
NoLastLoginCounter = NoLastLoginCounter + 1 'Accumulating requested DC's
LogonDC = "-"
Else '... Else ... Building up the Array with last logins
ReDim Preserve UserLastLogonArray(x)
UserLastLogonArray(x) = ShowResult & "_" & DC
UserVal = 1 '... User did at least one log on to the Domain
x = x + 1 'Counting up the Array size
End If
If NoLastLoginCounter = 9 Then
UserNeverLoggedOn = True
UsersNoLogonNo = UsersNoLogonNo + 1
End If
Next
MyArraySize = UBound(UserLastLogonArray) + 1
Call GetDateAndTime
End Function
'**********************************************************************************************************
' Get date and time for all elements in the Array, if any,
' and writing the result to the worksheet.
'**********************************************************************************************************
Function GetDateAndTime()
a = 0
i = 0
For a = 1 To MyArraySize Step 1 'Go throug elements in the Array
If UserVal = 0 Then 'If user do not have a LastLogin value, then ...
If NoGo <> 1 Then
OldYearTime = " - "
LogonDC = " - "
End If
ws.Cells(c, 1).Select
ws.Cells(c, 1).Value = UserObj.Name
objExcel.Selection.Font.ColorIndex = 3
ws.Cells(c, 2).Select
ws.Cells(c, 2).Value = LogonDC
objExcel.Selection.Font.ColorIndex = 3
ws.Cells(c, 3).Select
ws.Cells(c, 3).Value = OldYearTime
objExcel.Selection.Font.ColorIndex = 3
If UserNeverLoggedOn = True Then
ws.Cells(c, 5).Select
ws.Cells(c, 5).Value = "Has Never Logged On"
objExcel.Selection.Font.ColorIndex = 3
End If
ws.Cells(c, 7).Value = strWhenCreated
Else
MyDateAndTimePos = InStr(UserLastLogonArray(i), "_")
NewYearTime = Left(UserLastLogonArray(i), MyDateAndTimePos - 1)
MyPeriodPos = InStr(UserLastLogonArray(i), ".")
DC = Mid(UserLastLogonArray(i), (MyDateAndTimePos + 1), MyPeriodPos - (MyDateAndTimePos + 1))
Call LatestLogon(NewYearTime, DC)
Call CheckLogonDates(OldYearTime, LogonDC)
DateTimeCounter = DateTimeCounter + 1
i = i + 1
End If
Next
If MessageVal = 0 Then
ws.Cells(c, 1).Value = UserObj.Name
ws.Cells(c, 2).Value = LogonDC
ws.Cells(c, 3).Value = OldYearTime
ws.Cells(c, 8).Value = Flag
If Flag = 515 Or Flag = 547 Then
ws.Cells(c, 6).Select
ws.Cells(c, 6).Value = "Account Disabled***"
objExcel.Selection.Font.ColorIndex = 3
ws.Cells(c, 8).Select
ws.Cells(c, 8).Value = Flag
objExcel.Selection.Font.ColorIndex = 3
AccountDisNo = AccountDisNo + 1
End If
ws.Cells(c, 7).Value = strWhenCreated
Else
ws.Cells(c, 1).Select
ws.Cells(c, 1).Value = UserObj.Name
objExcel.Selection.Font.ColorIndex = 3
ws.Cells(c, 2).Select
ws.Cells(c, 2).Value = LogonDC
objExcel.Selection.Font.ColorIndex = 3
ws.Cells(c, 4).Select
ws.Cells(c, 4).Value = OldYearTime
objExcel.Selection.Font.ColorIndex = 3
Users30DaysNo = Users30DaysNo + 1
ws.Cells(c, 7).Value = strWhenCreated
ws.Cells(c, 8).Value = Flag
End If
Call DateCreationForUser
c = c + 1
UserVal = 0
ReDim UserLastLogonArray(x)
OldYearTime = 1
DateTimeCounter = 0
counter = 0
NoLastLoginCounter = 0
UserNeverLoggedOn = False
End Function
'**********************************************************************************************************
' Which logon in the UserLastLogonArray is the latest
'**********************************************************************************************************
Function LatestLogon(NewYearTime, DC)
If DateTimeCounter >= 1 Then
Pos1 = 0
Pos2 = 0
Pos1 = InStr(NewYearTime, " ")
NewYear = Left(NewYearTime, (Pos1 - 1))
NewYearVal = Right(NewYear, 4)
OldYearTimeLen = Len(OldYearTime)
If OldYearTimeLen > 2 Then
Pos2 = InStr(OldYearTime, " ")
OldYear = Left(OldYearTime, (Pos2 - 1))
OldYearVal = Right(OldYear, 4)
If NewYearVal >= OldYearVal Then
If NewYearVal = OldYearVal Then
NewDate = Left(NewYear, 5)
NewMonth = Right(NewDate, 2)
OldDate = Left(OldYear, 5)
OldMonth = Right(OldDate, 2)
If NewMonth >= OldMonth Then
If NewMonth = OldMonth Then
NewDay = Left(NewYear, 2)
OldDay = Left(OldYear, 2)
If NewDay >= OldDay Then
If NewDay = OldDay Then
Pos5 = Len(NewYearTime)
NewTime = Right(NewYearTime, (Pos5 - Pos1))
Pos6 = Len(OldYearTime)
OldTime = Right(OldYearTime, (Pos6 - Pos2))
If NewTime > OldTime Then
OldYearTime = NewYearTime
LogonDC = DC
End If
Else
OldYearTime = NewYearTime
LogonDC = DC
End If
End If
Else
OldYearTime = NewYearTime
LogonDC = DC
End If
End If
Else
OldYearTime = NewYearTime
LogonDC = DC
End If
End If
End If
End If
If DateTimeCounter < 1 Then
OldYearTime = NewYearTime
LogonDC = DC
End If
MessageVal = 0
End Function
'**********************************************************************************************************
' Check to see if the latest logon is older than 30 days
'**********************************************************************************************************
Dim MyVal
Function CheckLogonDates(OldYearTime, LogonDC)
User = UserObj.Name
Pos2 = ""
OldYear = ""
OldYearVal = ""
Pos2 = InStr(OldYearTime, " ")
OldYear = Left(OldYearTime, (Pos2 - 1))
OldYearVal = Right(OldYear, 4)
OldDate = Left(OldYear, 5)
OldMonth = Right(OldDate, 2)
OldDay = Left(OldDate, 2)
NewYearVal = Right(Date, 4)
NewDate = Left(Date, 5)
NewMonth = Right(NewDate, 2)
NewDay = Left(NewDate, 2)
MyVal = (NewMonth - OldMonth)
If OldYearVal <= NewYearVal Then
If OldYearVal < NewYearVal Then
MessageVal = 1
Else
If OldMonth < NewMonth Then
If (NewMonth - OldMonth) < 2 Then
If OldDay <= NewDay Then
MessageVal = 1
End If
Else
MessageVal = 1
End If
End If
End If
End If
End Function
'**********************************************************************************************************
' Checking creation date for user account
'**********************************************************************************************************
Function DateCreationForUser()
BadSymbol = InStr(1, SearchName, "/", 1) 'Check for bad symbol in canonical name ...
If BadSymbol <> 0 Then
ws.Cells(c, 7).Select
ws.Cells(c, 7).Value = "Check Manually !"
objExcel.Selection.Font.ColorIndex = 3
NoGo = 1
Else
On Error Resume Next
If UserGotNoOU = True Then
Set objUser = GetObject("LDAP://cn=" & UserFullName & ",cn=" & TopOU & ",dc=cdas,dc=dk")
If Err.Number <> 0 Then
ws.Cells(c, 12).Value = Err.Number
End If
Else
Set objUser = GetObject("LDAP://cn=" & UserFullName & ",ou=" & TopOU & ",dc=cdas,dc=dk")
If Err.Number <> 0 Then
ws.Cells(c, 12).Value = Err.Number
End If
End If
objUser.GetInfo
strWhenCreated = objUser.get("whenCreated")
ws.Cells(c, 7).Value = strWhenCreated
Set objUser = Nothing
End If
End Function
'**********************************************************************************************************
' Calling the Functions, Writing final statements to files and displaying the HTML file
'**********************************************************************************************************
'Calling the functions in the right order
Sub run1223()
NoLastLoginCounter = 0
UserNeverLoggedOn = False
FileTime = Timer
AccountDisNo = 0
UsersNoLogonNo = 0
Users30DaysNo = 0
UserInDomainNo = 0
MessageVal = 0
DateTimeCounter = 0
OldYearTime = 1
FolderPath = "C:\Temp"
WriteFilePath = "C:\Temp\WriteAllUsersLastLogon"
c = 2
DateTimeVal = Date & " " & Time
Set WshShell = WScript.CreateObject("WScript.shell")
Set WshShell = CreateObject("WScript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Call ControlSyntax
Call MakeFolder
Call MakeFile
Call GetDCforDomain
'---------------------------
'--- Writing to the Excel file ---
ws.Cells(c, 1).Value = "Script started at " & DateTimeVal
c = c + 1
ws.Cells(c, 1).Value = "Script Ended at " & Date & " " & Time
Set ws = objExcel.Worksheets(1)
ExcelPath = "c:\Temp\WriteAllUsersLastLogon_" & Date & "_" & FileTime & ".xls"
MsgBox ExcelPath
ws.SaveAs ExcelPath
objExcel.Quit
'---------------------------
'---------------------------
'--- Writing to the HTML file ---
WriteFile.Write "<table border='0' cellpadding='0' cellspacing='0'>" & vbCrLf
WriteFile.Write "<tr>" & vbCrLf
WriteFile.Write "<td class='LogText' width='390'>Number of users queried:</td>" & vbCrLf
WriteFile.Write "<td class='LogText' width='10' align='right'>" & (c - 3) & "</td>" & vbCrLf
WriteFile.Write "</tr>" & vbCrLf
WriteFile.Write "<tr>" & vbCrLf
WriteFile.Write "<td class='LogText' width='390'>Number of DC's queried:</td>" & vbCrLf
WriteFile.Write "<td class='LogText' width='10' align='right'>" & UserInDomainNo & "</td>" & vbCrLf
WriteFile.Write "</tr>" & vbCrLf
WriteFile.Write "<tr>" & vbCrLf
WriteFile.Write "<td class='LogText' width='390'>Users that haven't logged on for 30 days or more:</td>" & vbCrLf
WriteFile.Write "<td class='LogText' width='10' align='right'>" & (Users30DaysNo - 1) & "</td>" & vbCrLf
WriteFile.Write "</tr>" & vbCrLf
WriteFile.Write "<tr>" & vbCrLf
WriteFile.Write "<td class='LogText' width='390'>Users that haven't logged on ever:</td>" & vbCrLf
WriteFile.Write "<td class='LogText' width='10' align='right'>" & (UsersNoLogonNo - 1) & "</td>" & vbCrLf
WriteFile.Write "</tr>" & vbCrLf
WriteFile.Write "<tr>" & vbCrLf
WriteFile.Write "<td class='LogText' width='390'>Number of disabled accounts:</td>" & vbCrLf
WriteFile.Write "<td class='LogText' width='10' align='right'>" & AccountDisNo & "</td>" & vbCrLf
WriteFile.Write "</tr>" & vbCrLf
WriteFile.Write "</table><br><br>" & vbCrLf
WriteFile.Write "<br><br><br><br>" & vbCrLf
WriteFile.Write "<script type=" & Chr(34) & "text/vbscript" & Chr(34) & " language=" & Chr(34) & "VBScript" & Chr(34) & ">" & vbCrLf
WriteFile.Write "sub FireExcel()" & vbCrLf
WriteFile.Write " WShell.run " & Chr(34) & "excel.exe" & " " & ExcelPath & Chr(34) & vbCrLf
WriteFile.Write "end sub" & vbCrLf
WriteFile.Write "</script>" & vbCrLf
WriteFile.Write ""
WriteFile.Write "<font class='LogText'>Click here to open the Excel file: <a href=" & Chr(34) & WriteFilePath & "_" & FileTime & ".htm" & Chr(34) & "name='FireExcel' onclick='FireExcel'>" & ExcelPath & "</a></font>" & vbCrLf
WriteFile.Write ""
WriteFile.Write "</body>" & vbCrLf & "</html>" & vbCrLf
WriteFile.Close
WshShell.Run """C:\Program Files\Internet Explorer\IEXPLORE.EXE""" & WriteFilePath & "_" & FileTime & ".htm"
'---------------------------
MsgBox "The AllUsersLastLogon.vbs script has ended !"
End Sub
'**********************************************************************************************************
' THE END !!
'**********************************************************************************************************
'
'
|