{"id":5107,"date":"2016-06-17T10:07:17","date_gmt":"2016-06-17T14:07:17","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=5107"},"modified":"2016-06-17T10:07:17","modified_gmt":"2016-06-17T14:07:17","slug":"the-cim-ple-way-with-powershell-and-event-logs","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/","title":{"rendered":"The CIM-ple way with PowerShell and Event Logs"},"content":{"rendered":"<p>I'm always on the lookout for new ways to do things. Often I'm trying to find a way to create something that is easy to use without requiring a lot of PowerShell scripting.\u00a0 I also like using the final result as teaching aids so even if you don't need the end product, I hope you'll pick up a trick or two that you can use in your own scripting projects. The task I had in mind today is a better way to get event log information. Not the events themselves, but rather the event log file. How many entries are in it? How big is it? How much of the configured log is being used? Here's what I came up with.<\/p>\n<p><!--more--><\/p>\n<p>We have always had the <a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113314\" target=\"_blank\">Get-Eventlog<\/a> cmdlet which will provide some of this information using the -List parameter.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image-13.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"Listing with Get-Eventlog\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-13.png\" alt=\"Listing with Get-Eventlog\" width=\"644\" height=\"210\" border=\"0\" \/><\/a><\/p>\n<p>There is a bit more to each object and you could use a PowerShell expression with <a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113387\" target=\"_blank\">Select-Object<\/a> to get the desired result. You could also write a function to simplify the process. But if you have to go that route, I say find a way to use CIM or PowerShell remoting. So much of remote access in PowerShell is done over legacy protocols and I believe we should strive to do more over WsMan. Because the event log files are exposed via WMI through the Win32_NTEventLogFile, we can use <a title=\"read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=287299\" target=\"_blank\">Get-CimInstance<\/a> to retrieve them.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image-14.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"Listing with Get-CimInstance\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-14.png\" alt=\"Listing with Get-CimInstance\" width=\"644\" height=\"135\" border=\"0\" \/><\/a><\/p>\n<p>Yes, the output is different. But by looking at the properties I can create a function to make it easier to query and write a custom object to the pipeline with more relevant information.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image-15.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"Using a PowerShell function\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-15.png\" alt=\"Using a PowerShell function\" width=\"644\" height=\"459\" border=\"0\" \/><\/a><\/p>\n<p>In my testing this is also much faster than using Get-Eventlog.\u00a0 Want to know how I did this and how it works? Grab a copy of the script file from GitHub.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/jdhitsolutions\/528f48c7cb135f0d6d7b2271b5a616b1.js\"><\/script><\/p>\n<p>The function includes complete help and examples and I've attempted to document with internal comments throughout. But let me touch on a few highlights.<\/p>\n<p>First, because the function is essentially a wrapper for Get-CimInstance, I wanted to be able to use both computer names and CimSessions. You'll notice in the Parameters section that I'm using 2 parameter sets.\u00a0 You'll see that both sets are configured to accept value from pipeline.\u00a0 This works because when PowerShell processes incoming, it detects the object type and selects the appropriate parameter set.<\/p>\n<p>My function also includes a few other parameters used by Get-CimInstance like -Filter. Anything that is specified when the command is executed becomes a part of the built-in variable $PSBoundParameters, which is a hashtable. I display it with <a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113429\" target=\"_blank\">Write-Verbose<\/a> which is handy when troubleshooting. The great thing about $PSBoundParameters is that I can splat. The main part of my function splats to Get-CimInstance.<\/p>\n<pre class=\"lang:ps mark:0 decode:true \">Get-CimInstance @PSBoundParameters | Select $ListProperties\r\n<\/pre>\n<p>However, this means for other parameters like -Name,\u00a0 I need to adjust PSBoundParameters because -Name isn't part of Get-CimInstance.<\/p>\n<pre class=\"lang:ps mark:0 decode:true \">if ($Name) {\r\n     #remove from PSBoundparameters\r\n     $PSBoundParameters.Remove(\"Name\") | Out-Null\r\n     \r\n     $filter = \"logfilename = '$Name'\"\r\n     Write-Verbose \"[BEGIN  ] Adding filter: $filter\"\r\n     $PSBoundParameters.Add(\"Filter\",$filter)\r\n         \r\n   }\r\n<\/pre>\n<p>I can remove the bound parameter, but this doesn't delete the value of $Name. It merely removes it from the hashtable. I can still use the parameter. In this case I'm defining a WMI filter and and adding Filter to $PSBoundParameters because that <em>is<\/em> a part of Get-CimInstance.<\/p>\n<p>The other thing I've done which I think makes the script easier to read, is to define a set of properties in the Begin block. This keeps the Process block a bit simpler. In my function, I knew I wanted to get certain properties and use certain names. I also wanted to create new properties with some calculated values. For example, I wanted to show a percentage used value: How much of the configured maximum size is being used from the actual file size.<\/p>\n<pre class=\"lang:ps mark:0 decode:true \">#define a set of Properties to return\r\n   $Properties = @{Name=\"Computername\";Expression={$_.CSName}},\r\n   @{Name=\"LogName\";Expression={$_.LogFileName}},\r\n   \"NumberOfRecords\",\r\n   @{Name=\"Path\";Expression={$_.Name}},\r\n   @{Name=\"SizeMB\";Expression = {[math]::Round($_.FileSize\/1MB,2)}},\r\n   @{Name=\"MaxSizeMB\";Expression = {$_.MaxFileSize\/1MB -as [int]}},\r\n   @{Name=\"PctUsed\";Expression= {[math]::Round(($_.FileSize\/$_.maxFileSize)*100,2)}},\r\n   \"LastModified\",\r\n   @{Name=\"ModifiedAge\";Expression={(Get-Date) - $_.LastModified}}\r\n<\/pre>\n<p>I also combined these techniques. I wanted an option to display a quick list of event logs showing only the log name and number of entries.<\/p>\n<pre class=\"lang:ps mark:0 decode:true \">if ($ListOnly) {\r\n        #update PSBoundparameters\r\n        #limit Get-CimInstance to only retrieving the required\r\n        #properties which should speed up the query.\r\n        $PSBoundParameters.Add(\"Property\", @(\"Logfilename\",\"NumberofRecords\",\"CSName\"))\r\n        $PSBoundParameters.Remove(\"ListOnly\") | Out-Null\r\n\r\n        #define a list properties\r\n        $ListProperties = @{Name=\"Computername\";Expression={$_.CSName}},\r\n        @{Name=\"LogName\";Expression={$_.LogFileName}},\r\n        \"NumberOfRecords\"\r\n   }\r\n<\/pre>\n<p>Get-CimInstance supports retrieving only selected properties which can improve performance so I add that to $PSBoundParameters, get rid of the function's parameter and define a collection of properties when using -ListOnly.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image-16.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"List only with Get-EventLogFile\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-16.png\" alt=\"List only with Get-EventLogFile\" width=\"644\" height=\"220\" border=\"0\" \/><\/a><\/p>\n<p>Whenever I have used Get-Eventlog in the past I've usually had to add a step to filter out logs with no entries. So I included that ability in my function. Although I wanted the option to combine this with other parameters.<\/p>\n<pre class=\"lang:ps mark:0 decode:true \">if ($SkipEmptyLog -And $Name) {\r\n        #update existing filter\r\n        #remove from PSBoundparameters\r\n        $PSBoundParameters.Remove(\"SkipEmptyLog\") | Out-Null\r\n        $filter+= \" AND NumberofRecords&lt;&gt;0\"\r\n        Write-Verbose \"[BEGIN  ] Updating filter: $filter\"\r\n        $PSBoundParameters.Filter = $filter\r\n     \r\n   }\r\n   elseif ($SkipEmptyLog) {\r\n       #remove from PSBoundparameters\r\n       $PSBoundParameters.Remove(\"SkipEmptyLog\") | Out-Null\r\n\r\n       #create filter to only filter out logs with no records\r\n       $filter+= \"NumberofRecords&lt;&gt;0\"\r\n       Write-Verbose \"[BEGIN  ] Adding filter: $filter\"\r\n       $PSBoundParameters.Add(\"Filter\",$filter)\r\n   }\r\n<\/pre>\n<p>Remember, I'm always thinking about managing at scale and querying multiple servers at once. It might be possible that I want to query for a specific event log on 100 servers and skip any that have 0 entries.<\/p>\n<p>Here are some examples of the function in action.<\/p>\n<pre class=\"lang:ps mark:0 decode:true \">get-cimsession | get-eventlogfile -Name System | Out-Gridview -Title \"System\"\r\n<\/pre>\n<p>I can pipe existing CIM sessions to the command.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image-17.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"System Event Log Data\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-17.png\" alt=\"System Event Log Data\" width=\"644\" height=\"151\" border=\"0\" \/><\/a><\/p>\n<p>Or find logs that are full<\/p>\n<pre class=\"lang:ps mark:0 decode:true \">get-cimsession | get-eventlogfile | Where {$_.PctUsed -ge 100 } | sort PctUsed,Computername -Descending | select Computername,LogName,*Size*,PctUsed | format-table\r\n<\/pre>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image-18.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"Getting high usage event logs with PowerShell\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-18.png\" alt=\"Getting high usage event logs with PowerShell\" width=\"644\" height=\"326\" border=\"0\" \/><\/a><\/p>\n<p>Clearly I need to address the Security log on my domain controller!<\/p>\n<p>There are many ways I can think of to use this function. Of course I'd love to hear from you. Does this solve any problems? Did you pick up anything useful? How might you use it? If you encounter any bugs or have upgrade requests, please post them in comments on the GitHub page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m always on the lookout for new ways to do things. Often I&#8217;m trying to find a way to create something that is easy to use without requiring a lot of PowerShell scripting.\u00a0 I also like using the final result as teaching aids so even if you don&#8217;t need the end product, I hope you&#8217;ll&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New from the blog: The CIM-ple way with #PowerShell and Event Logs","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,8,19],"tags":[387,534,540],"class_list":["post-5107","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","category-wmi","tag-cim","tag-powershell","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The CIM-ple way with PowerShell and Event Logs &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The CIM-ple way with PowerShell and Event Logs &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I&#039;m always on the lookout for new ways to do things. Often I&#039;m trying to find a way to create something that is easy to use without requiring a lot of PowerShell scripting.\u00a0 I also like using the final result as teaching aids so even if you don&#039;t need the end product, I hope you&#039;ll...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-17T14:07:17+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-13.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"The CIM-ple way with PowerShell and Event Logs\",\"datePublished\":\"2016-06-17T14:07:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/\"},\"wordCount\":848,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/image_thumb-13.png\",\"keywords\":[\"CIM\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"PowerShell\",\"Scripting\",\"WMI\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/\",\"name\":\"The CIM-ple way with PowerShell and Event Logs &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/image_thumb-13.png\",\"datePublished\":\"2016-06-17T14:07:17+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/image_thumb-13.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/image_thumb-13.png\",\"width\":644,\"height\":210},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/5107\\\/the-cim-ple-way-with-powershell-and-event-logs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The CIM-ple way with PowerShell and Event Logs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The CIM-ple way with PowerShell and Event Logs &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/","og_locale":"en_US","og_type":"article","og_title":"The CIM-ple way with PowerShell and Event Logs &#8226; The Lonely Administrator","og_description":"I'm always on the lookout for new ways to do things. Often I'm trying to find a way to create something that is easy to use without requiring a lot of PowerShell scripting.\u00a0 I also like using the final result as teaching aids so even if you don't need the end product, I hope you'll...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/","og_site_name":"The Lonely Administrator","article_published_time":"2016-06-17T14:07:17+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-13.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"The CIM-ple way with PowerShell and Event Logs","datePublished":"2016-06-17T14:07:17+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/"},"wordCount":848,"commentCount":0,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-13.png","keywords":["CIM","PowerShell","Scripting"],"articleSection":["PowerShell","Scripting","WMI"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/","name":"The CIM-ple way with PowerShell and Event Logs &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-13.png","datePublished":"2016-06-17T14:07:17+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-13.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-13.png","width":644,"height":210},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5107\/the-cim-ple-way-with-powershell-and-event-logs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"The CIM-ple way with PowerShell and Event Logs"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":7361,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7361\/powershell-7-cross-platform-scripting-tips-and-traps\/","url_meta":{"origin":5107,"position":0},"title":"PowerShell 7 Cross-Platform Scripting Tips and Traps","author":"Jeffery Hicks","date":"March 13, 2020","format":false,"excerpt":"One of the reasons you want to adopt PowerShell 7 on your desktop, is that it can\u00a0 be used cross-platform. Theoretically, you can write a PowerShell script or function that works on Windows, Linux, and Mac. However, this is not without challenges. In some ways, it feels like we are\u2026","rel":"","context":"In &quot;PowerShell 7&quot;","block_context":{"text":"PowerShell 7","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-7\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-4.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-4.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-4.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/03\/hicks-scripting-4.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":3615,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3615\/powershell-essentials-webinar\/","url_meta":{"origin":5107,"position":1},"title":"PowerShell Essentials Webinar","author":"Jeffery Hicks","date":"January 29, 2014","format":false,"excerpt":"Tomorrow I will be presenting a day of PowerShell training via a series of webinars for Windows IT Pro magazine. I will be presenting 3 webinars, each about 1 hour in length. The first webinar is on the PowerShell syntax and shell. Basically, how to survive in the shell if\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/windowsitpro.com\/site-files\/windowsitpro.com\/files\/imagecache\/product\/OnLine_icon_48.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2342,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2342\/query-local-administrators-with-cim\/","url_meta":{"origin":5107,"position":2},"title":"Query Local Administrators with CIM","author":"Jeffery Hicks","date":"May 24, 2012","format":false,"excerpt":"Yesterday I posted an article on listing members of the local administrators group with PowerShell and Get-WmiObject. PowerShell 3.0 offers an additional way using the CIM cmdlets. The CIM cmdlets query the same WMI information, except instead of using the traditional RPC\/DCOM connection, these cmdlets utilize PowerShell's remoting endpoint so\u2026","rel":"","context":"In &quot;Powershell 3.0&quot;","block_context":{"text":"Powershell 3.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-3-0\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/05\/talkbubble-v3-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3661,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/","url_meta":{"origin":5107,"position":3},"title":"Creating CIM Scripts without Scripting","author":"Jeffery Hicks","date":"January 29, 2014","format":false,"excerpt":"When Windows 8 and Windows Server 2012 came out, along with PowerShell 3.0, we got our hands on some terrific technology in the form of the CIM cmdlets. Actually, we got much more than people realize. One of the reasons there was a big bump in the number of shipping\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6142,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6142\/join-me-for-a-2-day-powershell-scripting-workshop\/","url_meta":{"origin":5107,"position":4},"title":"Join Me for a 2 Day PowerShell Scripting Workshop","author":"Jeffery Hicks","date":"November 12, 2018","format":false,"excerpt":"I am very happy to announce a 2 day public PowerShell learning event. In association with the fine people behind the Techmentor conference, I will be presenting a 2 day PowerShell Scripting workshop in Dallas, TX on February 4-5, 2019. There is an option to attend virtually, but you'll really\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"announcer-blue","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/announcer-blue_thumb.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2206,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2206\/powershell-scripting-with-validateset\/","url_meta":{"origin":5107,"position":5},"title":"PowerShell Scripting with [ValidateSet]","author":"Jeffery Hicks","date":"April 16, 2012","format":false,"excerpt":"Today we'll continue our exploration of the parameter validation attributes you can use in you PowerShell scripting. We've already looked at [ValidateRange] and [ValidateScript]. Another attribute you are likely to use is [ValidateSet()]. You can use this to verify that the parameter value belongs to a pre-defined set. To use,\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=5107"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5107\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=5107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=5107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=5107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}