{"id":194,"date":"2014-12-16T00:01:00","date_gmt":"2014-12-16T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/12\/16\/use-powershell-to-find-hotfixes-installed-in-time-range\/"},"modified":"2019-02-18T10:36:32","modified_gmt":"2019-02-18T17:36:32","slug":"use-powershell-to-find-hotfixes-installed-in-time-range","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-find-hotfixes-installed-in-time-range\/","title":{"rendered":"Use PowerShell to Find Hotfixes Installed in Time Range"},"content":{"rendered":"<p><strong>Summary<\/strong><span style=\"font-size:12px\">: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to find hotfixes that were installed during a certain time range.<\/span><\/p>\n<p align=\"left\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;Hey, Scripting Guy!<\/p>\n<p align=\"left\">I have a problem at work. It seems there was a hotfix that was installed in the last couple of months that is causing problems with the video driver on a certain model of computer. Unfortunately, the problem has been somewhat erratic, and due to holidays, the users have been slow to report the issue. So I do not have exact information as to when the hotfix was installed. I only have a time frame, so to speak.<\/p>\n<p align=\"left\">I know that the update occurred sometime after Halloween, and sometime before Thanksgiving. So, it is like a six week window that I need to look into. I also know that the most recent round of hotfixes have no relationship to the problem, so I can exclude them.<\/p>\n<p align=\"left\">I need to look at my computers to see what hotfixes were installed during that time frame. I want to take the hotfixes into the lab and figure out which one is causing the problem so I can get it resolved via support.<\/p>\n<p align=\"left\">Does this make sense? Can you help?<\/p>\n<p>&mdash;PM<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>&nbsp;Hello PM,<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. One of the reasons we enjoy living in Charlotte is that the winters are mild. It is a beautiful day this morning&mdash;cool and crisp, with deep blue skies, and not a cloud in sight. It is a nice day to sit outside on the porch and sip a cup of English Breakfast tea. I added bits of blueberry leaf, strawberry leaf, marshmallow root, lemon grass, and a cinnamon stick to the pot. The result is a nice, rich, and complex flavor that goes well with a toasted whole-grain English muffin, French butter, and homemade grape jam. I have my Surface Pro 3 with me, and am checking the email sent to <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>.<\/p>\n<p>Yes, PM, it is relatively easy to see what hotfixes have been installed.<\/p>\n<h2>Begin with Get-Hotfix<\/h2>\n<p>I begin by using the <b>Get-Hotfix<\/b> cmdlet to return a list of hotfixes that are installed on my system. As I look at the listing, I see that there is an <b>InstalledOn<\/b><i> <\/i>property. This is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-12-16-14-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-12-16-14-01.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<h2>Filter on the InstalledOn property<\/h2>\n<p>It was easy enough to return a list of hotfixes by using the <b>Get-HotFix<\/b> cmdlet. Now, I need to filter out the date range. To do this, I need to pipe the results from the <b>Get-HotFix<\/b> cmdlet, and use the <b>Where-Object<\/b> cmdlet to filter on the <b>InstalledOn<\/b> property.<\/p>\n<p>I have a beginning and an ending date, so I need to use a compound <b>Where<\/b> filter. I will also use the greater than (<b>-gt<\/b>) and the less than (<b>-lt<\/b>) operators. To have both of these operators in effect at the same time, means I need to use another operator&mdash;the AND (<b>-and<\/b>) operator.<\/p>\n<p>The lucky thing for us is that Windows PowerShell does automatic type conversion, so I do not need to cast my date strings (&ldquo;10\/1\/2014&rdquo; and &ldquo;12\/11\/2014&rdquo;) to <b>DateTime<\/b> objects. So this will simplify my script a bit.<\/p>\n<p>Here is the first part of the operation. I use <b>Get-HotFix<\/b> to return the hotfixes, and I pipe it to the <b>Where-Object<\/b> cmdlet so I can do my filtering. I use <b>Where<\/b> as an alias for the <b>Where-Object<\/b> because it is a bit shorter.<\/p>\n<p style=\"margin-left:30px\">Get-HotFix |<\/p>\n<p style=\"margin-left:30px\">Where {<\/p>\n<p>Because I am using a compound <b>Where<\/b> filter, I cannot use the simplified <b>Where-Object<\/b> syntax. So I need to use the <b>$_<\/b> symbol to represent the current object (hotfix entry) in the pipeline. I will examine each of the hotfix entries, look at the <b>InstalledOn<\/b> property, and see if it falls in my date range.<\/p>\n<p>To determine the date range, I look at the greater than and the less than ranges. Here is what the filter portion looks like:<\/p>\n<p style=\"margin-left:30px\">$_.InstalledOn -gt &quot;10\/1\/2014&quot; -AND $_.InstalledOn -lt &quot;12\/11\/2014&quot;<\/p>\n<p>I want to sort the output so it will be easier to read. I once again use the <b>InstalledOn<\/b> property. The complete script is shown here:<\/p>\n<p style=\"margin-left:30px\">Get-HotFix |<\/p>\n<p style=\"margin-left:30px\">Where {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; $_.InstalledOn -gt &quot;10\/1\/2014&quot; -AND $_.InstalledOn -lt &quot;12\/11\/2014&quot; } |<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; sort InstalledOn<\/p>\n<p>Here is the script and the associated output:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-12-16-14-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-12-16-14-02.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>PM, that is all there is to using Windows PowerShell to find hotfixes that were installed in a specific date range. Join me tomorrow when I will talk about more cool Windows PowerShell stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">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><b>Ed Wilson, Microsoft Scripting Guy<\/b><span style=\"font-size:12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to find hotfixes that were installed during a certain time range. &nbsp;Hey, Scripting Guy! I have a problem at work. It seems there was a hotfix that was installed in the last couple of months that is causing problems with the video driver on [&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":[51,31,3,4,561,45],"class_list":["post-194","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-operating-system","tag-scripting-guy","tag-scripting-techniques","tag-service-packs-and-hot-fixes","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to find hotfixes that were installed during a certain time range. &nbsp;Hey, Scripting Guy! I have a problem at work. It seems there was a hotfix that was installed in the last couple of months that is causing problems with the video driver on [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/194","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=194"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/194\/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=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}