AD computer last shutdown history

Rmartin0000 106 Reputation points
2020-08-05T16:17:38.74+00:00

HI,The below command executes AD user logon hisotry and need the similar but last shutdown history. kindly advice.

Get-ADComputer -Filter * -Properties *  | Sort LastLogonDate | FT Name, LastLogonDate -Autosize | Out-File C:\Temp\ComputerLastLogonDate.txt Thanks

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,912 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,383 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Rich Matheisen 45,096 Reputation points
    2020-08-05T19:12:08.717+00:00

    How about this?

    $Filter = @{Logname='System'; ID=1074,6006,6008}
    Get-WinEvent -FilterHashtable $Filter |
        Select-Object TimeCreated,MachineName,Id |
            Export-CSV -Path ShutdownLogPath -NoTypeInformation
    
    1 person found this answer helpful.
    0 comments No comments

  2. Rmartin0000 106 Reputation points
    2020-08-06T12:15:49.037+00:00

    Hi RichMatheisen-885

    The above works but for local machine but looking for entire domain clients. any idea?

    0 comments No comments

  3. Rich Matheisen 45,096 Reputation points
    2020-08-06T19:11:18.92+00:00

    This should work for all the computers in the AD, but it's going to be slow if you have a substantial number of machines or if some of the machines are inaccessible when you query them (and you just know that's going to happen!). You might consider using Invoke-Command and wrapping the Get-WinEvent/Select-Object in a script block and omit the -Computer parameter. Using the output from the Get-ADComputer in the Invoke-Command's -Computer parameter will get you a level of parallelism and off-line machines, while they'll affect the overall execution time, won't stall the execution of the entire script while the connection times out.

    $LogFilter = @{Logname='System'; ID=1074,6006,6008}
    Get-ADComputer -Filter <filter-conditions> |
        ForEach-Object{
            Get-WinEvent -ComputerName $_.Name -FilterHashtable $LogFilter |
                Select-Object TimeCreated,MachineName,Id
        } | Export-CSV -Path ShutdownLogPath -NoTypeInformation
    
    0 comments No comments

  4. 2020-08-20T01:48:28.04+00:00

    Hi, given that this post has been quiet for a while, this is a quick question and answer. Has your question been solved? If so, please mark it as an answer so that users with the same question can find and get help.
    :)

    0 comments No comments