none
How can we get member servers uptime from AD database ?

    Question

  • Hello !

    I want to know  the up time of member server from my DC (2012R2).  Is there any way to query in database to get member server machine last up time stamp or last off time stamp ?

    Below is the script to achieve the task which works on network but I am trying to get from AD database.  

    Function Get-Uptime {
    Param ( [string] $ComputerName = $env:COMPUTERNAME )
    $os = Get-WmiObject win32_operatingsystem -ComputerName $ComputerName -ErrorAction SilentlyContinue
     if ($os.LastBootUpTime) {
       $uptime = (Get-Date) - $os.ConvertToDateTime($os.LastBootUpTime)
       Write-Output ("Last boot: " + $os.ConvertToDateTime($os.LastBootUpTime) )
       Write-Output ("Uptime   : " + $uptime.Days + " Days " + $uptime.Hours + " Hours " + $uptime.Minutes + " Minutes" )
      }
      else {
        Write-Warning "Unable to connect to $computername"
      }
    }


    Get-Uptime -ComputerName RemoteComputerHostName


    • Edited by Tushar Barhate Thursday, August 10, 2017 11:01 AM reformat
    Thursday, August 10, 2017 10:59 AM

Answers

  • Hi,

    AD DS provides a distributed database that stores and manages information about network resources and application-specific data from directory-enabled applications. AD Database includes information such as domain architecture, objects, replication and etc. information. 

    System start and stop would be system level event/operation, you can search for specific event(Event ID 6005/6006 in Windows logs - system) to check the system startup and shutdown time.

    Writing scripting and PowerShell command based on customer’s requirement is beyond support scope on this forum.

    There are existing scripts on Microsoft Script Center, you may try to find useful information there:
    https://technet.microsoft.com/en-us/scriptcenter/bb410849.aspx

    Thank you for your understanding.

    Best Regards,
    Eve Wang

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Marked as answer by Tushar Barhate Saturday, August 12, 2017 6:07 AM
    Friday, August 11, 2017 8:01 AM
    Moderator