'========================================================================== ' GPOLastApplied.vbs ' ' AUTHOR: Alan Kaplan, VA VISN 6 ' alan dot kaplan at va dot gov ' DATE : 11/10/2009 '========================================================================== Option Explicit Dim strComputer, message Dim wshShell : Set wshShell = WScript.CreateObject("WScript.Shell") Dim fso: Set fso = CreateObject("Scripting.FileSystemObject") Dim strIP, strPath If WScript.Arguments.Count = 1 Then strComputer = WScript.Arguments(0) Else strComputer = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%") strComputer = InputBox("Get GPO Last Applied Date on what PC:","Computer Name",strComputer) End If If strcomputer = "" Then WScript.Quit strComputer = UCase(strComputer) 'On Error Resume Next If not PingReply(strComputer) Then msgbox strComputer & " failed to ping",vbCritical + vbOKOnly,"Error" WScript.Quit End If 'Get time that the security database was last modified. strPath = "\\" & strComputer & "\admin$\security\database\secedit.sdb" Dim file : Set file = fso.GetFile(strPath) 'Build message Dim iLastMod iLastMod = file.DateLastModified message = "GPO Last Applied: " & iLastMod & VbCrLf & _ GetElapsedTime (now,file.DateLastModified) & "ago" MsgBox message '======= Functions and Subs =========== Function PingReply(strcomputer) Dim objScriptExec, strPingResults Dim objRE, match, matches 'RegEx pattern from Bill Stewart Set objRE = New RegExp objRE.Pattern = " [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}: " 'Three lines from Steve Cathersalc Set objScriptExec=wshShell.Exec("ping -n 2 -w 1000 " & strComputer) Set Matches = objRE.Execute(objScriptExec.StdOut.Readall) ' Execute search. If Matches.count = 1 Then PingReply = True For Each Match in Matches ' Iterate Matches collection. strIP = trim(replace(Match.Value,":","")) 'Cleanup Next Else strIP = "" PingReply = False End If End Function Public Function GetElapsedTime(dStart, dEnd) ' Original procedure : GetElapsedTime ' Date : 12/29/2006, by Noah Pruitt ' http://www.utteraccess.com/forums/showflat.php?Cat=&Board=83&Number=1886159 ' converted to vbscript by Alan Kaplan '--------------------------------------------------------------------------------------- Dim interval, totalhours, totalminutes , totalseconds Dim days , hours , Minutes , Seconds Dim strET interval = dStart - dEnd On Error Resume Next days = Int(CSng(interval)) totalhours = Int(CSng(interval * 24)) totalminutes = Int(CSng(interval * 1440)) totalseconds = Int(CSng(interval * 86400)) hours = totalhours Mod 24 Minutes = totalminutes Mod 60 Seconds = totalseconds Mod 60 If days > 0 Then strET = days & " Day" If days > 1 Then strET = strET & "s" End If strET = strET & " " End If If hours > 0 Then strET = strET & hours & " Hour" If hours > 1 Then strET = strET & "s" End If strET = strET & " " End If If Minutes > 0 Then strET = strET & Minutes & " Minute" If Minutes > 1 Then strET = strET & "s" End If strET = strET & " " End If If Seconds > 0 Then strET = strET & Seconds & " Second" If Seconds > 1 Then strET = strET & "s" End If strET = strET & " " End If GetElapsedTime = strET End Function Function IsCScript() If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then IsCScript = True Else IsCScript = False End If End Function