{"id":636,"date":"2010-05-13T09:16:21","date_gmt":"2010-05-13T14:16:21","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=636"},"modified":"2014-03-15T10:33:08","modified_gmt":"2014-03-15T14:33:08","slug":"select-wmi","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/","title":{"rendered":"Select WMI"},"content":{"rendered":"<p>I\u2019ve been helping out on some WMI and PowerShell issues in the forums at ScriptingAnswers.com. As I was working on a problem I ended up taking a slight detour to address an issue that has always bugged me. When I run a command like this:<\/p>\n<pre class=\"lang:ps decode:true \" >get-wmiobject -query \"Select Name,Description,Disabled from Win32_UserAccount\"<\/pre>\n<p>PowerShell wants to return system classes as well.<\/p>\n<pre class=\"lang:batch decode:true \" >PS C:\\&gt; get-wmiobject -query \"Select Name,Description,Disabled from Win32_UserAccount\"\r\n\r\n\r\n__GENUS          : 2\r\n__CLASS          : Win32_UserAccount\r\n__SUPERCLASS     :\r\n__DYNASTY        :\r\n__RELPATH        :\r\n__PROPERTY_COUNT : 3\r\n__DERIVATION     : {}\r\n__SERVER         :\r\n__NAMESPACE      :\r\n__PATH           :\r\nDescription      : Built-in account for administering the computer\/domain\r\nDisabled         : False\r\nName             : Administrator\r\nPSComputerName   :\r\n\r\n...<\/pre>\n<p>The work around has been to pipe the original expression to <a title=\"Get online help for this cmdlet\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113387\" target=\"_blank\">Select-Object<\/a> and re-selecting the properties I want. This seems like an unnecessary step. Now, depending on the class I could simple return all WMI objects and then use Select-Object. But I should be able to take advantage of early filtering and use <a title=\"get on line help\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113337\" target=\"_blank\">Get-WmiObject<\/a> as it was intended. So I wrote a function called Select-WMI that will take any WMI-looking object and return the non system properties.<\/p>\n<pre class=\"lang:ps decode:true\">#requires -version 2.0\r\n\r\nFunction Select-WMI {\r\n&lt;#\r\n.Synopsis\r\nReturn non system properties from a WMI Object.\r\n.Description\r\nWhen using -query and Get-WmiObject, you get system properties included, like __CLASS \r\nand __SERVER. This function will strip off these properties and only return class properties.  \r\nUse -Populated when you want to get all class properties but only if they have a value\r\ndefined. This is similar to piping a WMI object to Select * except in this function\r\nyou'll only get properties with a value.\r\n.Parameter InputObject\r\nA WMI object either from a Get-WMIObject expression.\r\n.Parameter Populated\r\nOnly return properties that have a defined value.\r\n.Example\r\nPS C:\\&gt; Get-WMIObject -query \"Select Model,Name,Manufacturer from win32_computersystem\" | Select-WMI\r\nManufacturer               Model                      Name                     \r\n------------               -----                      ----                     \r\nTOSHIBA                    Qosmio X505                SERENITY                 \r\n\r\n.Example\r\nPS C:\\&gt; Get-WMIObject win32_operatingsystem | Select-WMI\r\nBootDevice                                : \\Device\\HarddiskVolume1\r\nBuildNumber                               : 7600\r\nBuildType                                 : Multiprocessor Free\r\nCaption                                   : Microsoft Windows 7 Ultimate \r\nCodeSet                                   : 1252\r\nCountryCode                               : 1\r\nCreationClassName                         : Win32_OperatingSystem\r\nCSCreationClassName                       : Win32_ComputerSystem\r\nCSDVersion                                : \r\nCSName                                    : SERENITY\r\nCurrentTimeZone                           : -240\r\nDataExecutionPrevention_32BitApplications : True\r\nDataExecutionPrevention_Available         : True\r\nDataExecutionPrevention_Drivers           : True\r\nDataExecutionPrevention_SupportPolicy     : 2\r\nDebug                                     : False\r\nDescription                               : \r\nDistributed                               : False\r\nEncryptionLevel                           : 256\r\nForegroundApplicationBoost                : 2\r\nFreePhysicalMemory                        : 2346688\r\nFreeSpaceInPagingFiles                    : 4182504\r\nFreeVirtualMemory                         : 6091932\r\nInstallDate                               : 20100120131825.000000-300\r\nLargeSystemCache                          : \r\nLastBootUpTime                            : 20100511175627.595198-240\r\nLocalDateTime                             : 20100511180234.565000-240\r\nLocale                                    : 0409\r\nManufacturer                              : Microsoft Corporation\r\nMaxNumberOfProcesses                      : 4294967295\r\nMaxProcessMemorySize                      : 8589934464\r\nMUILanguages                              : {en-US}\r\nName                                      : Microsoft Windows 7 Ultimate |C:\\Wi\r\n                                            ndows|\\Device\\Harddisk0\\Partition2\r\nNumberOfLicensedUsers                     : \r\nNumberOfProcesses                         : 80\r\nNumberOfUsers                             : 5\r\nOperatingSystemSKU                        : 1\r\nOrganization                              : JDH Information Technology Solution\r\n                                            s\r\nOSArchitecture                            : 64-bit\r\nOSLanguage                                : 1033\r\nOSProductSuite                            : 256\r\nOSType                                    : 18\r\nOtherTypeDescription                      : \r\nPAEEnabled                                : \r\nPlusProductID                             : \r\nPlusVersionNumber                         : \r\nPrimary                                   : True\r\nProductType                               : 1\r\nRegisteredUser                            : Jeff\r\nSerialNumber                              : 00426-065-0389393-86732\r\nServicePackMajorVersion                   : 0\r\nServicePackMinorVersion                   : 0\r\nSizeStoredInPagingFiles                   : 4182504\r\nStatus                                    : OK\r\nSuiteMask                                 : 272\r\nSystemDevice                              : \\Device\\HarddiskVolume2\r\nSystemDirectory                           : C:\\Windows\\system32\r\nSystemDrive                               : C:\r\nTotalSwapSpaceSize                        : \r\nTotalVirtualMemorySize                    : 8363108\r\nTotalVisibleMemorySize                    : 4182504\r\nVersion                                   : 6.1.7600\r\nWindowsDirectory                          : C:\\Windows\r\n\r\n.Example\r\nPS C:\\&gt; Get-WMIObject win32_bios -computername SERVER01 | Select-WMI -Populated\r\nBiosCharacteristics   : {4, 7, 8, 9...}\r\nBIOSVersion           : {TOSQCI - 6040000, Ver 1.00PARTTBL}\r\nCaption               : Ver 1.00PARTTBL\r\nDescription           : Ver 1.00PARTTBL\r\nManufacturer          : TOSHIBA\r\nName                  : Ver 1.00PARTTBL\r\nPrimaryBIOS           : True\r\nReleaseDate           : 20100223000000.000000+000\r\nSerialNumber          : Z9131790W\r\nSMBIOSBIOSVersion     : V2.20   \r\nSMBIOSMajorVersion    : 2\r\nSMBIOSMinorVersion    : 6\r\nSMBIOSPresent         : True\r\nSoftwareElementID     : Ver 1.00PARTTBL\r\nSoftwareElementState  : 3\r\nStatus                : OK\r\nTargetOperatingSystem : 0\r\nVersion               : TOSQCI - 6040000\r\n.Example\r\nPS C:\\&gt; Select-wmi (gwmi win32_useraccount) | select -first 1\r\n\r\nAccountType        : 512\r\nCaption            : SERENITY\\Administrator\r\nDescription        : Built-in account for administering the computer\/domain\r\nDisabled           : False\r\nDomain             : SERENITY\r\nFullName           :\r\nInstallDate        :\r\nLocalAccount       : True\r\nLockout            : False\r\nName               : Administrator\r\nPasswordChangeable : True\r\nPasswordExpires    : False\r\nPasswordRequired   : True\r\nSID                : S-1-5-21-2858895768-3673612314-3109562570-500\r\nSIDType            : 1\r\nStatus             : OK\r\n.Inputs\r\nAny WMI or [system.management.managementobject] object\r\n.Outputs\r\nA WMI or [system.management.managementobject] object\r\n.Link\r\nGet-WMIObject\r\nSelect-Object\r\n.Link\r\nhttp:\/\/bit.ly\/ebmiio\r\n\r\n.Notes\r\n NAME:      Select-WMI\r\n VERSION:   1.1\r\n AUTHOR:    Jeffery Hicks (@jeffhicks)\r\n LASTEDIT:  5\/11\/2010\r\n\r\n      Learn 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\r\n     \"Those who forget to script are doomed to repeat their work.\"\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#&gt;\r\n\r\n[CmdletBinding()]\r\nParam(\r\n[Parameter(Position=0,ValueFromPipeline=$True)]\r\n[object[]]$InputObject,\r\n[switch]$Populated\r\n)\r\nBegin {\r\n    write-verbose \"Starting $($myinvocation.MyCommand)\"\r\n    if ($populated) {\r\n        write-verbose \"Populated specified\"\r\n    }\r\n} #Begin\r\n\r\nProcess {\r\n    write-verbose \"Analyzing object\"\r\n    foreach ($item in $inputObject) {\r\n    #only process objects that look like WMI objects\r\n    if ($item.__CLASS) {\r\n        write-verbose \"Found $($item.psbase.properties.count) properties\"\r\n        #create an empty array to hold property names\r\n        $properties=@()\r\n        $populatedProperties=@()\r\n\r\n        foreach ($property in $item.properties) {\r\n          if ($Populated -AND  $item.($property.name) -ne $NULL) {\r\n           #only add property name if it has a value\r\n           write-verbose \"Value confirmed. Adding $($property.name)\"\r\n           #the following line will display the property value as a string\r\n           #so you might get funny looking output\r\n           #write-verbose  ($item.($property.name) | out-string)\r\n           $populatedProperties+=$property.name\r\n           }\r\n           else {\r\n           write-verbose \"Adding $($property.name)\"\r\n           $properties+=$property.name\r\n           }\r\n        }\r\n           write-verbose \"Returning WMI Object\"\r\n           if ($populated) {\r\n              write-verbose \"Returning $($populatedProperties.count) populated properties\"\r\n              $item | select $populatedProperties\r\n           }\r\n           else {\r\n              $item | select $properties\r\n           }\r\n    }\r\n      else {\r\n\r\n        Write-warning \"You did not pass a valid WMI Object\"\r\n      }\r\n    } #ForEach\r\n} #Process\r\n\r\nEnd {\r\n    write-verbose \"Ending $($myinvocation.MyCommand)\"\r\n } #end\r\n} #end function<\/pre>\n<p>I assumed you would run it as part of a pipeline. Now, I can more easily get the information I\u2019m after.<br \/>\n<a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-300x89.png\" alt=\"selectwmi\" width=\"300\" height=\"89\" class=\"aligncenter size-medium wp-image-3753\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-300x89.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi.png 800w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The function will also work to bypass PowerShell\u2019s default formatting for WMI objects, making it easier to see all the properties.<br \/>\n<a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-2-300x244.png\" alt=\"selectwmi-2\" width=\"300\" height=\"244\" class=\"aligncenter size-medium wp-image-3754\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-2-300x244.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-2.png 570w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>But I took this one step further. There are times when all I want are properties that have a value. So Select-WMI has a \u2013Populated parameter so that only populated properties are displayed.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-3-300x180.png\" alt=\"selectwmi-3\" width=\"300\" height=\"180\" class=\"aligncenter size-medium wp-image-3755\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-3-300x180.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-3.png 555w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now, you'll only really need this when using the WMI cmdlets. In PowerShell v3 and later you can use Get-CimInstance which by default does not display the system properties.<\/p>\n<p>[updated March 15, 2014]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve been helping out on some WMI and PowerShell issues in the forums at ScriptingAnswers.com. As I was working on a problem I ended up taking a slight detour to address an issue that has always bugged me. When I run a command like this: get-wmiobject -query &#8220;Select Name,Description,Disabled from Win32_UserAccount&#8221; PowerShell wants to return&#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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[75,8,19],"tags":[32,103,534],"class_list":["post-636","post","type-post","status-publish","format-standard","hentry","category-powershell-v2-0","category-scripting","category-wmi","tag-functions","tag-get-wmiobject","tag-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Select WMI &#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\/636\/select-wmi\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Select WMI &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I\u2019ve been helping out on some WMI and PowerShell issues in the forums at ScriptingAnswers.com. As I was working on a problem I ended up taking a slight detour to address an issue that has always bugged me. When I run a command like this: get-wmiobject -query &quot;Select Name,Description,Disabled from Win32_UserAccount&quot; PowerShell wants to return...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2010-05-13T14:16:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-03-15T14:33:08+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-300x89.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\\\/scripting\\\/636\\\/select-wmi\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/636\\\/select-wmi\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Select WMI\",\"datePublished\":\"2010-05-13T14:16:21+00:00\",\"dateModified\":\"2014-03-15T14:33:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/636\\\/select-wmi\\\/\"},\"wordCount\":243,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/636\\\/select-wmi\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2010\\\/05\\\/selectwmi-300x89.png\",\"keywords\":[\"functions\",\"Get-WMIObject\",\"PowerShell\"],\"articleSection\":[\"PowerShell v2.0\",\"Scripting\",\"WMI\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/636\\\/select-wmi\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/636\\\/select-wmi\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/636\\\/select-wmi\\\/\",\"name\":\"Select WMI &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/636\\\/select-wmi\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/636\\\/select-wmi\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2010\\\/05\\\/selectwmi-300x89.png\",\"datePublished\":\"2010-05-13T14:16:21+00:00\",\"dateModified\":\"2014-03-15T14:33:08+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/636\\\/select-wmi\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/636\\\/select-wmi\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/636\\\/select-wmi\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2010\\\/05\\\/selectwmi.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2010\\\/05\\\/selectwmi.png\",\"width\":800,\"height\":239},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/636\\\/select-wmi\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell v2.0\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell-v2-0\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Select WMI\"}]},{\"@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":"Select WMI &#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\/636\/select-wmi\/","og_locale":"en_US","og_type":"article","og_title":"Select WMI &#8226; The Lonely Administrator","og_description":"I\u2019ve been helping out on some WMI and PowerShell issues in the forums at ScriptingAnswers.com. As I was working on a problem I ended up taking a slight detour to address an issue that has always bugged me. When I run a command like this: get-wmiobject -query \"Select Name,Description,Disabled from Win32_UserAccount\" PowerShell wants to return...","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/","og_site_name":"The Lonely Administrator","article_published_time":"2010-05-13T14:16:21+00:00","article_modified_time":"2014-03-15T14:33:08+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-300x89.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\/scripting\/636\/select-wmi\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Select WMI","datePublished":"2010-05-13T14:16:21+00:00","dateModified":"2014-03-15T14:33:08+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/"},"wordCount":243,"commentCount":0,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-300x89.png","keywords":["functions","Get-WMIObject","PowerShell"],"articleSection":["PowerShell v2.0","Scripting","WMI"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/","name":"Select WMI &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi-300x89.png","datePublished":"2010-05-13T14:16:21+00:00","dateModified":"2014-03-15T14:33:08+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/05\/selectwmi.png","width":800,"height":239},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/636\/select-wmi\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell v2.0","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},{"@type":"ListItem","position":2,"name":"Select WMI"}]},{"@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":2241,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2241\/skipping-wmi-system-properties-in-powershell\/","url_meta":{"origin":636,"position":0},"title":"Skipping WMI System Properties in PowerShell","author":"Jeffery Hicks","date":"April 25, 2012","format":false,"excerpt":"One of my favorite techniques when using WMI in PowerShell is to pipe an object to Select-Object and select all properties. Try this: get-wmiobject win32_bios | select * It works, but it also gets all of the system properties like __PATH which I rarely care about. I also get other\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":1532,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/","url_meta":{"origin":636,"position":1},"title":"Get Local Administrators with WMI and PowerShell","author":"Jeffery Hicks","date":"July 1, 2011","format":false,"excerpt":"Earlier this week I was helping someone out on a problem working with the local administrators group. There are a variety of ways to enumerate the members of a local group. The code he was using involved WMI. I hadn't really worked with the WMI approach in any great detail\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":103,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/103\/more-with-process-and-service-uptime\/","url_meta":{"origin":636,"position":2},"title":"More with Process and Service uptime","author":"Jeffery Hicks","date":"February 20, 2007","format":false,"excerpt":"Like most things scripting, there's usually more than one way to do things. I thought I had a nice solution for getting service uptime via WMI. But alas, there is an even easier way. PowerShell has a ConvertToDateTime method which will convert a WMI time to a standard date time\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":100,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/100\/more-with-service-uptime\/","url_meta":{"origin":636,"position":3},"title":"More with Service Uptime","author":"Jeffery Hicks","date":"February 16, 2007","format":false,"excerpt":"I knew I wasn't totally satisfied with my recent attempt at listing service uptime. I knew there was a more elegant solution and here it is: $s=Get-WmiObject -query \"Select name,processId,state from Win32_service where state='running'\"foreach ($item in $s) {$p=(Get-Process | Where {$_.id -eq $item.ProcessID}).StartTime$u=(get-date).Subtract($p)Write-Host $item.Name `t $u.Days day $u.hours hours $u.minutes\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":1551,"url":"https:\/\/jdhitsolutions.com\/blog\/wmi\/1551\/find-non-system-service-accounts-with-powershell-and-wmi\/","url_meta":{"origin":636,"position":4},"title":"Find Non System Service Accounts with PowerShell and WMI","author":"Jeffery Hicks","date":"July 5, 2011","format":false,"excerpt":"As easy as Get-Service is to use in PowerShell, it has one limitation for IT Pros: it can't show you what account the service is running under. In old school terms, \"What is the service account?\" Fortunately you can get that information using WMI. Here's a query you can use\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":515,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/515\/find-that-service\/","url_meta":{"origin":636,"position":5},"title":"Find That Service","author":"Jeffery Hicks","date":"November 19, 2009","format":false,"excerpt":"Once again, the fine forum members at ScriptingAnswers.com come through and help get my PowerShell idea engine revving. The latest post posed this basic question: \u201cI need to query my servers and find all services using a specific service account.\u201d The poster thought this would be a good opportunity to\u2026","rel":"","context":"In &quot;CommandLine&quot;","block_context":{"text":"CommandLine","link":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/636","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=636"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/636\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=636"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}