<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Get Reboot History Using Powershell Archives - the Sysadmin Channel</title>
	<atom:link href="https://thesysadminchannel.com/tag/get-reboot-history-using-powershell/feed/" rel="self" type="application/rss+xml" />
	<link>https://thesysadminchannel.com/tag/get-reboot-history-using-powershell/</link>
	<description>Documenting My Life as a System Administrator</description>
	<lastBuildDate>Sun, 13 Dec 2020 06:56:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">144174110</site>	<item>
		<title>Get Reboot History Using Powershell</title>
		<link>https://thesysadminchannel.com/get-reboot-history-using-powershell/</link>
					<comments>https://thesysadminchannel.com/get-reboot-history-using-powershell/#comments</comments>
		
		<dc:creator><![CDATA[Paul Contreras]]></dc:creator>
		<pubDate>Wed, 02 Sep 2020 05:51:09 +0000</pubDate>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[EventID 1074]]></category>
		<category><![CDATA[find who rebooted a server powershell]]></category>
		<category><![CDATA[Get Reboot History Using Powershell]]></category>
		<category><![CDATA[powershell get shutdown events]]></category>
		<category><![CDATA[powershell script to get reboot history for multiple servers]]></category>
		<guid isPermaLink="false">https://thesysadminchannel.com/?p=2571</guid>

					<description><![CDATA[<p>A while back I posted a script on how to Get System Uptime and Last Reboot Status Using Powershell so I thought a great edition to that script would be to Get Reboot History using Powershell. The uptime script showed&#8230; <a href="https://thesysadminchannel.com/get-reboot-history-using-powershell/" class="more-link">Continue Reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="https://thesysadminchannel.com/get-reboot-history-using-powershell/">Get Reboot History Using Powershell</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A while back I posted a script on how to <a href="https://thesysadminchannel.com/get-uptime-last-reboot-status-multiple-computers-powershell/" rel="noopener noreferrer" target="_blank">Get System Uptime and Last Reboot Status Using Powershell</a> so I thought a great edition to that script would be to <strong>Get Reboot History using Powershell</strong>.</p>
<p>The uptime script showed you when was the last time a machine was booted, aka how long the system has been running, but what if you wanted to pull a little more information?  What if you wanted to see the shutdown or reboot history, and probably more importantly, who was the actor that imposed that event.  </p>
<p>A minor incident happened the other day where person A was running a job while logged into a server, and it just so happens that person B needed to complete a series of patches on that same server.  Obviously the communication could have been handled much better but long story short, person B applied the patches and manually reboot the server, cutting off person A&#8217;s job mid tracks.</p>
<p>If you&#8217;re looking to use to a Powershell script to get reboot history for multiple servers, I&#8217;m sure your scenario may be different from the one above.  Whatever the reason is, I got you covered in this post.</p>
<h2>Event Viewer Logs and Event ID 1074</h2>
<p>Shortly after, I used my Google-fu and eventually came across some articles that would point me in the right direction.  I was sure there would be some logs in the event viewer and sure enough, I found <strong>Event ID 1074</strong> under the System Logs.</p>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2020/12/EventLog-EventID-1074-Reboot.png" target="_blank" rel="noopener noreferrer"><img fetchpriority="high" decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2020/12/EventLog-EventID-1074-Reboot.png" alt="EventLog EventID 1074 Reboot" width="1889" height="934" class="aligncenter size-full wp-image-2573" srcset="https://thesysadminchannel.com/wp-content/uploads/2020/12/EventLog-EventID-1074-Reboot.png?v=1607838714 1889w, https://thesysadminchannel.com/wp-content/uploads/2020/12/EventLog-EventID-1074-Reboot-1024x506.png?v=1607838714 1024w, https://thesysadminchannel.com/wp-content/uploads/2020/12/EventLog-EventID-1074-Reboot-768x380.png?v=1607838714 768w" sizes="(max-width: 1889px) 100vw, 1889px" /></a></p>
<p>I have worked with scripting Event Viewer logs in the past, such as this <a href="https://thesysadminchannel.com/get-account-lock-out-source-powershell/" rel="noopener noreferrer" target="_blank">Get Account Lock Out Source Using Powershell</a>, so I was already familiar with how the process goes.  And if you&#8217;re ok with checking the event viewer manually from the time to time it may not be worth looking up how to do it in Powershell.  However for me, I love automating things and using Powershell everywhere I can, not to mention this would be great for the community to use as well.</p>
<p>Now let&#8217;s get on to the script!</p>
<h2>Get Reboot History Using Powershell Script</h2>
<pre class="brush: powershell; title: ; notranslate">

Function Get-RebootHistory {
&lt;#
.SYNOPSIS
    This will output who initiated a reboot or shutdown event.

.NOTES
    Name: Get-RebootHistory
    Author: theSysadminChannel
    Version: 1.0
    DateCreated: 2020-Aug-5

.LINK
    https://thesysadminchannel.com/get-reboot-history-using-powershell -

.EXAMPLE
    Get-RebootHistory -ComputerName Server01, Server02

.EXAMPLE
    Get-RebootHistory -DaysFromToday 30 -MaxEvents 1

.PARAMETER ComputerName
    Specify a computer name you would like to check.  The default is the local computer

.PARAMETER DaysFromToday
    Specify the amount of days in the past you would like to search for

.PARAMETER MaxEvents
    Specify the number of events you would like to search for (from newest to oldest)
#&gt;


    [CmdletBinding()]
    param(
        [Parameter(
            Mandatory = $false,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true
        )]
        [string[]]  $ComputerName = $env:COMPUTERNAME,

        [int]       $DaysFromToday = 7,

        [int]       $MaxEvents = 9999
    )

    BEGIN {}

    PROCESS {
        foreach ($Computer in $ComputerName) {
            try {
                $Computer = $Computer.ToUpper()
                $EventList = Get-WinEvent -ComputerName $Computer -FilterHashtable @{
                    Logname = 'system'
                    Id = '1074', '6008'
                    StartTime = (Get-Date).AddDays(-$DaysFromToday)
                } -MaxEvents $MaxEvents -ErrorAction Stop


                foreach ($Event in $EventList) {
                    if ($Event.Id -eq 1074) {
                        [PSCustomObject]@{
                            TimeStamp    = $Event.TimeCreated
                            ComputerName = $Computer
                            UserName     = $Event.Properties.value[6]
                            ShutdownType = $Event.Properties.value[4]
                        }
                    }

                    if ($Event.Id -eq 6008) {
                        [PSCustomObject]@{
                            TimeStamp    = $Event.TimeCreated
                            ComputerName = $Computer
                            UserName     = $null
                            ShutdownType = 'unexpected shutdown'
                        }
                    }

                }

            } catch {
                Write-Error $_.Exception.Message

            }
        }
    }

    END {}
}


</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2020/12/Get-Reboot-History-Using-Powershell-Examples.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2020/12/Get-Reboot-History-Using-Powershell-Examples.png" alt="Get Reboot History Using Powershell Examples" width="2238" height="1144" class="aligncenter size-full wp-image-2575" srcset="https://thesysadminchannel.com/wp-content/uploads/2020/12/Get-Reboot-History-Using-Powershell-Examples.png?v=1607839790 2238w, https://thesysadminchannel.com/wp-content/uploads/2020/12/Get-Reboot-History-Using-Powershell-Examples-1024x523.png?v=1607839790 1024w, https://thesysadminchannel.com/wp-content/uploads/2020/12/Get-Reboot-History-Using-Powershell-Examples-768x393.png?v=1607839790 768w" sizes="(max-width: 2238px) 100vw, 2238px" /></a></p>
<p>&nbsp;</p>
<p>So now that you have the script in hand, just copy and paste to a local file so you can start sending nice notes to people for rebooting machines.</p>
<p>Anyway I hope you enjoyed this script and can put it to use.  If you liked it and want to see more, be sure to check out our own <a href="https://thesysadminchannel.com/powershell/" rel="noopener noreferrer" target="_blank">Powershell repository</a> full of useful, real world scripts that I&#8217;m certain you can use in your environment.  While you&#8217;re at it, don&#8217;t forget to check out our <a href="https://www.youtube.com/c/theSysadminChannel" rel="noopener noreferrer" target="_blank">Youtube Page</a> for awesome sysadmin video content.</p>
<p>The post <a href="https://thesysadminchannel.com/get-reboot-history-using-powershell/">Get Reboot History Using Powershell</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thesysadminchannel.com/get-reboot-history-using-powershell/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2571</post-id>	</item>
	</channel>
</rss>
