Script to check last reboot date-time with credentials used to reboot

Please help to share power shell  script To check last reboot for windows servers (mentioned in server list ) with user id used for reboot
LVL 1
patronTechnical consultant Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yo_beeDirector of Information TechnologyCommented:
You will need the Active Directory Module on the computer you want to run this script from.
I have a Get-WinEvent script that I use to see how long a user's computer is locked and I figure I can do something similar for your request.

I first gather all the computer in my environment using the Get-ADComputer  and then for each computer I run Get-WinEvent and story it in an array.

$computers = Get-adcomputer -Filter * -SearchBase 'OU=Computers,OU=FLH,DC=contoso,DC=com' -SearchScope OneLevel 
$Table = @()
Foreach ($computer in $computers)
{
 If(Test-Connection -ComputerName $computer.name)
 {
    Get-WinEvent -ComputerName $computer.Name -FilterHashtable @{ProviderName='User32';ID = 1074} | select -First 1 | foreach {  $sid = $_.userid;  if($sid -eq $null) { return; }  $objSID = New-Object System.Security.Principal.SecurityIdentifier($sid);  $objUser = $objSID.Translate([System.Security.Principal.NTAccount]);
     $Results = New-Object Object
     $Results | Add-Member -Type NoteProperty -Name 'Computername' -Value $computer.name 
     $Results | Add-Member -Type NoteProperty -Name 'User' -Value $objUser.Value
     $Results | Add-Member -Type NoteProperty -Name 'Date' -Value $_.TimeCreated
     $table += $Results
    }
    }
    }
    $table | Export-Csv -Path C:\temp\Lastreboot.csv -NoTypeInformation

Open in new window


I took some info from these two sites and put together the script.  
https://prajwaldesai.com/restarted-windows-server/
https://stackoverflow.com/questions/17155311/get-username-from-get-winevent
0
Jess DodsonWindows System AdministratorCommented:
I wrote up a post on how to set this up:

https://girl-germs.com/?p=1079

Includes all the .xml files etc, that you'll need for it all which are all up on GitHub.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
patronTechnical consultant Author Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.