{"id":3661,"date":"2014-01-29T12:04:52","date_gmt":"2014-01-29T17:04:52","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=3661"},"modified":"2014-01-29T12:14:08","modified_gmt":"2014-01-29T17:14:08","slug":"creating-cim-scripts-without-scripting","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/","title":{"rendered":"Creating CIM Scripts without Scripting"},"content":{"rendered":"<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM1.png\" align=\"left\" \/>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 modules and cmdlets was CDXML. With some work and a properly formatted XML file, you could create your own commands based on WMI and CIM classes. Modules like SMBShare were built the same way. But creating a CDXML based module is not a task for someone just getting started with PowerShell.<\/p>\n<p>So I decided to build a tool that just about anyone could use to create their own CIM-based commands, using relatively common PowerShell scripting techniques. You might find some of the things I do in my script just as interesting or useful. I was also motivated because I know that many IT Pros want to script but don't have the time or feel they don't have the skills. I hope what I've come up with will help jump start or accelerate the process.<\/p>\n<p>My script, CIMScriptMaker.ps1, will guide you through identifying a WMI class and create an advanced function to get instances of that class. You can even add a filter and select which properties to display. You can then edit the function further if you want and end up with a practical tool that didn't take a lot of time to write. Let me walk you through the process. The script works in either the console or the ISE. I'll launch the script from the prompt.<\/p>\n<pre class=\"lang:batch decode:true \" >PS C:\\&gt; C:\\scripts\\CIMScriptMaker.ps1\r\nEnumerating namspaces on JH-WIN81-ENT....please wait...\r\n<\/pre>\n<p>The script defaults to the local computer, but you can specify a remote computer running PowerShell 3 or later. The script then enumerates the namespaces and presents a list using Out-Gridview. I use the title as a prompt.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM2.png\" \/><\/p>\n<p>I'll select Root\\CimV2 and click OK. My script then queries all the classes in that namespace and again displays a list using Out-Gridview. What's nice is that you can use the filtering capability to quickly find a class you are interested in.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM3.png\" \/><\/p>\n<p>I'm going to select Win32_PageFileUsage and click OK. Using the Popup method from the old Wscript.Shell VBScript object I prompt if the user wants to test retrieving all instances of the selected class.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM4.png\" \/><\/p>\n<p>Naturally, I do. If there are results, they will be displayed in Out-Gridview again.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM5.png\" \/><\/p>\n<p>The script will wait for me to close the gridview. After which I'll be prompted to continue.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM6.png\" \/><\/p>\n<p>Next the script will display a list of properties for the class and ask if I want to filter.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM7.png\" \/><\/p>\n<p>If you opt to filter, you'll get a gridview with a list of operators to choose from. The default is =. Then you'll get a Visual Basic message box asking you to enter in a value. For this demo I clicked Cancel to skip filtering.<\/p>\n<p>Next I am prompted to select the properties. Clicking cancel will in essence give you the full CIM object. If you select properties then behind the scenes I'm generating code that is piping a Get-CimInstance command to Select-Object. I'll select a few.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM8.png\" \/><\/p>\n<p>And that's it! The script will generate an advanced function based on the selections you have made. The function defaults to a name using the Get verb and the noun is the class name. The function is copied to the clipboard so that you can paste it into your script editor and also saved to a global variable, $cimscript, just in case you accidentally overwrite the clipboard<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM9.png\" \/><\/p>\n<p>If you are in the console, you can right-click to paste it right into your current session. The function includes comment based help. The function can take computer names or you can use CIMSessions.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM10.png\" \/><\/p>\n<p>Here's what the generated code looks like.<\/p>\n<pre class=\"lang:ps decode:true \" >\r\n#Requires -version 3.0\r\n\r\nFunction Get-Win32_PageFileUsage  {\r\n&lt;#\r\n.Synopsis\r\nGet Win32_PageFileUsage information\r\n.Description\r\nThis command uses the CIM cmdlets to query a remote computer for information\r\nfrom the Win32_PageFileUsage class in the Root\\CIMV2 namespace. \r\nThis command requires PowerShell 3.0 or later.\r\n.Parameter Computername\r\nThe name of a computer to query. It should be running PowerShell 3.0 or later.\r\nThis parameter also supports aliases of CN and Host.\r\n.Parameter CimSession\r\nA previously created CimSession. Works best when you pipe the CimSession\r\nto this command. See examples.\r\n.Example\r\nPS C:\\&gt; Get-Win32_PageFileUsage\r\n\r\nRun the command defaulting to the local computername.\r\n.Example\r\nPS C:\\&gt; Get-CimSession | Get-Win32_PageFileUsage | Out-Gridview -title Get-Win32_PageFileUsage\r\n\r\nGet all CIMSessions and pipe them to this command sending results to Out-Gridview.\r\n.Notes\r\nVersion     : 1.0\r\nAuthor      : JH-WIN81-ENT\\Jeff\r\nLast Updated: 1\/29\/2014\r\n.Inputs\r\nString or CimSession\r\n.Outputs\r\nCIMObject or custom object\r\n.Link\r\nGet-CimInstance\r\nGet-CimSession\r\n#&gt;\r\n\r\n[cmdletbinding(DefaultParameterSetName=\"Computer\")]\r\nParam(\r\n[Parameter(Position=0,ValueFromPipelinebyPropertyName=$True,\r\nParameterSetName=\"Computer\")]\r\n[ValidateNotNullorEmpty()]\r\n[Alias(\"CN\",\"Host\")]\r\n[string[]]$Computername=$env:Computername,\r\n\r\n[Parameter(Position=0,ValueFromPipeline=$True,\r\nParameterSetName=\"Session\")]\r\n[string[]]$CimSession\r\n\r\n)\r\n\r\nBegin {\r\n Write-Verbose \"Starting command $($MyInvocation.Mycommand)\"\r\n #create a hashtable of parameters to splat against Get-CimInstance\r\n $cimParam=@{\r\n Namespace = \"Root\\CIMV2\"\r\n ClassName = \"Win32_PageFileUsage \"\r\n ErrorAction = \"Stop\" \r\n }\r\n} #begin\r\n\r\nProcess {\r\n if ($computername) {\r\n   $cimParam.Computername=$computername\r\n   Write-Verbose \"Processing $Computername\"\r\n }\r\n else {\r\n   #must be a cimsession\r\n   $cimParam.CIMSession=$CimSession\r\n   Write-Verbose \"Processing $($CimSession.ComputerName)\"\r\n }\r\n \r\n Try {\r\n    Get-CimInstance @cimParam | \r\n    Select-Object -property InstallDate,Name,Status,AllocatedBaseSize,CurrentUsage,PeakUsage,TempPageFile,PSComputername\r\n } #try\r\n Catch {\r\n    Write-Warning \"Failed to retrieve information. $($_.Exception.Message)\"\r\n } #catch\r\n} #Process\r\n\r\nEnd {\r\n Write-Verbose \"Ending command $($MyInvocation.Mycommand)\"\r\n} #end\r\n\r\n} #end function\r\n<\/pre>\n<p>Now I have a CIM based tool that just works or I can develop it further.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM11.png\" \/><\/p>\n<p>Right now, all my script does is generate a command to get WMI information using Get-CimInstance. With a little more work I could probably have it generate commands that do things as well using WMI class methods. But that's for another day. In the mean time, here is my script.<\/p>\n<pre class=\"lang:ps decode=True\">\r\n#requires -version 3.0\r\n\r\n<#\r\nVersion: 1.0\r\nAuthor : Jeff Hicks\r\n         @jeffhicks\r\n         http:\/\/jdhitsolutions.com\/blog\r\n\r\n\"Those who forget to script are doomed to repeat their work.\"\r\n\r\nLearn more:\r\n PowerShell in Depth: An Administrator's Guide \r\n PowerShell Deep Dives \r\n Learn PowerShell 3 in a Month of Lunches \r\n Learn PowerShell Toolmaking in a Month of Lunches \r\n PowerShell and WMI \r\n \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#>\r\n\r\nParam([string]$computername = $env:COMPUTERNAME)\r\n\r\nFunction Get-Namespace {\r\n#this function will recursively enumerate namespaces\r\n\r\nParam(\r\n[string]$Namespace=\"Root\",\r\n[Microsoft.Management.Infrastructure.CimSession]$CimSession\r\n)\r\n\r\n $nspaces = $cimsession | Get-CimInstance -Namespace $Namespace -ClassName __Namespace\r\n  foreach ($nspace in $nspaces) {\r\n\r\n  $child = Join-Path -Path $Namespace -ChildPath $nspace.Name\r\n  $child\r\n  Get-Namespace $child $CimSession\r\n  }\r\n}\r\n\r\n#create a CIMSession\r\n$cimsess = New-CimSession -ComputerName $computername\r\n\r\n#browse namespaces\r\nWrite-Host \"Enumerating namspaces on $computername....please wait...\" -ForegroundColor Cyan\r\n$ns = Get-Namespace -CimSession $cimsess | Sort |\r\nOut-GridView -Title \"$($cimsess.Computername): Select a namespace\" -OutputMode Single\r\n\r\nif ($ns) {\r\n    #get classes filtering out system classes\r\n    Write-Host \"Enumerating classes...please wait...\" -ForegroundColor Cyan\r\n    $class = $cimsess | Get-CimClass -Namespace $ns | \r\n    Where {$_.cimclassname -notmatch \"^__\" -AND $_.CimClassProperties.Name -notcontains \"Antecedent\"} | \r\n    Sort CimClassName | Select CimClassName,CimClassProperties |\r\n    Out-GridView -Title \"$NS : Select a class name\" -OutputMode Single\r\n}\r\n\r\nif ($class) {\r\n\r\n    #create a VBScript message box\r\n    $wshell = New-Object -ComObject \"Wscript.Shell\"\r\n    $r = $wshell.Popup(\"Do you want to test this class?\",-1,$class.CimClassname,32+4)\r\n\r\n    if ($r -eq 6) {\r\n        #Yes\r\n        $test = $cimsess | Get-CimInstance -Namespace $ns -ClassName $class.CimClassName \r\n        if ($test) {\r\n         $test | Out-GridView -Title \"$NS\\$($Class.cimClassName)\" -Wait\r\n         $prompt=\"Do you want to continue?\"\r\n         $icon=32+4\r\n        }\r\n        else {\r\n          $prompt=\"No results were returned. Do you want to continue?\"\r\n          $icon=16+4\r\n        }\r\n\r\n        $r = $wshell.Popup($prompt,-1,$class.CimClassname,$icon)\r\n        if ($r -eq 7) {\r\n          Write-Host \"Exiting. Please try again later.\" -ForegroundColor Yellow\r\n          #bail out\r\n          Return\r\n        }\r\n\r\n    } #if r = 6\r\n\r\n    #define basic command\r\n    $cmd = \"Get-CimInstance @cimParam\"\r\n    \r\n    #create a filter\r\n    $filterProperty = $class.CimClassProperties | Select Name,CimType,Flags |\r\n    Out-GridView -Title \"Select a property to filter on or cancel to not filter.\" -OutputMode Single\r\n\r\n    if ($filterProperty) {\r\n        $operator = \"=\",\"<\",\">\",\"<>\",\">=\",\"<=\",\"like\" | \r\n        Out-GridView -Title \"Select an operator. Default if you cancel is =\" -OutputMode Single\r\n\r\n        #create a VBSCript inputbox\r\n        Add-Type -AssemblyName \"microsoft.visualbasic\" -ErrorAction Stop \r\n        $Prompt = \"Enter a value for your filter. If using a string, wrap the value in ''. If using Like, use % as the wildcard character.\"\r\n        $title= \"-filter \"\"$($filterproperty.Name) $operator ?\"\"\"\r\n        $value=[microsoft.visualbasic.interaction]::InputBox($Prompt,$Title)\r\n\r\n        $filter = \"-filter \"\"$($filterproperty.Name) $operator $value\"\"\"\r\n        \r\n        $cmd+=\" $filter\"\r\n    } #if filterproperty\r\n\r\n    #show properties\r\n    Write-Host \"Getting class properties\" -ForegroundColor Cyan\r\n    $properties = $class.CimClassProperties | select Name,CimType,Flags | \r\n    Out-Gridview -Title \"$($class.CimClassName) : Select one or more properties. Cancel will select *\" -PassThru\r\n\r\n    if ($properties) {\r\n     $select = $properties.name -join \",\"\r\n     $cmd+= @\"\r\n | \r\n    Select-Object -property $select,PSComputername\r\n\"@\r\n    } #if properties\r\n\r\n} #if $class\r\n\r\n#define a name for the function using the class name\r\n$cmdName = \"Get-$($class.CimClassName)\"\r\n\r\n#the auto-generated PowerShell code\r\n$myScript = @\"\r\n#Requires -version 3.0\r\n\r\nFunction $cmdName  {\r\n<#\r\n.Synopsis\r\nGet $($Class.CimClassName) information\r\n.Description\r\nThis command uses the CIM cmdlets to query a remote computer for information\r\nfrom the $($Class.CimClassName) class in the $NS namespace. \r\nThis command requires PowerShell 3.0 or later.\r\n.Parameter Computername\r\nThe name of a computer to query. It should be running PowerShell 3.0 or later.\r\nThis parameter also supports aliases of CN and Host.\r\n.Parameter CimSession\r\nA previously created CimSession. Works best when you pipe the CimSession\r\nto this command. See examples.\r\n.Example\r\nPS C:\\> $cmdName\r\n\r\nRun the command defaulting to the local computername.\r\n.Example\r\nPS C:\\> Get-CimSession | $cmdName | Out-Gridview -title $cmdName\r\n\r\nGet all CIMSessions and pipe them to this command sending results to Out-Gridview.\r\n.Notes\r\nVersion     : 1.0\r\nAuthor      : $($env:userdomain)\\$($env:username)\r\nLast Updated: $((Get-Date).ToShortDateString())\r\n.Inputs\r\nString or CimSession\r\n.Outputs\r\nCIMObject or custom object\r\n.Link\r\nGet-CimInstance\r\nGet-CimSession\r\n#>\r\n\r\n[cmdletbinding(DefaultParameterSetName=\"Computer\")]\r\nParam(\r\n[Parameter(Position=0,ValueFromPipelinebyPropertyName=`$True,\r\nParameterSetName=\"Computer\")]\r\n[ValidateNotNullorEmpty()]\r\n[Alias(\"CN\",\"Host\")]\r\n[string[]]`$Computername=`$env:Computername,\r\n\r\n[Parameter(Position=0,ValueFromPipeline=`$True,\r\nParameterSetName=\"Session\")]\r\n[string[]]`$CimSession\r\n\r\n)\r\n\r\nBegin {\r\n Write-Verbose \"Starting command `$(`$MyInvocation.Mycommand)\"\r\n #create a hashtable of parameters to splat against Get-CimInstance\r\n `$cimParam=@{\r\n Namespace = \"$NS\"\r\n ClassName = \"$($Class.CimClassName) \"\r\n ErrorAction = \"Stop\" \r\n }\r\n} #begin\r\n\r\nProcess {\r\n if (`$computername) {\r\n   `$cimParam.Computername=`$computername\r\n   Write-Verbose \"Processing `$Computername\"\r\n }\r\n else {\r\n   #must be a cimsession\r\n   `$cimParam.CIMSession=`$CimSession\r\n   Write-Verbose \"Processing `$(`$CimSession.ComputerName)\"\r\n }\r\n \r\n Try {\r\n    $cmd\r\n } #try\r\n Catch {\r\n    Write-Warning \"Failed to retrieve information. `$(`$_.Exception.Message)\"\r\n } #catch\r\n} #Process\r\n\r\nEnd {\r\n Write-Verbose \"Ending command `$(`$MyInvocation.Mycommand)\"\r\n} #end\r\n\r\n} #end function\r\n\"@\r\n\r\n$myScript | clip\r\n$global:cimscript = $myScript\r\n\r\n#remove the cimsession\r\n$cimsess | Remove-CimSession\r\n\r\nWrite-Host \"Your function, $cmdName, has been saved to the clipboard and in the global variable `$cimscript.\" -ForegroundColor Green\r\n<\/pre>\n<p>What do you think?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 modules and cmdlets was CDXML&#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":"Fresh from the blog: Creating CIM Scripts without Scripting http:\/\/bit.ly\/1cuU2ic #PowerShell","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,359,450,8,19],"tags":[387,534,540,547],"class_list":["post-3661","post","type-post","status-publish","format-standard","hentry","category-powershell","category-powershell-3-0","category-powershell-4-0","category-scripting","category-wmi","tag-cim","tag-powershell","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>Creating CIM Scripts without Scripting &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating CIM Scripts without Scripting &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"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 modules and cmdlets was CDXML....\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2014-01-29T17:04:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-01-29T17:14:08+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM1.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\\\/3661\\\/creating-cim-scripts-without-scripting\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3661\\\/creating-cim-scripts-without-scripting\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Creating CIM Scripts without Scripting\",\"datePublished\":\"2014-01-29T17:04:52+00:00\",\"dateModified\":\"2014-01-29T17:14:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3661\\\/creating-cim-scripts-without-scripting\\\/\"},\"wordCount\":716,\"commentCount\":7,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3661\\\/creating-cim-scripts-without-scripting\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/012914_1704_CreatingCIM1.png\",\"keywords\":[\"CIM\",\"PowerShell\",\"Scripting\",\"WMI\"],\"articleSection\":[\"PowerShell\",\"Powershell 3.0\",\"PowerShell 4.0\",\"Scripting\",\"WMI\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3661\\\/creating-cim-scripts-without-scripting\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3661\\\/creating-cim-scripts-without-scripting\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3661\\\/creating-cim-scripts-without-scripting\\\/\",\"name\":\"Creating CIM Scripts without Scripting &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3661\\\/creating-cim-scripts-without-scripting\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3661\\\/creating-cim-scripts-without-scripting\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/012914_1704_CreatingCIM1.png\",\"datePublished\":\"2014-01-29T17:04:52+00:00\",\"dateModified\":\"2014-01-29T17:14:08+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3661\\\/creating-cim-scripts-without-scripting\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3661\\\/creating-cim-scripts-without-scripting\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3661\\\/creating-cim-scripts-without-scripting\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/012914_1704_CreatingCIM1.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/012914_1704_CreatingCIM1.png\",\"width\":197,\"height\":239},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3661\\\/creating-cim-scripts-without-scripting\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Creating CIM Scripts without Scripting\"}]},{\"@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":"Creating CIM Scripts without Scripting &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/","og_locale":"en_US","og_type":"article","og_title":"Creating CIM Scripts without Scripting &#8226; The Lonely Administrator","og_description":"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 modules and cmdlets was CDXML....","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/","og_site_name":"The Lonely Administrator","article_published_time":"2014-01-29T17:04:52+00:00","article_modified_time":"2014-01-29T17:14:08+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM1.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\/3661\/creating-cim-scripts-without-scripting\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Creating CIM Scripts without Scripting","datePublished":"2014-01-29T17:04:52+00:00","dateModified":"2014-01-29T17:14:08+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/"},"wordCount":716,"commentCount":7,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM1.png","keywords":["CIM","PowerShell","Scripting","WMI"],"articleSection":["PowerShell","Powershell 3.0","PowerShell 4.0","Scripting","WMI"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/","name":"Creating CIM Scripts without Scripting &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM1.png","datePublished":"2014-01-29T17:04:52+00:00","dateModified":"2014-01-29T17:14:08+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM1.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/01\/012914_1704_CreatingCIM1.png","width":197,"height":239},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3661\/creating-cim-scripts-without-scripting\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Creating CIM Scripts without Scripting"}]},{"@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":2342,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2342\/query-local-administrators-with-cim\/","url_meta":{"origin":3661,"position":0},"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":6082,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6082\/searching-for-a-cim-wmi-class-with-powershell\/","url_meta":{"origin":3661,"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":2935,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/","url_meta":{"origin":3661,"position":2},"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":5187,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5187\/get-antivirus-product-status-with-powershell\/","url_meta":{"origin":3661,"position":3},"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":8541,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8541\/getting-ciminstance-by-path\/","url_meta":{"origin":3661,"position":4},"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":3615,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3615\/powershell-essentials-webinar\/","url_meta":{"origin":3661,"position":5},"title":"PowerShell Essentials Webinar","author":"Jeffery Hicks","date":"January 29, 2014","format":false,"excerpt":"Tomorrow I will be presenting a day of PowerShell training via a series of webinars for Windows IT Pro magazine. I will be presenting 3 webinars, each about 1 hour in length. The first webinar is on the PowerShell syntax and shell. Basically, how to survive in the shell if\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/windowsitpro.com\/site-files\/windowsitpro.com\/files\/imagecache\/product\/OnLine_icon_48.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3661","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=3661"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3661\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=3661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=3661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=3661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}