question

rmartin0000 avatar image
0 Votes"
rmartin0000 asked YoungYang-MSFT answered

AD computer last shutdown history

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

windows-server-powershellwindows-active-directory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
1 Vote"
RichMatheisen-8856 answered

How about this?

 $Filter = @{Logname='System'; ID=1074,6006,6008}
 Get-WinEvent -FilterHashtable $Filter |
     Select-Object TimeCreated,MachineName,Id |
         Export-CSV -Path ShutdownLogPath -NoTypeInformation
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

rmartin0000 avatar image
0 Votes"
rmartin0000 answered

Hi RichMatheisen-885

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YoungYang-MSFT avatar image
0 Votes"
YoungYang-MSFT answered

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.
:)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.