{"id":8492,"date":"2021-07-15T13:38:22","date_gmt":"2021-07-15T17:38:22","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=8492"},"modified":"2021-07-15T13:38:26","modified_gmt":"2021-07-15T17:38:26","slug":"searching-for-powershell-with-cim","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/","title":{"rendered":"Searching for PowerShell with CIM"},"content":{"rendered":"\n<p>Yesterday<a href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8482\/revisiting-powershell-version-inventory\/\"> I shared a script <\/a>that you could use to inventory systems for Windows PowerShell and PowerShell 7 installations. This should work for most people who install PowerShell 7 with the provided installer. But, as has been pointed out more than once to me, this won't detect any side-loaded or out-of-band installations. I made reference to this in the previous article. I think the best you can do is search the hard drive instances of pwsh.exe. But we don't want to do a brute-force recursive directory search. Instead, I'm going to use Get-CimInstance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-CimInstance -ClassName CIM_Logicalfile -Filter \"filename='pwsh' AND extension = 'exe' AND drive='C:'\"<\/code><\/pre>\n\n\n\n<p>I'm limiting search to drive C to speed things up. This type of search finds both stable and preview installations.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"408\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim-1024x408.png\" alt=\"\" class=\"wp-image-8493\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim-1024x408.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim-300x120.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim-768x306.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim-850x339.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim.png 1044w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>This gives me the same information I had before plus a  bit more. I can still search for Windows PowerShell the same way using Get-Command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Script<\/h2>\n\n\n\n<p>Here's a revised script.<\/p>\n\n\n\n<pre title=\"Get-PSExefile.ps1\" class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">#requires -version 5.1\n\n[cmdletbinding()]\nParam(\n    [Parameter(HelpMessage = \"Specify the drive to search for instances of pwsh.exe\")]\n    [ValidatePattern(\"^[c-zC-Z]$\")]\n    [string]$Drive = \"C\"\n)\n\n#a private function to shorten filenames\nFunction _shortName {\n    Param($path)\n\n    $parts = $path.split(\"\\\")\n    $out = foreach ($part in $parts) {\n        if ($part -match \"\\s\") {\n            \"{0}~1\" -f $part.Substring(0, 6)\n        }\n        else {\n            $part\n        }\n    }\n\n    $out -join \"\\\"\n}\n\nWrite-Verbose \"Searching for PowerShell installations on $([System.Environment]::MachineName)\"\n$os = (Get-CimInstance -ClassName Win32_OperatingSystem -Property Caption).caption\n\n#region Windows Powershell\nTry {\n    Write-Verbose \"Testing for Windows PowerShell\"\n    $cmd = Get-Command -Name powershell.exe -ErrorAction stop\n    if ($cmd) {\n        Write-Verbose \"Using $($cmd.path)\"\n        #need to run Powershell.exe to get $PSVersion\n        $psh = &amp;$cmd.path -nologo -noprofile -command { Get-Host }\n\n        #test for PowerShell 2.0 engine or feature\n\n        Write-Verbose \"Testing for Windows PowerShell 2.0 engine or feature\"\n\n        #get computersystem roles to determine if running on a server or client\n        #assuming operating system caption uses 'Server'\n\n        if ($os.caption -match \"server\") {\n            Write-Verbose \"Running Get-WindowsFeature\"\n            $f = Get-WindowsFeature PowerShell-V2\n        }\n        else {\n            Write-Verbose \"Running Get-WindowsOptionalFeature\"\n            $f = Get-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root\n        }\n\n        if ($f.installed -OR $f.State -eq 'Enabled') {\n            $comment = \"Windows PowerShell 2.0 feature enabled or installed\"\n        }\n        else {\n            $comment = \"\"\n        }\n        #the install date will reflect the last time the OS was updated or installed\n        [pscustomobject]@{\n            PSTypeName      = \"PSInstallInfo\"\n            Name            = $cmd.Name\n            Path            = $cmd.source\n            PSVersion       = $psh.Version\n            Installed       = (Get-Item $cmd.source).CreationTime\n            Comments        = $comment\n            Computername    = [System.Environment]::MachineName\n            OperatingSystem = $os\n        }\n        Remove-Variable cmd\n\n    } #$cmd found\n} #try\nCatch {\n    #this should never happen\n    Write-Verbose \"Windows PowerShell not installed on $([Environment]::MachineName).\"\n}\n#endregion\n\n#region PowerShell 7\nWrite-Verbose \"Testing for PowerShell 7 including preview builds\"\n$pwsh = Get-CimInstance -ClassName CIM_Logicalfile -Filter \"filename='pwsh' AND extension = 'exe' AND drive='$($drive):'\"\nif ($pwsh) {\n    Foreach ($item in $pwsh) {\n\n        if ($item.path -match 'preview') {\n            $comment = \"Preview\"\n        }\n        else {\n            $comment = \"\"\n        }\n\n        #test for SSH\n        if (Test-Path $env:programdata\\ssh\\sshd_config ) {\n            #get short name\n            $short = _shortName $item.EightDotThreeFileName\n            Write-Verbose \"Testing for an SSH subsystem using $short\"\n            $ssh = Get-Content $env:programdata\\ssh\\sshd_config | Select-String $($short -replace \"\\\\\", \"\\\\\")\n            #'(?&lt;=powershell\\s).*pwsh.exe'\n            if ($ssh.matches.value -eq $short) {\n                $comment += \" SSH configured\"\n            }\n        }\n\n        [pscustomobject]@{\n            PSTypeName      = \"PSInstallInfo\"\n            Name            = Split-Path $item.name -Leaf\n            Path            = Split-Path $item.name\n            PSVersion       = $item.version\n            Installed       = $item.InstallDate\n            Comments        = $comment.Trim()\n            Computername    = [System.Environment]::MachineName\n            OperatingSystem = $os\n        }\n\n    }\n}\n#endregion\n\n#end of script\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Changes<\/h2>\n\n\n\n<p>I made a few changes in this version. First, I decided not to treat the PowerShell 2.0 engine as a separate version. You use the same powershell.exe version for both 5.1 and 2.0. Instead, I reflect the 2.0 engine status in the comment. I also took a different approach to SSH. Instead of testing if SSH is installed and running, I'm checking the sshd_config file for the existence of a PowerShell subsystem. This is what lets your connect using SSH remoting in PowerShell.<\/p>\n\n\n\n<p>This requires a little manipulation because the long file name from Windows is truncated in the sshd_config file. So instead of searching for C:\\Program Files\\PowerShell\\7\\pwsh.exe\", I'm looking for  \"c:\\progra~1\\powershell\\7\\pwsh.exe\". I wrote a short helper function to convert the path. I realize this is not foolproof but it works for my SSH installations.<\/p>\n\n\n\n<p>Here's default local output.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"529\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim2.png\" alt=\"\" class=\"wp-image-8496\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim2.png 750w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim2-300x212.png 300w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/a><\/figure>\n\n\n\n<p>As before, you can use remoting to inventory other servers and desktops.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$c = Invoke-Command -FilePath C:\\scripts\\Get-PSExeFile.ps1 -ComputerName win10,srv1,srv2 -HideComputerName | sort computername<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"844\" height=\"401\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim3.png\" alt=\"\" class=\"wp-image-8497\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim3.png 844w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim3-300x143.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim3-768x365.png 768w\" sizes=\"auto, (max-width: 844px) 100vw, 844px\" \/><\/a><\/figure>\n\n\n\n<p>Do you like that? I revised the format ps1xml file.<\/p>\n\n\n\n<pre title=\"psinstalledinfo.format.ps1xml\" class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;!--\nFormat type data generated 07\/13\/2021 12:14:45 by PROSPERO\\Jeff\n\nThis file was created using the New-PSFormatXML command that is part\nof the PSScriptTools module.\n\nhttps:\/\/github.com\/jdhitsolutions\/PSScriptTools\n-->\n&lt;Configuration>\n  &lt;ViewDefinitions>\n    &lt;View>\n      &lt;!--Created 07\/13\/2021 12:14:45 by PROSPERO\\Jeff-->\n      &lt;Name>default&lt;\/Name>\n      &lt;ViewSelectedBy>\n        &lt;TypeName>PSInstallInfo&lt;\/TypeName>\n      &lt;\/ViewSelectedBy>\n      &lt;GroupBy>\n        &lt;ScriptBlock>\n        if ($host.name -match \"console|code|serverremotehost\") {\n          \"{0} [$([char]27)[3m{1}$([char]27)[0m]\" -f $_.Computername,$_.OperatingSystem\n        }\n        else {\n          \"{0} [{1}]\" -f $_.Computername,$_.OperatingSystem\n        }\n        &lt;\/ScriptBlock>\n        &lt;Label>Computername&lt;\/Label>\n      &lt;\/GroupBy>\n      &lt;TableControl>\n        &lt;!--Delete the AutoSize node if you want to use the defined widths\n        &lt;AutoSize \/>.-->\n        &lt;TableHeaders>\n          &lt;TableColumnHeader>\n            &lt;Label>Name&lt;\/Label>\n            &lt;Width>19&lt;\/Width>\n            &lt;Alignment>left&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n          &lt;TableColumnHeader>\n            &lt;Label>PSVersion&lt;\/Label>\n            &lt;Width>16&lt;\/Width>\n            &lt;Alignment>left&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n           &lt;TableColumnHeader>\n            &lt;Label>Installed&lt;\/Label>\n            &lt;Width>12&lt;\/Width>\n            &lt;Alignment>left&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n          &lt;TableColumnHeader>\n            &lt;Label>Comments&lt;\/Label>\n          &lt;\/TableColumnHeader>\n        &lt;\/TableHeaders>\n        &lt;TableRowEntries>\n          &lt;TableRowEntry>\n            &lt;TableColumnItems>\n              &lt;TableColumnItem>\n                &lt;PropertyName>Name&lt;\/PropertyName>\n              &lt;\/TableColumnItem>\n              &lt;TableColumnItem>\n                &lt;ScriptBlock>\n                if (($host.name -match \"console|code|serverremotehost\") -AND ($_.path -match \"preview\")) {\n                  \"$([char]27)[38;5;219m$($_.PSVersion)$([char]27)[0m\"\n                }\n                else {\n                  $_.PSVersion\n                }\n                &lt;\/ScriptBlock>\n              &lt;\/TableColumnItem>\n              &lt;TableColumnItem>\n                &lt;ScriptBlock>$_.Installed.ToShortDateString()&lt;\/ScriptBlock>\n              &lt;\/TableColumnItem>\n              &lt;TableColumnItem>\n               &lt;ScriptBlock>\n                if (($host.name -match \"console|code|serverremotehost\") -AND ($_.comments-match \"SSH configured\")) {\n                  &lt;!-- replace SSH Detected with an ANSI sequence-->\n                  $_.comments -replace \"SSH configured\",\"$([char]27)[1;38;5;155mSSH configured$([char]27)[0m\"\n                }\n                else {\n                  $_.comments\n                }\n                &lt;\/ScriptBlock>\n              &lt;\/TableColumnItem>\n            &lt;\/TableColumnItems>\n          &lt;\/TableRowEntry>\n        &lt;\/TableRowEntries>\n      &lt;\/TableControl>\n    &lt;\/View>\n  &lt;\/ViewDefinitions>\n&lt;\/Configuration><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>At this point, you should have several options. Hopefully one of them meets your needs. Or feel free to cut and paste the parts you want into your own tool. If you take this approach, I hope you'll share your work. Questions and comments always welcome. Enjoy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday I shared a script that you could use to inventory systems for Windows PowerShell and PowerShell 7 installations. This should work for most people who install PowerShell 7 with the provided installer. But, as has been pointed out more than once to me, this won&#8217;t detect any side-loaded or out-of-band installations. I made reference&#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 on the blog: Searching for #PowerShell  with CIM","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,610],"tags":[387,534,611,540],"class_list":["post-8492","post","type-post","status-publish","format-standard","hentry","category-powershell","category-powershell-7","tag-cim","tag-powershell","tag-powershell-7","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Searching for PowerShell with CIM &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"One more script to inventory Windows PowerShell and PowerShell 7 installations, this time using Get-CimInstance.\" \/>\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\/8492\/searching-for-powershell-with-cim\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Searching for PowerShell with CIM &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"One more script to inventory Windows PowerShell and PowerShell 7 installations, this time using Get-CimInstance.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-15T17:38:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-15T17:38:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim-1024x408.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\\\/8492\\\/searching-for-powershell-with-cim\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8492\\\/searching-for-powershell-with-cim\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Searching for PowerShell with CIM\",\"datePublished\":\"2021-07-15T17:38:22+00:00\",\"dateModified\":\"2021-07-15T17:38:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8492\\\/searching-for-powershell-with-cim\\\/\"},\"wordCount\":375,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8492\\\/searching-for-powershell-with-cim\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/pwsh-cim-1024x408.png\",\"keywords\":[\"CIM\",\"PowerShell\",\"PowerShell 7\",\"Scripting\"],\"articleSection\":[\"PowerShell\",\"PowerShell 7\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8492\\\/searching-for-powershell-with-cim\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8492\\\/searching-for-powershell-with-cim\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8492\\\/searching-for-powershell-with-cim\\\/\",\"name\":\"Searching for PowerShell with CIM &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8492\\\/searching-for-powershell-with-cim\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8492\\\/searching-for-powershell-with-cim\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/pwsh-cim-1024x408.png\",\"datePublished\":\"2021-07-15T17:38:22+00:00\",\"dateModified\":\"2021-07-15T17:38:26+00:00\",\"description\":\"One more script to inventory Windows PowerShell and PowerShell 7 installations, this time using Get-CimInstance.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8492\\\/searching-for-powershell-with-cim\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8492\\\/searching-for-powershell-with-cim\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8492\\\/searching-for-powershell-with-cim\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/pwsh-cim.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/pwsh-cim.png\",\"width\":1044,\"height\":416},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8492\\\/searching-for-powershell-with-cim\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Searching for PowerShell with CIM\"}]},{\"@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":"Searching for PowerShell with CIM &#8226; The Lonely Administrator","description":"One more script to inventory Windows PowerShell and PowerShell 7 installations, this time using Get-CimInstance.","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\/8492\/searching-for-powershell-with-cim\/","og_locale":"en_US","og_type":"article","og_title":"Searching for PowerShell with CIM &#8226; The Lonely Administrator","og_description":"One more script to inventory Windows PowerShell and PowerShell 7 installations, this time using Get-CimInstance.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/","og_site_name":"The Lonely Administrator","article_published_time":"2021-07-15T17:38:22+00:00","article_modified_time":"2021-07-15T17:38:26+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim-1024x408.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\/8492\/searching-for-powershell-with-cim\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Searching for PowerShell with CIM","datePublished":"2021-07-15T17:38:22+00:00","dateModified":"2021-07-15T17:38:26+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/"},"wordCount":375,"commentCount":6,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim-1024x408.png","keywords":["CIM","PowerShell","PowerShell 7","Scripting"],"articleSection":["PowerShell","PowerShell 7"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/","name":"Searching for PowerShell with CIM &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim-1024x408.png","datePublished":"2021-07-15T17:38:22+00:00","dateModified":"2021-07-15T17:38:26+00:00","description":"One more script to inventory Windows PowerShell and PowerShell 7 installations, this time using Get-CimInstance.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pwsh-cim.png","width":1044,"height":416},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8492\/searching-for-powershell-with-cim\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Searching for PowerShell with CIM"}]},{"@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":2781,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2781\/find-files-with-powershell-3-0\/","url_meta":{"origin":8492,"position":0},"title":"Find Files with PowerShell 3.0","author":"Jeffery Hicks","date":"February 7, 2013","format":false,"excerpt":"My last few articles have looked at using WMI and CIM_DATAFILE class to find files, primarily using Get-WmiObject in PowerShell. But now that we have PowerShell 3.0 at our disposal, we can use the new CIM cmdlets. So I took my most recent version of Get-CIMFile and revised it specifically\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":"get-cimfile3","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/get-cimfile3-1024x703.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/get-cimfile3-1024x703.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/get-cimfile3-1024x703.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2935,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/","url_meta":{"origin":8492,"position":1},"title":"Get CIMInstance from PowerShell 2.0","author":"Jeffery Hicks","date":"April 10, 2013","format":false,"excerpt":"I love the new CIM cmdlets in PowerShell 3.0. Querying WMI is a little faster because the CIM cmdlets query WMI using the WSMAN protocol instead of DCOM. The catch is that remote computers must be running PowerShell 3 which includes the latest version of the WSMAN protocol and the\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":"get-ciminstance-error","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error-300x145.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":8492,"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":7835,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7835\/finding-zombie-files-with-powershell\/","url_meta":{"origin":8492,"position":3},"title":"Finding Zombie Files with PowerShell","author":"Jeffery Hicks","date":"October 30, 2020","format":false,"excerpt":"Since this is Halloween weekend in the United States, I thought I'd offer up a PowerShell solution to a scary task - finding zombie files. Ok, maybe these aren't really living dead files, but rather files with a 0-byte length. It is certainly possible that you may intentionally want a\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\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/datatfile-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/datatfile-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/datatfile-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/datatfile-1.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/datatfile-1.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/datatfile-1.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":5187,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5187\/get-antivirus-product-status-with-powershell\/","url_meta":{"origin":8492,"position":4},"title":"Get Antivirus Product Status with PowerShell","author":"Jeffery Hicks","date":"July 22, 2016","format":false,"excerpt":"I expect that most of you with enterprise-wide antivirus installations probably have vendor tools for managing all of your clients. If so, don't go away just yet. Even though I'm going to demonstrate how to get antivirus product status with PowerShell, the scripting techniques might still be useful. Or you\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"antivirus information from WMI","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/07\/image_thumb-7.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/07\/image_thumb-7.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/07\/image_thumb-7.png?resize=525%2C300 1.5x"},"classes":[]},{"id":3661,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/","url_meta":{"origin":8492,"position":5},"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":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8492","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=8492"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8492\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}