{"id":8541,"date":"2021-08-20T12:29:46","date_gmt":"2021-08-20T16:29:46","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=8541"},"modified":"2021-08-20T16:19:43","modified_gmt":"2021-08-20T20:19:43","slug":"getting-ciminstance-by-path","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/","title":{"rendered":"Getting CIMInstance by Path"},"content":{"rendered":"\n<p>I am a member of the PowerShell Cmdlet <a href=\"https:\/\/github.com\/PowerShell\/PowerShell\/blob\/master\/docs\/community\/working-group.md\" target=\"_blank\" rel=\"noreferrer noopener\">Working Group<\/a>. We've been looking into <a href=\"https:\/\/github.com\/PowerShell\/PowerShell\/issues\/15247\" target=\"_blank\" rel=\"noreferrer noopener\">this issue<\/a> 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. Personally, I never have had a need to approach WMI\/CIM with this approach, but clearly, other IT Pros do.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Get WMI by Path<\/h2>\n\n\n\n<p>Most people use the WMI\/CIM cmdlets to get a bunch of things, using filtering to narrow down the selection. However, since the days of VBScript, you can also get a WMI object directly by referencing its path. This is a system property you can see using Get-WMIObject.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"231\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath-1024x231.png\" alt=\"\" class=\"wp-image-8542\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath-1024x231.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath-300x68.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath-768x173.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath-850x192.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath.png 1324w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>The format isn't too difficult to figure out: Computername\\namespace:classname.filter. Think of this property as the address of the object in the CIM repository. Using it allows you to go directly to the object which has a performance benefit. It is not difficult to use traditional syntax like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-WmiObject -Class win32_service -filter \"name='spooler'\"<\/code><\/pre>\n\n\n\n<p>This takes 241ms on my laptop. However, I can also use the [wmi] type accelerator using the path.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">[wmi]\"root\\cimv2:win32_service.Name='spooler'\"<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmiaccelerator.png\"><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"328\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmiaccelerator.png\" alt=\"\" class=\"wp-image-8543\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmiaccelerator.png 880w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmiaccelerator-300x112.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmiaccelerator-768x286.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmiaccelerator-850x317.png 850w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/a><\/figure>\n\n\n\n<p>This expression only took 130ms to retrieve the exact object I got with filtering. If you already have the path to a WMI object you want to manage this certainly seems like a smart way to go.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">CIM Limitations<\/h2>\n\n\n\n<p>Everything I just demonstrated works fine in Windows PowerShell using Get-WMIObject. However, this approach is considered deprecated and today we use the CIM cmdlets. These commands query the same CIM repository, except they do so using the WSMan protocol instead of RPC and DCOM. Which is a good thing. Unfortunately, Get-CimInstance doesn't return the __Path property.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimpath.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"152\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimpath-1024x152.png\" alt=\"\" class=\"wp-image-8544\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimpath-1024x152.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimpath-300x44.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimpath-768x114.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimpath-850x126.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimpath.png 1242w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>This has been the case since PowerShell v3. Whether it is a bug or design decision is irrelevant to me. However, I have enough information to construct the path All I need is the key property for the class which I can get with Get-CimClass.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkey.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"233\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkey-1024x233.png\" alt=\"\" class=\"wp-image-8545\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkey-1024x233.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkey-300x68.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkey-768x174.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkey-850x193.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkey.png 1092w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>I then wrote a PowerShell function based on this idea.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-CimKeyProperty {\n    [cmdletbinding()]\n    [Outputtype(\"cimKeyProperty\")]\n    Param(\n        [Parameter(Position = 0, Mandatory)]\n        [string]$Classname,\n        [ValidateNotNullOrEmpty()]\n        [string]$Namespace = \"root\\cimv2\",\n        [ValidateNotNullorEmpty()]\n        [string]$Computername = $env:Computername\n    )\n    Begin {\n        Write-Verbose \"[$((Get-Date).TimeofDay) BEGIN  ] Starting $($myinvocation.mycommand)\"\n    } #begin\n    Process {\n        Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Processing $namespace\\$classname\"\n        Try {\n            $cim = Get-CimClass @PSBoundParameters -ErrorAction stop\n            [pscustomobject]@{\n                PSTypename   = \"cimKeyProperty\"\n                Namespace    = $Namespace\n                Classname    = $cim.CimClassName\n                Name         = $cim.cimclassproperties.where( { $_.qualifiers.name -contains 'key' }).Name\n                Computername = $cim.CimSystemProperties.ServerName.toUpper()\n            }\n        }\n        Catch {\n            Throw $_\n        }\n    } #process\n    End {\n        Write-Verbose \"[$((Get-Date).TimeofDay) END    ] Ending $($myinvocation.mycommand)\"\n\n    } #end\n\n}<\/code><\/pre>\n\n\n\n<p>The function writes a rich object to the pipeline. It also takes into account the different types of paths, which I won't get into here.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkeyproperty.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"472\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkeyproperty-1024x472.png\" alt=\"\" class=\"wp-image-8547\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkeyproperty-1024x472.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkeyproperty-300x138.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkeyproperty-768x354.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkeyproperty-850x392.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/cimkeyproperty.png 1161w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>With this information, I can create the __Path.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function New-CimInstancePath {\n    [cmdletbinding()]\n    Param(\n        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]\n        [string]$Classname,\n        [Parameter(ValueFromPipelineByPropertyName)]\n        [string[]]$Name,\n        [Parameter(ValueFromPipelineByPropertyName)]\n        [string[]]$Value,\n        [Parameter(ValueFromPipelineByPropertyName)]\n        [ValidateNotNullOrEmpty()]\n        [string]$Namespace = \"root\\cimv2\",\n        [Parameter(ValueFromPipelineByPropertyName)]\n        [ValidateNotNullorEmpty()]\n        [string]$Computername = $env:Computername\n    )\n\n    Begin {\n        Write-Verbose \"[$((Get-Date).TimeofDay) BEGIN  ] Starting $($myinvocation.mycommand)\"\n    } #begin\n    Process {\n        Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Processing $Namespace.$Class\"\n        if ($Name -is [array]) {\n            Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Using a compound selector\"\n            $selectors = @()\n            for ($i = 0; $i -lt $name.count; $i++) {\n                $selectors += \"{0}=\"\"{1}\"\"\" -f $name[$i], $value[$i]\n            }\n            \"\\\\{0}\\{1}:{2}.{3}\" -f $Computername, $Namespace, $classname, ($selectors -join \",\")\n        }\n        elseif ($Name -AND $Value) {\n            Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Using $name property\"\n            \"\\\\{0}\\{1}:{2}.{3}='{4}'\" -f $Computername, $Namespace, $classname, $Name, $Value\n        }\n        else {\n            #singleton\n            Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Using singleton path\"\n            \"\\\\{0}\\{1}:{2}=@\" -f $Computername, $Namespace, $classname\n        }\n    } #process\n    End {\n        Write-Verbose \"[$((Get-Date).TimeofDay) END    ] Ending $($myinvocation.mycommand)\"\n\n    } #end\n}<\/code><\/pre>\n\n\n\n<p>I wrote this function to work together with Get-CimKeyProperty.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/new-ciminstancepath.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"119\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/new-ciminstancepath-1024x119.png\" alt=\"\" class=\"wp-image-8548\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/new-ciminstancepath-1024x119.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/new-ciminstancepath-300x35.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/new-ciminstancepath-768x90.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/new-ciminstancepath-850x99.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/new-ciminstancepath.png 1183w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>The last step is to create a command that can update a CimInstance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Add-CimInstancePath {\n    [cmdletbinding()]\n    Param(\n        [Parameter(Position = 0, ValueFromPipeline)]\n        [ciminstance]$Instance\n    )\n\n    Begin {\n        Write-Verbose \"[$((Get-Date).TimeofDay) BEGIN  ] Starting $($myinvocation.mycommand)\"\n    } #begin\n    Process {\n        Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Processing $($Instance.CimSystemProperties.ClassName)\"\n        $system = $Instance.CimSystemProperties\n        $get = @{\n            Classname    = $system.ClassName\n            Namespace    = $system.Namespace.replace(\"\/\", \"\\\")\n            Computername = $system.ServerName\n        }\n        $kp = Get-CimKeyProperty @get\n        if ($kp.Name) {\n            Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Defining a path using property $($kp.name)\"\n            $newpath = $kp | New-CimInstancePath -value $instance.CimInstanceProperties[$($kp.name)].value\n        }\n        else {\n            Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Defining a singleton path\"\n            $newpath = $kp | New-CimInstancePath\n        }\n\n        if ($newpath) {\n            $Instance.CimSystemProperties |\n            Add-Member -MemberType NoteProperty -Name __Path -Value $newpath -Force\n            #write the updated instance to the pipeline\n            $instance\n        }\n    } #process\n    End {\n        Write-Verbose \"[$((Get-Date).TimeofDay) END    ] Ending $($myinvocation.mycommand)\"\n    } #end\n}<\/code><\/pre>\n\n\n\n<p>This function is designed to take a CImInstance and add a __Path property to CimSystemproperties.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"283\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath-1024x283.png\" alt=\"\" class=\"wp-image-8549\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath-1024x283.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath-300x83.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath-768x212.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath-850x235.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath.png 1389w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>I can use this value with the [WMI] type accelerator.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"364\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath2.png\" alt=\"\" class=\"wp-image-8550\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath2.png 730w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/add-ciminstancepath2-300x150.png 300w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Using Winrm<\/h2>\n\n\n\n<p>However, this doesn't really address the underlying issue. In a world without Get-WmiObject, what am I going to do with this path information? For now, PowerShell 7 still supports [wmi], even though Get-WmiObject is gone. This is fine for local queries. But if you are getting an instance on a remote server, I'm pretty sure [wmi] is using legacy protocols, which we want to avoid.<\/p>\n\n\n\n<p>But here's the interesting part. I can use the command-line tool winrm.cmd to query WMI over WSMan, just as Get-CimInstance is doing and I can give it an instance path.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/winrm-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"445\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/winrm-1-1024x445.png\" alt=\"\" class=\"wp-image-8551\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/winrm-1-1024x445.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/winrm-1-300x130.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/winrm-1-768x334.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/winrm-1-850x370.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/winrm-1.png 1343w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>The catch is that the path syntax is slightly different from what we get with Get-WMIObject. In other words, I need to transform this: \\\\THINKP1\\root\\cimv2:Win32_Service.Name=\"Spooler\" into this: wmi\/root\/cimv2\/win32_service?name=spooler. The computername is handled separately.<\/p>\n\n\n\n<p>I already have code to get the __Path value using Get-CimInstance. Assuming I'm saving this value for later use, I wrote this function which in essence transforms the WMI path into something compatible with the winrm command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-CimInstancePath {\n    #this function uses winrm.cmd. It may not properly process non-Cimv2 paths\n    [cmdletbinding()]\n    [alias(\"gcip\")]\n    [OutputType(\"CimInstance\")]\n    Param(\n        [Parameter(Position = 0, Mandatory, ValueFromPipeline)]\n        [ValidateNotNullOrEmpty()]\n        [string]$InstancePath\n    )\n\n    Begin {\n        Write-Verbose \"[$((Get-Date).TimeofDay) BEGIN] Starting $($myinvocation.mycommand)\"\n        [regex]$rx = '((\\\\\\\\(?&lt;computername&gt;\\w+)\\\\)?(?&lt;namespace&gt;(ROOT|root|Root)\\\\.*(?=:)):)?(?&lt;class&gt;\\w+(?=\\.|\\=))(\\.(?&lt;filter&gt;.*))?'\n    } #begin\n    Process {\n        Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Processing $instancepath\"\n        if ($rx.IsMatch($InstancePath)) {\n            $groups = $rx.match($InstancePath).groups\n            $computername = $groups['computername'].Value\n            $filter = $groups['filter'].Value.replace(\",\", \"+\")\n            $class = $groups['class'].Value\n\n            $namespace = $groups['namespace'].value\n\n            $ns = \"wmi\/$($namespace.replace('\\','\/'))\"\n\n            [string]$get = \"$ns\/$class\"\n            if ($filter) {\n                Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Appending filter $filter\"\n                $get += \"?$filter\"\n            }\n            Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Getting $get\"\n            #Write-Host \"winrm get $get\" -ForegroundColor cyan\n            #winrm get $get.trim() &gt;d:\\temp\\r.txt\n            #$global:g = $get\n            if ($computername) {\n                Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Querying remote computer $computername\"\n                &lt;#\n                        Normally I would never use Invoke-Expression, but PowerShell is doing\n                        something odd with multi-selector paths like Win32_Bios and failing.\n                        This seems the best option.\n                    #&gt;\n                [xml]$raw = Invoke-Expression \"winrm get $get -r:$Computername -f:xml 2&gt;$env:temp\\e.txt\"\n            }\n            else {\n                [xml]$raw = Invoke-Expression \"winrm get $get -f:xml 2&gt;$env:temp\\e.txt\"\n            }\n\n            if ($raw) {\n\n                #insert the corresponding CIM type name\n                $cimtype = \"Microsoft.Management.Infrastructure.CimInstance#$($namespace.replace(\"\\\",\"\/\"))\/$class\"\n                Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Inserting typename $cimtype\"\n                $result = $raw.$class\n                $result.psobject.typenames.insert(0, $cimtype)\n                #write the result to the pipeline\n                $result\n            }\n            elseif (Test-Path $env:temp\\e.txt) {\n                $m = '(?&lt;=f:Message\\&gt;)(.|\\n)*(?=\\n\\&lt;\\\/f:Message)'\n                #'Message(.*\\n.*)*'\n                $msg = [System.Text.RegularExpressions.Regex]::Match((Get-Content $env:temp\\e.txt -Raw), $m).value.trim()\n                Write-Warning \"Failed to get CIM Instance. `n$msg\"\n            }\n\n            if (Test-Path $env:temp\\e.txt) {\n                # Remove-Item $env:temp\\e.txt\n            }\n        }\n        else {\n            Write-Warning \"Failed to parse instance $instancepath\"\n        }\n    } #process\n\n    End {\n        Write-Verbose \"[$((Get-Date).TimeofDay) END    ] Ending $($myinvocation.mycommand)\"\n    } #end\n}<\/code><\/pre>\n\n\n\n<p>This function not only takes the path and gets the information using winrm, it also creates an object and inserts the corresponding CIM property name, which lets PowerShell format the output just as it would using Get-CimInstance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$p = (get-ciminstance win32_service -filter \"name='bits'\" | Add-CimInstancePath).cimsystemproperties.__Path\nGet-CimInstancePath -InstancePath $p<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/get-ciminstancepath.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"181\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/get-ciminstancepath-1024x181.png\" alt=\"\" class=\"wp-image-8552\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/get-ciminstancepath-1024x181.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/get-ciminstancepath-300x53.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/get-ciminstancepath-768x136.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/get-ciminstancepath-850x150.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/get-ciminstancepath.png 1314w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Now I have a command that uses CIM and retrieves a WMI object by the instance path. There's no guarantee my code will work with all WMI classes, but I expect it should with the default win32 classes in Root\\Cimv2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Next Steps<\/h2>\n\n\n\n<p>I might publish these functions in a module to the PowerShell Gallery. As for PowerShell 7 and the open issue, I'm not sure what approach Microsoft should take. They could add a parameter to Get-CimInstance to get an instance by its path. Although they would also need to fix the missing system Path property. Another option would be to introduce a [cim] type accelerator that would work the same as [wmi]. The hypothetical [cim] would work the same as my Get-CimInstancePath.<\/p>\n\n\n\n<p>In the meantime, I hope you'll try these things out.  And if your work leverages getting WMI objects by path, I'd love to hear about it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am a member of the PowerShell Cmdlet Working Group. We&#8217;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. Personally, I never have had&#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: Getting CIMInstance by Path #PowerShell #PS7Now","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,8,19],"tags":[387,540,547],"class_list":["post-8541","post","type-post","status-publish","format-standard","hentry","category-powershell","category-powershell-7","category-scripting","category-wmi","tag-cim","tag-scripting","tag-wmi"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Getting CIMInstance by Path &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"Here&#039;s how I use CIM to get WMI objects by their path in PowerShell. We can use [wmi] in Windows PowerShell but what about PowerShell 7?\" \/>\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\/8541\/getting-ciminstance-by-path\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting CIMInstance by Path &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Here&#039;s how I use CIM to get WMI objects by their path in PowerShell. We can use [wmi] in Windows PowerShell but what about PowerShell 7?\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-20T16:29:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-20T20:19:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath-1024x231.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=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Getting CIMInstance by Path\",\"datePublished\":\"2021-08-20T16:29:46+00:00\",\"dateModified\":\"2021-08-20T20:19:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/\"},\"wordCount\":803,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/wmipath-1024x231.png\",\"keywords\":[\"CIM\",\"Scripting\",\"WMI\"],\"articleSection\":[\"PowerShell\",\"PowerShell 7\",\"Scripting\",\"WMI\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/\",\"name\":\"Getting CIMInstance by Path &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/wmipath-1024x231.png\",\"datePublished\":\"2021-08-20T16:29:46+00:00\",\"dateModified\":\"2021-08-20T20:19:43+00:00\",\"description\":\"Here's how I use CIM to get WMI objects by their path in PowerShell. We can use [wmi] in Windows PowerShell but what about PowerShell 7?\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/wmipath.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/wmipath.png\",\"width\":1324,\"height\":299},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8541\\\/getting-ciminstance-by-path\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Getting CIMInstance by Path\"}]},{\"@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":"Getting CIMInstance by Path &#8226; The Lonely Administrator","description":"Here's how I use CIM to get WMI objects by their path in PowerShell. We can use [wmi] in Windows PowerShell but what about PowerShell 7?","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\/8541\/getting-ciminstance-by-path\/","og_locale":"en_US","og_type":"article","og_title":"Getting CIMInstance by Path &#8226; The Lonely Administrator","og_description":"Here's how I use CIM to get WMI objects by their path in PowerShell. We can use [wmi] in Windows PowerShell but what about PowerShell 7?","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/","og_site_name":"The Lonely Administrator","article_published_time":"2021-08-20T16:29:46+00:00","article_modified_time":"2021-08-20T20:19:43+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath-1024x231.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":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Getting CIMInstance by Path","datePublished":"2021-08-20T16:29:46+00:00","dateModified":"2021-08-20T20:19:43+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/"},"wordCount":803,"commentCount":6,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath-1024x231.png","keywords":["CIM","Scripting","WMI"],"articleSection":["PowerShell","PowerShell 7","Scripting","WMI"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/","name":"Getting CIMInstance by Path &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath-1024x231.png","datePublished":"2021-08-20T16:29:46+00:00","dateModified":"2021-08-20T20:19:43+00:00","description":"Here's how I use CIM to get WMI objects by their path in PowerShell. We can use [wmi] in Windows PowerShell but what about PowerShell 7?","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/wmipath.png","width":1324,"height":299},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Getting CIMInstance by Path"}]},{"@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":8541,"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":6082,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6082\/searching-for-a-cim-wmi-class-with-powershell\/","url_meta":{"origin":8541,"position":1},"title":"Searching for a CIM\/WMI Class with PowerShell","author":"Jeffery Hicks","date":"September 18, 2018","format":false,"excerpt":"I got a question on Twitter about an older function I has posted to get antivirus information via WMI. The function continues to work fine with Windows 10, although there's always room for improvement. However, the question was that the function did not seem to work when querying a server\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\/2018\/09\/image_thumb.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/image_thumb.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/image_thumb.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/image_thumb.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":3661,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/","url_meta":{"origin":8541,"position":2},"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":7835,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7835\/finding-zombie-files-with-powershell\/","url_meta":{"origin":8541,"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":5577,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5577\/friday-fun-listing-wmi-namespaces\/","url_meta":{"origin":8541,"position":4},"title":"Friday Fun: Listing WMI Namespaces","author":"Jeffery Hicks","date":"May 5, 2017","format":false,"excerpt":"Welcome once again to the end of the week.\u00a0 Hopefully you spent some time in PowerShell. If not, perhaps this tidbit will be intriguing enough to give it a try. I always try to put the \"fun\" in function and today I have one that will enumerate all the WMI\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":5187,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5187\/get-antivirus-product-status-with-powershell\/","url_meta":{"origin":8541,"position":5},"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":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8541","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=8541"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8541\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}