{"id":85947,"date":"2004-09-28T05:44:17","date_gmt":"2004-09-28T13:44:17","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/scripting\/?p=85947"},"modified":"2019-06-05T05:52:11","modified_gmt":"2019-06-05T13:52:11","slug":"how-can-i-get-a-list-of-the-devices-that-arent-working","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-get-a-list-of-the-devices-that-arent-working\/","title":{"rendered":"How Can I Get a List of the Devices That Aren&#8217;t Working?"},"content":{"rendered":"<p><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\" \/><\/p>\n<p>Hey, Scripting Guy! In Device Manager, any time a device isn\u2019t working that device is marked with a yellow exclamation mark. How can I use a script to get a list of the devices that aren\u2019t working?<\/p>\n<p>&#8212; OL<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\" \/><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\" \/><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\" \/><\/a><\/p>\n<p>Hey, OL. Sometimes in baseball a batter absolutely hammers one, but the ball takes a lucky bounce and lands right in your glove. That\u2019s often referred to as a \u201ccandy hop.\u201d Turns out that this question is the scripting equivalent of a candy hop: it looks like it might be a tough one to answer, but it turns out to be pretty easy.<\/p>\n<p>WMI actually has a class &#8211; Win32_PNPEntity &#8211; that returns information about the devices found in Device Manager. Meanwhile, Win32_PNPEntity has a property &#8211; ConfigManagerErrorCode &#8211; that tells you whether or not the device is working properly. If the value of ConfigManagerErrorCode is 0, then the device appears to be working. If ConfigManagerErrorCode is anything <i>but <\/i>0, then something must be wrong. And here\u2019s the good part: any device with a ConfigManagerErrorCode value other than 0 will also have a little yellow exclamation mark next to it in Device Manager.<\/p>\n<p>In other words, to write a script that returns a list of the devices that aren\u2019t working properly we just need to connect to the Win32_PNPEntity class and query for all devices with a ConfigManagerErrrorCode other than 0:<\/p>\n<pre class=\"codeSample\">strComputer = \".\"<\/pre>\n<p>Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colItems = objWMIService.ExecQuery _\n(&#8220;Select * from Win32_PNPEntity Where ConfigManagerErrorCode &lt;&gt; 0&#8221;)<\/p>\n<p>For Each objItem in colItems\nWscript.Echo &#8220;Name: &#8221; &amp; objItem.Name\nNext<\/p>\n<p>And what if you\u2019d like more detailed information about all the devices installed on a computer? Well, because this question turned out to be an easy one to answer, we\u2019re feeling generous: here\u2019s a bonus script that returns all sorts of data about installed devices:<\/p>\n<pre class=\"codeSample\">strComputer = \".\"\r\nSet objWMIService = GetObject(\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\cimv2\")\r\nSet colItems = objWMIService.ExecQuery(\"Select * from Win32_PnPEntity\")\r\nFor Each objItem in colItems\r\n    Wscript.Echo \"Class GUID: \" &amp; objItem.ClassGuid\r\n    Wscript.Echo \"Device is Working: \" &amp; objItem.ConfigManagerErrorCode\r\n    Wscript.Echo \"Description: \" &amp; objItem.Description\r\n    Wscript.Echo \"Device ID: \" &amp; objItem.DeviceID\r\n    Wscript.Echo \"Manufacturer: \" &amp; objItem.Manufacturer\r\n    Wscript.Echo \"Name: \" &amp; objItem.Name\r\n    Wscript.Echo \"PNP Device ID: \" &amp; objItem.PNPDeviceID\r\n    Wscript.Echo \"Service: \" &amp; objItem.Service\r\nNext\r\n<\/pre>\n<p>No, no charge for the bonus script. That one is on us!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! In Device Manager, any time a device isn\u2019t working that device is marked with a yellow exclamation mark. How can I use a script to get a list of the devices that aren\u2019t working? &#8212; OL Hey, OL. Sometimes in baseball a batter absolutely hammers one, but the ball takes a lucky [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-85947","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! In Device Manager, any time a device isn\u2019t working that device is marked with a yellow exclamation mark. How can I use a script to get a list of the devices that aren\u2019t working? &#8212; OL Hey, OL. Sometimes in baseball a batter absolutely hammers one, but the ball takes a lucky [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/85947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=85947"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/85947\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=85947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=85947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=85947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}