{"id":2935,"date":"2013-04-10T11:42:11","date_gmt":"2013-04-10T15:42:11","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=2935"},"modified":"2014-05-06T08:27:12","modified_gmt":"2014-05-06T12:27:12","slug":"get-ciminstance-from-powershell-2-0","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/","title":{"rendered":"Get CIMInstance from PowerShell 2.0"},"content":{"rendered":"<p>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 WinRM service. But if your computers are running 3.0 then you can simply run a command like this:<\/p>\n<pre class=\"lang:ps decode:true\">get-content computers.txt | get-ciminstance win32_operatingsystem<\/pre>\n<p>However, if one of the computers is running PowerShell 2.0, you'll get an error.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-2936\" alt=\"get-ciminstance-error\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error-300x145.png\" width=\"300\" height=\"145\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error-300x145.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error-624x301.png 624w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error.png 997w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>In this example, CHI-DC02 is not running PowerShell 3.0. The solution is to create a CIMSession using a CIMSessionOption for DCOM.<\/p>\n<pre class=\"lang:ps decode:true\">$opt = New-CimSessionOption -Protocol Dcom\r\n$cs = New-CimSession -ComputerName CHI-DC02 -SessionOption $opt\r\n$cs | get-ciminstance win32_operatingsystem<\/pre>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-dcom.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-2937\" alt=\"get-ciminstance-dcom\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-dcom-300x97.png\" width=\"300\" height=\"97\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-dcom-300x97.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-dcom-624x202.png 624w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-dcom.png 996w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>So there is a workaround, but you have to know ahead of time which computers are not running PowerShell 3.0. When you use Get-CimInstance and specify a computername, the cmdlet setups up a temporary CIMSession. So why not create the temporary CIMSession with the DCOM option if it is needed? So I wrote a \"wrapper\" function called Get-MyCimInstance to do just that.<\/p>\n<p>The heart of the function is a nested function to test if a remote computer is running WSMAN 3.0.<\/p>\n<pre class=\"lang:default decode:true\">Function Test-IsWsman3 {\r\n[cmdletbinding()]\r\nParam(\r\n[Parameter(Position=0,ValueFromPipeline)]\r\n[string]$Computername=$env:computername\r\n)\r\n\r\nBegin {\r\n    #a regular expression pattern to match the ending\r\n    [regex]$rx=\"\\d\\.\\d$\"\r\n}\r\nProcess {\r\n    Try {\r\n        $result = Test-WSMan -ComputerName $Computername -ErrorAction Stop\r\n    }\r\n    Catch {\r\n        Write-Error $_.exception.message\r\n    }\r\n    if ($result) {\r\n        $m = $rx.match($result.productversion).value\r\n        if ($m -eq '3.0') {\r\n            $True\r\n        }\r\n        else {\r\n            $False\r\n        }\r\n    }\r\n} #process\r\nEnd {\r\n #not used\r\n}\r\n} #end Test-IsWSMan<\/pre>\n<p>The function uses Test-WSMan and a regular expression to get the remoting version. If it is 3.0 the function returns True. In Get-MyCIMInstance I test each computer and if not running 3.0, create the CIMSession option and include it when creating the temporary CIMSession.<\/p>\n<pre class=\"lang:ps decode:true\">Try {\r\n#test if computer is running WSMAN 2\r\n$isWSMAN3 = Test-IsWsman3 -Computername $computer -ErrorAction Stop\r\n\r\nif (-NOT $isWSMAN3) {\r\n    #create a CIM session using the DCOM protocol\r\n    Write-Verbose \"Creating a DCOM option\"\r\n    $opt = New-CimSessionOption -Protocol Dcom\r\n    $sessparam.Add(\"SessionOption\",$opt)\r\n}\r\nElse {\r\n        Write-Verbose \"Confirmed WSMAN 3.0\"\r\n}\r\n\r\nTry {               \r\n    $session = New-CimSession @sessParam\r\n}\r\nCatch {\r\n    Write-Warning \"Failed to create a CIM session to $computer\"\r\n    Write-Warning $_.Exception.Message\r\n}<\/pre>\n<p>I'm using a Try\/Catch block because if the computer is offline, my test function will throw an exception which I can catch.<\/p>\n<pre class=\"lang:ps decode:true \">Catch {\r\n        Write-Warning \"Unable to verify WSMAN on $Computer\"\r\n     }<\/pre>\n<p>Otherwise, all is good and \u00a0I can pass the rest of the parameters to Get-CimInstance.<\/p>\n<pre class=\"lang:default decode:true\">#create the parameters to pass to Get-CIMInstance\r\n        $paramHash=@{\r\n         CimSession= $session\r\n         Class = $class\r\n        }\r\n\r\n        $cimParams = \"Filter\",\"KeyOnly\",\"Shallow\",\"OperationTimeOutSec\",\"Namespace\"\r\n        foreach ($param in $cimParams) {\r\n          if ($PSBoundParameters.ContainsKey($param)) {\r\n            Write-Verbose \"Adding $param\"\r\n            $paramhash.Add($param,$PSBoundParameters.Item($param))\r\n          } #if\r\n        } #foreach param\r\n\r\n        #execute the query\r\n        Write-Verbose \"Querying $class\"\r\n        Get-CimInstance @paramhash<\/pre>\n<p>At the end of the process, I remove the temporary CIMSession. With this, now I can query both v2 and v3 computers.<br \/>\n<a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-myciminstance01.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-2938\" alt=\"get-myciminstance01\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-myciminstance01-300x172.png\" width=\"300\" height=\"172\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-myciminstance01-300x172.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-myciminstance01-624x358.png 624w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-myciminstance01.png 1004w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nNotice for CHI-DC02 I'm creating the DCOM option. Here's the command without all the verboseness.<br \/>\n<a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-myciminstance02.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-2939\" alt=\"get-myciminstance02\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-myciminstance02-300x94.png\" width=\"300\" height=\"94\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-myciminstance02-300x94.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-myciminstance02-624x196.png 624w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-myciminstance02.png 997w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nI could have created a proxy function for Get-CimInstance, but not only are they more complicated, I didn't want that much transparency. I wanted to know that I'm querying using my function and not Get-CimInstance. Here's the complete script.<\/p>\n<pre class=\"lang:ps decode:true\">#requires -version 3.0\r\n\r\n&lt;#\r\n  ****************************************************************\r\n  * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED *\r\n  * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK.  IF   *\r\n  * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, *\r\n  * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING.             *\r\n  ****************************************************************\r\n #&gt;\r\n\r\nFunction Get-MyCimInstance {\r\n\r\n&lt;#\r\n.Synopsis\r\nCreate on-the-fly CIMSessions to retrieve WMI data\r\n.Description\r\nThe Get-CimInstance cmdlet in PowerShell 3 can be used to retrieve WMI information\r\nfrom a remote computer using the WSMAN protocol instead of the legacy WMI service\r\nthat uses DCOM and RPC. However, the remote computers must be running PowerShell\r\n3 and the latest version of the WSMAN protocol. When querying a remote computer,\r\nGet-CIMInstance setups a temporary CIMSession. However, if the remote computer is\r\nrunning PowerShell 2.0 this will fail. You have to manually create a CIMSession\r\nwith a CIMSessionOption to use the DCOM protocol.\r\n\r\nThis command does that for you automatically. It is designed to use computernames.\r\nThe computer is tested and if it is running PowerShell 2.0 then a temporary session\r\nis created using DCOM. Otherwise a standard CIMSession is created. The remaining \r\nCIM parameters are then passed to Get-CIMInstance.\r\n\r\nGet-MyCimInstance is essentially a wrapper around Get-CimInstance to make it easier\r\nto query data from a mix of computers.\r\n.Example\r\nPS C:\\&gt; get-content computers.txt | get-myciminstance -class win32_logicaldisk -filter \"drivetype=3\"\r\n.Notes\r\nLast Updated: April 11, 2013\r\nVersion     : 1.0\r\nAuthor      : Jeffery Hicks (@JeffHicks)\r\n\r\nRead PowerShell:\r\nLearn Windows PowerShell 3 in a Month of Lunches\r\nLearn PowerShell Toolmaking in a Month of Lunches\r\nPowerShell in Depth: An Administrator's Guide\r\n\r\n.Link\r\nhttp:\/\/jdhitsolutions.com\/blog\/2013\/04\/get-ciminstance-from-powershell-2-0\r\n\r\n.Link\r\nGet-CimInstance\r\nNew-CimSession\r\nNew-CimsessionOption\r\n\r\n.Inputs\r\nstring\r\n\r\n.Outputs\r\nCIMInstance\r\n\r\n#&gt;\r\n\r\n[cmdletbinding()]\r\n\r\nParam(\r\n[Parameter(Position=0,Mandatory,HelpMessage=\"Enter a class name\",\r\nValueFromPipelineByPropertyName)]\r\n[ValidateNotNullorEmpty()]\r\n[string]$Class,\r\n[Parameter(Position=1,ValueFromPipelineByPropertyName,ValueFromPipeline)]\r\n[ValidateNotNullorEmpty()]\r\n[string[]]$Computername=$env:computername,\r\n[Parameter(ValueFromPipelineByPropertyName)]\r\n[string]$Filter,\r\n[Parameter(ValueFromPipelineByPropertyName)]\r\n[string[]]$Property,\r\n[Parameter(ValueFromPipelineByPropertyName)]\r\n[ValidateNotNullorEmpty()]\r\n[string]$Namespace=\"root\\cimv2\",\r\n[switch]$KeyOnly,\r\n[uint32]$OperationTimeoutSec,\r\n[switch]$Shallow,\r\n[System.Management.Automation.Credential()]$Credential = [System.Management.Automation.PSCredential]::Empty\r\n)\r\n\r\nBegin {\r\n    Write-Verbose -Message \"Starting $($MyInvocation.Mycommand)\"  \r\n    Write-verbose -Message ($PSBoundParameters | out-string)\r\n\r\n    Function Test-IsWsman3 {\r\n        [cmdletbinding()]\r\n        Param(\r\n        [Parameter(Position=0,ValueFromPipeline)]\r\n        [string]$Computername=$env:computername\r\n        )\r\n\r\n        Begin {\r\n            #a regular expression pattern to match the ending\r\n            [regex]$rx=\"\\d\\.\\d$\"\r\n        }\r\n        Process {\r\n            Try {\r\n                $result = Test-WSMan -ComputerName $Computername -ErrorAction Stop\r\n            }\r\n            Catch {\r\n                #Write the error to the pipeline if the computer is offline\r\n                #or there is some other issue\r\n                write-Error $_.exception.message\r\n            }\r\n            if ($result) {\r\n                $m = $rx.match($result.productversion).value\r\n                if ($m -eq '3.0') {\r\n                    $True\r\n                }\r\n                else {\r\n                    $False\r\n                }\r\n            }\r\n        } #process\r\n        End {\r\n         #not used\r\n        }\r\n        } #end Test-IsWSMan\r\n\r\n} #begin\r\n\r\nProcess {\r\n    foreach ($computer in $computername) {\r\n        Write-Verbose \"Processing $computer\"\r\n\r\n        #hashtable of parameters for New-CimSession\r\n        $sessParam=@{Computername=$computer;ErrorAction='Stop'}\r\n        if ($credential) {\r\n            Write-Verbose \"Adding alternate credential for CIMSession\"\r\n            $sessParam.Add(\"Credential\",$Credential)\r\n        }\r\n        Try {\r\n        #test if computer is running WSMAN 2\r\n        $isWSMAN3 = Test-IsWsman3 -Computername $computer -ErrorAction Stop\r\n\r\n        if (-NOT $isWSMAN3) {\r\n            #create a CIM session using the DCOM protocol\r\n            Write-Verbose \"Creating a DCOM option\"\r\n            $opt = New-CimSessionOption -Protocol Dcom\r\n            $sessparam.Add(\"SessionOption\",$opt)\r\n        }\r\n        Else {\r\n                Write-Verbose \"Confirmed WSMAN 3.0\"\r\n        }\r\n\r\n        Try {               \r\n            $session = New-CimSession @sessParam\r\n        }\r\n        Catch {\r\n            Write-Warning \"Failed to create a CIM session to $computer\"\r\n            Write-Warning $_.Exception.Message\r\n        }\r\n\r\n        #create the parameters to pass to Get-CIMInstance\r\n        $paramHash=@{\r\n         CimSession= $session\r\n         Class = $class\r\n        }\r\n\r\n        $cimParams = \"Filter\",\"KeyOnly\",\"Shallow\",\"OperationTimeOutSec\",\"Namespace\"\r\n        foreach ($param in $cimParams) {\r\n          if ($PSBoundParameters.ContainsKey($param)) {\r\n            Write-Verbose \"Adding $param\"\r\n            $paramhash.Add($param,$PSBoundParameters.Item($param))\r\n          } #if\r\n        } #foreach param\r\n\r\n        #execute the query\r\n        Write-Verbose \"Querying $class\"\r\n        Get-CimInstance @paramhash\r\n\r\n        #remove the temporary cimsession\r\n        Remove-CimSession $session\r\n     } #Try\r\n     Catch {\r\n        Write-Warning \"Unable to verify WSMAN on $Computer\"\r\n     }\r\n    } #foreach computer\r\n\r\n} #process\r\n\r\nEnd {\r\n    Write-Verbose -Message \"Ending $($MyInvocation.Mycommand)\"\r\n} #end\r\n\r\n} #end Get-MyCimInstance<\/pre>\n<p>I hope you'll let me know what you think and if you find this useful.<\/p>\n<p>UPDATE: I've revised this script and article since it's original posting to better handle errors if you can't test WSMAN. I also added support for alternate credentials, which is something you can't do with Get-CimInstance.<\/p>\n<p>NOTE: I should also point out that there is an apparent bug with Get-CimInstance. If you run the command for all instances of a given class, like win32_share and the remote computer is running PowerShell v2 you will get the error I've written about. But, if you use a query or a filter, it will work. So while this will fail if the computer is running v2, get-ciminstance win32_share -computername $c, these will work:<\/p>\n<p>Get-CimInstance -query \"Select * from win32_share\" -computername $c<br \/>\nGet-CimInstance -win32_share -filter \"Name='C$'\" -computername $c<\/p>\n<p>It is an odd behavior, but it can work in your favor depending on how your structure your command. What I haven't verified yet is what protocol PowerShell is using in these situations when the remote computer is running v2. Of course, the best, long term solution is to get all of your managed systems to at least PowerShell 3.0.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 WinRM service. But if your&#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":"","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":[359,8,19],"tags":[387,421,224,534,540,547,89],"class_list":["post-2935","post","type-post","status-publish","format-standard","hentry","category-powershell-3-0","category-scripting","category-wmi","tag-cim","tag-ciminstance","tag-function","tag-powershell","tag-scripting","tag-wmi","tag-wsman"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Get CIMInstance from PowerShell 2.0 &#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\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get CIMInstance from PowerShell 2.0 &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"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 WinRM service. But if your...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2013-04-10T15:42:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-05-06T12:27:12+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error-300x145.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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Get CIMInstance from PowerShell 2.0\",\"datePublished\":\"2013-04-10T15:42:11+00:00\",\"dateModified\":\"2014-05-06T12:27:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/\"},\"wordCount\":552,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/04\\\/get-ciminstance-error-300x145.png\",\"keywords\":[\"CIM\",\"CIMInstance\",\"Function\",\"PowerShell\",\"Scripting\",\"WMI\",\"wsman\"],\"articleSection\":[\"Powershell 3.0\",\"Scripting\",\"WMI\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/\",\"name\":\"Get CIMInstance from PowerShell 2.0 &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/04\\\/get-ciminstance-error-300x145.png\",\"datePublished\":\"2013-04-10T15:42:11+00:00\",\"dateModified\":\"2014-05-06T12:27:12+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/04\\\/get-ciminstance-error.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/04\\\/get-ciminstance-error.png\",\"width\":997,\"height\":482},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/2935\\\/get-ciminstance-from-powershell-2-0\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Powershell 3.0\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell-3-0\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get CIMInstance from PowerShell 2.0\"}]},{\"@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":"Get CIMInstance from PowerShell 2.0 &#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\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/","og_locale":"en_US","og_type":"article","og_title":"Get CIMInstance from PowerShell 2.0 &#8226; The Lonely Administrator","og_description":"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 WinRM service. But if your...","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/","og_site_name":"The Lonely Administrator","article_published_time":"2013-04-10T15:42:11+00:00","article_modified_time":"2014-05-06T12:27:12+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error-300x145.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":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Get CIMInstance from PowerShell 2.0","datePublished":"2013-04-10T15:42:11+00:00","dateModified":"2014-05-06T12:27:12+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/"},"wordCount":552,"commentCount":3,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error-300x145.png","keywords":["CIM","CIMInstance","Function","PowerShell","Scripting","WMI","wsman"],"articleSection":["Powershell 3.0","Scripting","WMI"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/","name":"Get CIMInstance from PowerShell 2.0 &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error-300x145.png","datePublished":"2013-04-10T15:42:11+00:00","dateModified":"2014-05-06T12:27:12+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error.png","width":997,"height":482},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Powershell 3.0","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-3-0\/"},{"@type":"ListItem","position":2,"name":"Get CIMInstance from PowerShell 2.0"}]},{"@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":3497,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3497\/resolving-sids-with-wmi-wsman-and-powershell\/","url_meta":{"origin":2935,"position":0},"title":"Resolving SIDs with WMI, WSMAN and PowerShell","author":"Jeffery Hicks","date":"October 15, 2013","format":false,"excerpt":"In the world of Windows, an account SID can be a very enigmatic thing. Who is S-1-5-21-2250542124-3280448597-2353175939-1019? Fortunately, many applications, such as the event log viewer resolve the SID to an account name. The downside, is that when you are accessing that same type of information from PowerShell, you end\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"win32_sid-fail","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/10\/win32_sid-fail-1024x330.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/10\/win32_sid-fail-1024x330.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/10\/win32_sid-fail-1024x330.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2342,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2342\/query-local-administrators-with-cim\/","url_meta":{"origin":2935,"position":1},"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":5931,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5931\/a-powershell-mystery\/","url_meta":{"origin":2935,"position":2},"title":"A PowerShell Mystery","author":"Jeffery Hicks","date":"April 2, 2018","format":false,"excerpt":"The other day I was prepping for my sessions at the upcoming PowerShell + DevOps Global Summit. As I usually do, when I am building demos that will connect to remote machines I often use the local computer as a placeholder. This should always work right? so imagine my surprise\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":8541,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/","url_meta":{"origin":2935,"position":3},"title":"Getting CIMInstance by Path","author":"Jeffery Hicks","date":"August 20, 2021","format":false,"excerpt":"I am a member of the PowerShell Cmdlet Working Group. We've been looking into this issue and it is an intriguing one. Enough so that I spent some time looking into it and writing up some test code. If you work with WMI\/CIM this might be of interest to you.\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\/2021\/08\/add-ciminstancepath2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath2.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath2.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":2781,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2781\/find-files-with-powershell-3-0\/","url_meta":{"origin":2935,"position":4},"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":3504,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3504\/runspaces-remoting-and-workflow-oh-my\/","url_meta":{"origin":2935,"position":5},"title":"Runspaces, Remoting and Workflow, Oh My!","author":"Jeffery Hicks","date":"October 18, 2013","format":false,"excerpt":"The other day on Twitter I saw a message about new script in the Microsoft Script Center on getting remote event logs with WMI. So I took a look at the script. If you take a minute to look at the script you'll quickly realize this is not a script\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"talkbubble","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2935","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=2935"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2935\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}