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

patron
patron used Ask the Experts™
on
Please help to share power shell  script To check last reboot for windows servers (mentioned in server list ) with user id used for reboot
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
yo_beeDirector of Information Technology

Commented:
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
Windows System Administrator
Commented:
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.
patronTechnical consultant

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial