{"id":4321,"date":"2009-03-20T18:24:59","date_gmt":"2009-03-20T18:24:59","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2009\/03\/20\/get-progid\/"},"modified":"2019-02-18T13:12:45","modified_gmt":"2019-02-18T20:12:45","slug":"get-progid","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/get-progid\/","title":{"rendered":"Get-ProgID"},"content":{"rendered":"<p>The other day, a friend over in Microsoft Research wanted to figure out how to get out the width and height of an image in PowerShell.&#160; There are many ways that you can approach this particular problem.&#160; I knew three right off of the top of my head, but none of them had a really optimal experience.<\/p>\n<ul>\n<li>I could use <a href=\"http:\/\/blogs.msdn.com\/mediaandmicrocode\/archive\/2008\/07\/13\/microcode-windows-powershell-windows-desktop-search-problem-solving.aspx\">Windows Desktop Search<\/a>, but then I\u2019d have to wade through shell properties and it would not work when the images haven\u2019t been indexed. <\/li>\n<li>I could use Windows Media Player (New-Object \u2013ComObject WMPlayer.OCX), but I\u2019d also have to wade through a lot of metadata information that\u2019s indexed by #, so this wouldn\u2019t be ideal. <\/li>\n<li>I could use the <a href=\"http:\/\/blogs.technet.com\/jamesone\/archive\/2008\/12\/09\/borrowing-from-windows-explorer-in-powershell-part-2-extended-properties.aspx\">Shell Properties<\/a>, but this too would involve a lot of translating property numbers into property names. <\/li>\n<\/ul>\n<p>I knew there had to be a better way.&#160; Some object had to be able to give me back image width and height as a nice simple property.<\/p>\n<p>I normally use two functions to find my way around unfamiliar problems (before I start using search engines).&#160; One I\u2019ve shared out a few times is called <a href=\"http:\/\/blogs.msdn.com\/mediaandmicrocode\/archive\/2008\/10\/23\/microcode-powershell-scripting-tricks-exploring-net-types-with-a-get-type-function-and-reflection.aspx\">Get-Type<\/a>.&#160; Get-Type will search anything loaded in .NET for a potential solution.&#160; The problem with Get-Type is that not every type .NET has is always loaded, and loading up these types is fairly expensive.&#160; COM objects, however, are listed in the registry.&#160; Since we can crawl the registry in PowerShell, it\u2019s simple enough to go ahead and check through all of the ProgIDs.<\/p>\n<p>Here&#8217;s my Get-ProgID function.&#160; The second example is how I found some cool image manipulation objects I can use from PowerShell.<\/p>\n<pre class=\"PowerShellColorizedScript\"><span style=\"color: #00008b\">function<\/span> <span style=\"color: #8a2be2\">Get-ProgID<\/span> <span style=\"color: #000000\">{<\/span>\n    <span style=\"color: #006400\">#.Synopsis<\/span>\n    <span style=\"color: #006400\">#   Gets all of the ProgIDs registered on a system<\/span>\n    <span style=\"color: #006400\">#.Description<\/span>\n    <span style=\"color: #006400\">#   Gets all ProgIDs registered on the system.  The ProgIDs returned can be used with New-Object -comObject<\/span>\n    <span style=\"color: #006400\">#.Example<\/span>\n    <span style=\"color: #006400\">#   Get-ProgID<\/span>\n    <span style=\"color: #006400\">#.Example<\/span>\n    <span style=\"color: #006400\">#   Get-ProgID | Where-Object { $_.ProgID -like &quot;*Image*&quot; } <\/span>\n    <span style=\"color: #00008b\">param<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #000000\">)<\/span>\n    <span style=\"color: #ff4500\">$paths<\/span> <span style=\"color: #a9a9a9\">=<\/span> <span style=\"color: #000000\">@(<\/span><span style=\"color: #8b0000\">&quot;REGISTRY::HKEY_CLASSES_ROOT\\CLSID&quot;<\/span><span style=\"color: #000000\">)<\/span>\n    <span style=\"color: #00008b\">if<\/span> <span style=\"color: #000000\">(<\/span><span style=\"color: #ff4500\">$env:Processor_Architecture<\/span> <span style=\"color: #a9a9a9\">-eq<\/span> <span style=\"color: #8b0000\">&quot;amd64&quot;<\/span><span style=\"color: #000000\">)<\/span> <span style=\"color: #000000\">{<\/span>\n        <span style=\"color: #ff4500\">$paths<\/span><span style=\"color: #a9a9a9\">+=<\/span><span style=\"color: #8b0000\">&quot;REGISTRY::HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID&quot;<\/span>\n    <span style=\"color: #000000\">}<\/span>\n    <span style=\"color: #0000ff\">Get-ChildItem<\/span> <span style=\"color: #ff4500\">$paths<\/span> <span style=\"color: #000080\">-include<\/span> <span style=\"color: #8a2be2\">VersionIndependentPROGID<\/span> <span style=\"color: #000080\">-recurse<\/span> <span style=\"color: #a9a9a9\">|<\/span>\n    <span style=\"color: #0000ff\">Select-Object<\/span> <span style=\"color: #000000\">@{<\/span>\n        <span style=\"color: #000000\">Name<\/span><span style=\"color: #a9a9a9\">=<\/span><span style=\"color: #8b0000\">'ProgID'<\/span>\n        <span style=\"color: #000000\">Expression<\/span><span style=\"color: #a9a9a9\">=<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #ff4500\">$_<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">GetValue<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #8b0000\">&quot;&quot;<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #000000\">}<\/span>\n    <span style=\"color: #000000\">}<\/span><span style=\"color: #a9a9a9\">,<\/span> <span style=\"color: #000000\">@{<\/span>\n        <span style=\"color: #000000\">Name<\/span><span style=\"color: #a9a9a9\">=<\/span><span style=\"color: #8b0000\">'32Bit'<\/span>\n        <span style=\"color: #000000\">Expression<\/span><span style=\"color: #a9a9a9\">=<\/span><span style=\"color: #000000\">{<\/span>\n            <span style=\"color: #00008b\">if<\/span> <span style=\"color: #000000\">(<\/span><span style=\"color: #ff4500\">$env:Processor_Architecture<\/span> <span style=\"color: #a9a9a9\">-eq<\/span> <span style=\"color: #8b0000\">&quot;amd64&quot;<\/span><span style=\"color: #000000\">)<\/span> <span style=\"color: #000000\">{<\/span>\n                <span style=\"color: #ff4500\">$_<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">PSPath<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">Contains<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #8b0000\">&quot;Wow6432Node&quot;<\/span><span style=\"color: #000000\">)<\/span>\n            <span style=\"color: #000000\">}<\/span> <span style=\"color: #00008b\">else<\/span> <span style=\"color: #000000\">{<\/span>\n                <span style=\"color: #ff4500\">$true<\/span>\n            <span style=\"color: #000000\">}<\/span>\n        <span style=\"color: #000000\">}<\/span>\n    <span style=\"color: #000000\">}<\/span>\n<span style=\"color: #000000\">}<\/span><\/pre>\n<p>Hope this Helps,<\/p>\n<p>James Brundage [MSFT]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The other day, a friend over in Microsoft Research wanted to figure out how to get out the width and height of an image in PowerShell.&#160; There are many ways that you can approach this particular problem.&#160; I knew three right off of the top of my head, but none of them had a really [&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":[],"class_list":["post-4321","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>The other day, a friend over in Microsoft Research wanted to figure out how to get out the width and height of an image in PowerShell.&#160; There are many ways that you can approach this particular problem.&#160; I knew three right off of the top of my head, but none of them had a really [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4321","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=4321"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4321\/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=4321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=4321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=4321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}