{"id":76251,"date":"2016-01-14T00:01:00","date_gmt":"2016-01-14T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/01\/14\/use-powershell-to-work-with-data-from-ms-oms\/"},"modified":"2019-02-18T09:20:17","modified_gmt":"2019-02-18T16:20:17","slug":"use-powershell-to-work-with-data-from-ms-oms","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-work-with-data-from-ms-oms\/","title":{"rendered":"Use PowerShell to Work with Data from MS OMS"},"content":{"rendered":"<p><b>Summary<\/b>: Ed Wilson, Microsoft Scripting Guy, talks about using Windows PowerShell to parse data obtained from Microsoft Operations Management Suite.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. One of the things I have been working on a lot the past month is the new <a href=\"https:\/\/blogs.technet.microsoft.com\/msoms\/\" target=\"_blank\">Microsoft Operations Management Suite Blog<\/a>. For one thing, it is on the new blogging platform we using at Microsoft, so the blog is like a new toy with lots of fun things for a geek to play with. In addition, Microsoft Operations Management Suite (MS OMS) is a tremendously powerful platform that uses Windows PowerShell in the background, so it is also way cool to play with. With these two sets of givens, it was only a matter of time before I begin to merge the two.<\/p>\n<p>The other day I wrote a blog post for the MS OMS blog titled <a href=\"https:\/\/blogs.technet.microsoft.com\/msoms\/2016\/01\/13\/perform-system-update-assessment-with-msoms\/\" target=\"_blank\">Perform system update assessment with #MSOMS<\/a>. I have written such articles before for the Hey, Scripting Guy! Blog, but they were always a bit annoying to write because update information has a tendency to be reported in different ways, in different places, depending on the level of the operating system and so on. It can be done, but I am never too sure of the results, for instance, as compared to what the Security Update tool reports in Control Panel. The <b>System Update Assessment<\/b> tool in MS OMS is reliable, produces cool reports, is quick, and it can export a CSV file.&nbsp;<\/p>\n<h2>Parsing MS OMS data with PowerShell<\/h2>\n<p>The first thing I do is in MS OMS. I click the <b>Export<\/b> button at the bottom of the System Update Assessment tool:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-14-16-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-14-16-01.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>After I save the data in a location I can find, I open the data in a Microsoft Excel spreadsheet:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-14-16-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-14-16-02.png\" alt=\"Image of spreadsheet\" title=\"Image of spreadsheet\" \/><\/a><\/p>\n<h2>Import the CSV file using PowerShell<\/h2>\n<p>The way cool thing about importing the CSV file with Windows PowerShell is that I obtain objects that represent each row that appears in my Excel sheet. This makes the data easier to read and manipulate.<\/p>\n<p>Importing the CSV file is easy, I use the <b>Import-CSV<\/b> cmdlet and store the returned objects in a variable that I name <b>$csv<\/b>:<\/p>\n<p style=\"margin-left:30px\">$csv = Import-Csv C:\\fso\\SearchResults.csv<\/p>\n<p>When I call the <b>$csv<\/b> variable, the objects that I stored appear in my Windows PowerShell console&hellip;and scroll and scroll and scroll. The commands and a portion of the output are shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-14-16-03.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-14-16-03.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Each of the column headings now appear as a property associated with each instance of the object. So how many objects (rows) do I have? The following command shows me that there are 522:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; $csv.Count<\/p>\n<p style=\"margin-left:30px\">522<\/p>\n<p>I may be interested in how many servers need which update. I can do this by grouping the updates by title, and then sorting the output. I use the following command (<b>ft<\/b> is an alias for <b>Format-Table<\/b>):<\/p>\n<p style=\"margin-left:30px\">$csv | group title -NoElement | sort count -Descending | ft count, name<\/p>\n<p>Here is the output:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-14-16-04.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-14-16-04.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Perhaps I am interested in the KB ID, the severity, and the computers to which the update applies. I can easily use a command such as the following to obtain the information:<\/p>\n<p style=\"margin-left:30px\">$csv | select computer, kbid, msrcseverity | sort msrcseverity, computer<\/p>\n<p>The output will be something like the following:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-14-16-05.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-14-16-05.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Maybe what I want to know is how many updates require a reboot. I can obtain this information by using the following command:<\/p>\n<p style=\"margin-left:30px\">$csv | sort rebootBehavior -Descending | where rebootbehavior -eq &#039;CanRequestReboot&#039; |<\/p>\n<p style=\"margin-left:30px\">select computer, kbid, rebootbehavior, MSRCSeverity<\/p>\n<p>The command and its output are shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-14-16-06.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-14-16-06.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>One thing that is kind of fun is to see how long it will take to install of these updates. There is an <b>InstallTimePredictionSeconds<\/b> property that I can use. All I need to do is add all the values together. (Note that some of the updates do not include a prediction time.) I use the following command:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; $a = 0<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; $csv | % {$a+=$_.installtimepredictionseconds}<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; $a<\/p>\n<p style=\"margin-left:30px\">12343.6000473499<\/p>\n<p>Dividing by 60 gives me the number of minutes:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; $a \/ 60<\/p>\n<p style=\"margin-left:30px\">205.726667455832<\/p>\n<p>This is just scratching the surface of how I can use Windows PowerShell to parse the data exported from Microsoft Operations Management Suite. Remember, it is Windows PowerShell and CSV manipulation. I have written several posts about <a href=\"https:\/\/social.technet.microsoft.com\/Search\/en-US?query=csv&amp;rn=Hey,%20Scripting%20Guy!%20Blog&amp;rq=site:blogs.technet.com\/b\/heyscriptingguy\/&amp;beta=0&amp;ac=4\">using PowerShell with CSV files<\/a>. Join me tomorrow when I will talk about more cool 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>. Also check out my <a href=\"https:\/\/blogs.technet.microsoft.com\/msoms\/\" target=\"_blank\">Microsoft Operations Management Suite Blog<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Ed Wilson, Microsoft Scripting Guy, talks about using Windows PowerShell to parse data obtained from Microsoft Operations Management Suite. Microsoft Scripting Guy, Ed Wilson, is here. One of the things I have been working on a lot the past month is the new Microsoft Operations Management Suite Blog. For one thing, it is 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":[169,663,3,4,45],"class_list":["post-76251","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-csv-and-other-delimited-files","tag-msoms","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Ed Wilson, Microsoft Scripting Guy, talks about using Windows PowerShell to parse data obtained from Microsoft Operations Management Suite. Microsoft Scripting Guy, Ed Wilson, is here. One of the things I have been working on a lot the past month is the new Microsoft Operations Management Suite Blog. For one thing, it is on [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/76251","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=76251"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/76251\/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=76251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=76251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=76251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}