{"id":2546,"date":"2013-11-19T00:01:00","date_gmt":"2013-11-19T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/11\/19\/use-powershell-to-review-the-setup-event-log\/"},"modified":"2013-11-19T00:01:00","modified_gmt":"2013-11-19T00:01:00","slug":"use-powershell-to-review-the-setup-event-log","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-review-the-setup-event-log\/","title":{"rendered":"Use PowerShell to Review the Setup Event Log"},"content":{"rendered":"<p><strong>Summary<\/strong>: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to review the setup event log.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. The ticket sales for <a href=\"http:\/\/powershellsaturday.com\/007\/conference\/powershell-saturday-007-charlotte-nc-february-8-2014\/\" target=\"_blank\">Windows PowerShell Saturday in Charlotte, North Carolina<\/a> have been going pretty well. Stay tuned for some pretty exciting news&mdash;we may be adding a fourth track to the event. The reason is that there were so many excellent sessions proposed and we had a hard time choosing. In some cases, we really could not make a decision. So we may be running four tracks. This is great news, but also sort of bad news if you were hoping to catch all of the sessions. But of course, even if there were only two tracks, you would not be able to catch all of the sessions. The great thing is that there is a nice variety of sessions. Some are beginner, some are advanced, and some are, well, just plain cool. You will not want to miss out on this event.<\/p>\n<p>The first thing you need to know about using Windows PowerShell to review the setup event log, is that I am not talking about Windows Setup. It seems like I have been reviewing Windows Setup log files forever. Nope. We are not going to review the Windows Setup log. What I am talking about is an event log that happens to be called &ldquo;setup.&rdquo; This log is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5875.HSG-11-19-13-01.png\"><img decoding=\"async\" title=\"Image of log\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5875.HSG-11-19-13-01.png\" alt=\"Image of log\" \/><\/a><\/p>\n<p>This view into the Event viewer is (in my mind) misleading. Because under Windows Logs, I have the traditional event logs: Application, Security, and System. These logs have been around since Windows first came out. In fact, it was a question on my MCSE exam for Windows&nbsp;NT&nbsp;3.51.<\/p>\n<p>So I open the Windows PowerShell console, and attempt to read from the Setup event log by using the <strong>Get-Eventlog<\/strong> cmdlet (which only works with traditional event logs), and it fails. This command is shown here:<\/p>\n<p style=\"padding-left: 30px\">Get-EventLog -LogName setup<\/p>\n<p>When I use <strong>Get-EventLog<\/strong> to look for event logs, I see that the Setup log is missing.<\/p>\n<p style=\"padding-left: 30px\">Get-EventLog &ndash;List<\/p>\n<p>The failed command says that the Setup log does not exist on my computer. Dude, I just saw it in the Event Viewer! Here are the commands and the output:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5504.HSG-11-19-13-02.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5504.HSG-11-19-13-02.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<h2>The case of the missing log<\/h2>\n<p>Remember, there are two cmdlets to work with the two different types of Windows Event logs. The first cmdlet, created in the Windows PowerShell&nbsp;1.0 days, works with traditional event logs. It is called <strong>Get-EventLog<\/strong>. The second cmdlet, created in Windows PowerShell&nbsp;2.0 days, is called <strong>Get-WinEvent<\/strong>, and it will query traditional (classic) event logs in addition to the more modern types of event logs (modern in the sense that they were created four versions of Windows ago in the Windows Vista days).<\/p>\n<p>I use the <strong>Get-WinEvent<\/strong> cmdlet to see if I can find the Setup log. It works. Here is the command and the output:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-WinEvent -ListLog setup<\/p>\n<p style=\"padding-left: 30px\">LogMode&nbsp;&nbsp; MaximumSizeInBytes RecordCount LogName<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;-&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8211; &#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">Circular&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1052672&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 58 Setup<\/p>\n<p>I want to find a bit more information, so I pipe the output to the <strong>Format-List<\/strong> cmdlet as shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4341.HSG-11-19-13-03.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4341.HSG-11-19-13-03.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Groovy. So I will have to use the <strong>Get-WinEvent<\/strong> cmdlet to query this log file. No problem. None whatsoever. In fact, I wrote an <a href=\"http:\/\/social.technet.microsoft.com\/Search\/en-US?query=get-winevent&amp;beta=0&amp;rn=Hey%2c+Scripting+Guy!+Blog&amp;rq=site:blogs.technet.com\/b\/heyscriptingguy\/&amp;ac=2\" target=\"_blank\">entire series of Hey, Scripting Guy! Blog posts about using Get-WinEvent<\/a>.<\/p>\n<p>By following the post&nbsp;<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/01\/24\/use-powershell-cmdlet-to-filter-event-log-for-easy-parsing.aspx\" target=\"_blank\">Use PowerShell Cmdlet to Filter Event Log for Easy Parsing<\/a><em> <\/em>as a guideline (there is great info in the post about creating filter hash tables), I write a query to parse the Setup log and to return only items that state they need a reboot. This command is shown here:<\/p>\n<p style=\"padding-left: 30px\">Get-WinEvent -FilterHashtable @{logname = &#8216;setup&#8217;; id = 4}<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3323.HSG-11-19-13-04.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3323.HSG-11-19-13-04.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>The output is pretty cool, but unfortunately, it does not tell me why the reboot is necessary. In addition, I already know the ID and the level because I selected the ID in my filter query. So I pipe the output to <strong>Format-Table<\/strong> and wrap the output. I also tighten up the output. Here is my command:<\/p>\n<p style=\"padding-left: 30px\">Get-WinEvent -FilterHashtable @{logname = &#8216;setup&#8217;; id = 4} |<\/p>\n<p style=\"padding-left: 30px\">Format-Table timecreated, message -AutoSize -Wrap<\/p>\n<p>Here is the results:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1884.HSG-11-19-13-05.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1884.HSG-11-19-13-05.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>This is a better output for me, but I find myself looking to see what packages are installed. I notice they are all KB-type packages. So, I decide to pipe the results to <strong>Select-String<\/strong>, and to filter out only matches that begin with KB and are followed by some numbers. Here is the command I come up with:<\/p>\n<p>Get-WinEvent -FilterHashtable @{logname = &#8216;setup&#8217;; id = 4} | select message |<\/p>\n<p style=\"padding-left: 30px\">Select-String -Pattern &#8216;kb\\d*&#8217; -AllMatches | select matches<\/p>\n<p style=\"padding-left: 30px\"><strong>Note <\/strong>&nbsp;I use a simple RegEx pattern here. For more information about Windows PowerShell and Regular Expressions refer to <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/windows+powershell\/scripting+techniques\/regular+expressions\/\" target=\"_blank\">this collection of Hey, Scripting Guy! Blog posts<\/a>.<\/p>\n<p>The output is exactly what I wanted to see, as shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5635.HSG-11-19-13-06.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5635.HSG-11-19-13-06.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Join me tomorrow when I will talk more about using Windows PowerShell for troubleshooting.<\/p>\n<p>I invite you to follow me on <a href=\"mailto:Twitter\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to review the setup event log. Microsoft Scripting Guy, Ed Wilson, is here. The ticket sales for Windows PowerShell Saturday in Charlotte, North Carolina have been going pretty well. Stay tuned for some pretty exciting news&mdash;we may be adding a fourth track to the [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[462,3,4,134,461,45],"class_list":["post-2546","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-powershell-4-0","tag-scripting-guy","tag-scripting-techniques","tag-troubleshooting","tag-windows-8-1","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to review the setup event log. Microsoft Scripting Guy, Ed Wilson, is here. The ticket sales for Windows PowerShell Saturday in Charlotte, North Carolina have been going pretty well. Stay tuned for some pretty exciting news&mdash;we may be adding a fourth track to the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=2546"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2546\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=2546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}