Announcement

Collapse
No announcement yet.

Last reboot Time revisted

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Last reboot Time revisted

    I was reading an old thread in here about remotely getting last reboot time. REMS and JeremyW posted some great scripts. I can "almost" do what I am trying to do with those scripts.

    REM Posted these two scripts:

    Batch:
    @echo off
    :// Give the name of the target computer
    Set strComputer=ComputerName

    for /f "Tokens=2 Delims==" %%i in ('wmic /node:%strComputer% OS Get LastBootUpTime /format:list') Do Set LastBootUpTime=%%i
    Set LBT-Year=%LastBootUpTime:~0,4%||: yyy
    Set LBT-Month=%LastBootUpTime:~4,2%||: mm
    Set LBT-Day=%LastBootUpTime:~6,2%||: dd
    Set LBT-Hour=%LastBootUpTime:~8,2%||: hh
    Set LBT-Minute=%LastBootUpTime:~10,2%||: mm
    Set LBT-Second=%LastBootUpTime:~12,2%||: ss
    cls

    @echo.
    @echo %strComputer%
    @echo Last Boot Date= %LBT-Month%/%LBT-Day%/%LBT-Year% (mm/dd/yyyy)
    @echo Last Boot Time= %LBT-Hour%^:%LBT-Minute%^:%LBT-Second%

    @echo.
    @pause
    VBS:
    '// Give the name of the target computer
    strComputer = "ComputerName"
    Set objWMIService = GetObject("winmgmts:\\" _
    & strComputer & "\root\cimv2")
    Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

    For Each objOS in colOperatingSystems
    dtmBootup = objOS.LastBootUpTime
    Exit For
    Next

    WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
    Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) )
    WMIDateStringToTime = CDate(Mid(dtmBootup, 9, 2) & ":" & _
    Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))

    Wscript.Echo strComputer & vbNewLine & _
    "Last Boot Date= " & WMIDateStringToDate & vbNewLine & _
    "Last Boot Time= " & WMIDateStringToTime
    This is perfect but I need it for more than just one machine at a time.

    JeremyW posted this wonderful vbs script to force reboots:
    On Error Resume Next

    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Open "Provider=ADsDSOObject;"

    Set objCommand = CreateObject("ADODB.Command")
    objCommand.ActiveConnection = objConnection


    '--- change the DN to where you want to start your search ---
    objCommand.CommandText = _
    "<LDAP://ou=workstations,ou=corp,dc=domain,dc=com>;" & _
    "(objectCategory=computer);distinguishedName,name; subtree"

    Set objRecordSet = objCommand.Execute

    While Not objRecordSet.EOF

    RestartComputer objRecordSet.Fields("Name")
    objRecordSet.MoveNext

    Wend

    objConnection.Close


    Sub RestartComputer(strComputer)

    set objShell = CreateObject("WScript.Shell")
    objShell.Run "shutdown -s -t 0 -f -m \\" & strComputer

    End Sub
    I love this script as I can specify the OU and it just reboots all machines within that OU.

    I'd love to find a way to specify an OU and get the last reboot times for all the workstations within that OU(XP, Vista, and W7).

    Thanks for any help you all can lend.

    Mike
Working...
X