{"id":4751,"date":"2009-01-10T04:54:25","date_gmt":"2009-01-10T04:54:25","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2009\/01\/10\/get-usb-using-wmi-association-classes-in-powershell\/"},"modified":"2019-02-18T13:12:55","modified_gmt":"2019-02-18T20:12:55","slug":"get-usb-using-wmi-association-classes-in-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/get-usb-using-wmi-association-classes-in-powershell\/","title":{"rendered":"Get-USB &#8211; Using WMI Association Classes in PowerShell"},"content":{"rendered":"<p class=\"PostHeader\">Last Thursday, we had our first meeting of PowerShell Script Club on the Microsoft Campus. Script Clubs are really cool. They&#8217;re kind of like a hands on lab with no set topic or teacher. You bring an idea for a script, and ask your fellow PowerShell users about help getting the script written.&#160; Leave a comment if you\u2019d like to set up a local script club.<\/p>\n<p class=\"PostHeader\">One of the questions I helped answer involved using a <a href=\"http:\/\/www.microsoft.com\/resources\/documentation\/WindowsServ\/2003\/all\/ADS\/en-us\/node_api_associationclassdefinitions.mspx?mfr=true\">WMI association class<\/a>, which is a class in WMI that links two other classes together. Association classes are pretty common, and pretty useful, once you get the hang of them.<\/p>\n<p class=\"PostHeader\">One association class is <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394505(VS.85).aspx\">Win32_USBControllerDevice<\/a>. Here&#8217;s a quick function that resolves the association class and returns all USB devices from WMI. The function is one line, and the inline help is 8 lines.<\/p>\n<p>  <\/p>\n<p class=\"CmdletSynopsis\"><b>Synopsis:<\/b>     <\/p>\n<blockquote><p>Gets USB devices attached to the system <\/p><\/blockquote>\n<p>  <\/p>\n<p class=\"CmdletDescription\"><b>Detailed Description:<\/b>     <\/p>\n<blockquote><p>Uses WMI to get the USB Devices attached to the system <\/p><\/blockquote>\n<p>  <\/p>\n<p class=\"Examples\"><strong>Examples<\/strong>: <\/p>\n<blockquote>\n<pre class=\"CmdletExample\">    -------------------------- EXAMPLE 1 --------------------------\nGet-USB    <\/pre>\n<\/blockquote>\n<blockquote>\n<pre class=\"CmdletExample\">    -------------------------- EXAMPLE 2 --------------------------\nGet-USB | Group-Object Manufacturer<br \/><\/pre>\n<\/blockquote>\n<p>Here&#8217;s Get-USB: <i><\/i><\/p>\n<blockquote>\n<pre class=\"CmdletDefinition\">function Get-USB {\n    #.Synopsis\n    #    Gets USB devices attached to the system\n    #.Description\n    #    Uses WMI to get the USB Devices attached to the system\n    #.Example\n    #    Get-USB\n    #.Example\n    #    Get-USB | Group-Object Manufacturer\n    Get-WmiObject Win32_USBControllerDevice | Foreach-Object { [Wmi]$_.Dependent }\n}\n    <\/pre>\n<\/blockquote>\n<\/p>\n<p><\/p>\n<p class=\"Postfooter\">Hope this Helps,<\/p>\n<p class=\"Postfooter\">James Brundage [MSFT]<\/p>\n<p style=\"font-size: xx-small\">Automatically generated with <a href=\"http:\/\/blogs.msdn.com\/powershell\/archive\/tags\/Write-CommandBlogPost\/default.aspx\">Write-CommandBlogPost<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last Thursday, we had our first meeting of PowerShell Script Club on the Microsoft Campus. Script Clubs are really cool. They&#8217;re kind of like a hands on lab with no set topic or teacher. You bring an idea for a script, and ask your fellow PowerShell users about help getting the script written.&#160; Leave a [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-4751","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>Last Thursday, we had our first meeting of PowerShell Script Club on the Microsoft Campus. Script Clubs are really cool. They&#8217;re kind of like a hands on lab with no set topic or teacher. You bring an idea for a script, and ask your fellow PowerShell users about help getting the script written.&#160; Leave a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=4751"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4751\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=4751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=4751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=4751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}