{"id":1650,"date":"2010-03-29T23:17:17","date_gmt":"2010-03-30T07:17:17","guid":{"rendered":"http:\/\/www.bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/"},"modified":"2010-03-29T23:17:17","modified_gmt":"2010-03-30T07:17:17","slug":"script-to-enable-preview-pane-for-powershell-scripts","status":"publish","type":"post","link":"https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/","title":{"rendered":"Script to enable preview pane for PowerShell scripts"},"content":{"rendered":"<p>If you are running Windows 7, you probably know what preview pane is. And if you use PowerShell and create ps1 scripts, you may also wonder how can you enable preview for PowerShell scripts in Windows Explorer.<\/p>\n<p>Well, Nate Bruneau shared how to edit registry to enable preview for ps1 scripts. Being a scripter myself, I figured I would wrap it into a nice script and share it with everyone. Thanks Nate for your permission.<\/p>\n<p>The scrip runs on Windows 7 and Windows Server 2008 R2. You must run it from elevated PowerShell session. The script uses elevation code from <a href=\"http:\/\/www.interact-sw.co.uk\/iangblog\/2007\/02\/09\/pshdetectelevation\" target=\"_blank\" rel=\"noopener noreferrer\">Ian Griffiths\u2019 blog<\/a> to check for elevation and exits with notification if PowerShell is not running as administrator.<\/p>\n<p>Here\u2019s the script:<\/p>\n<pre class=\"brush: powershell; ruler: true; auto-links: true; toolbar: true\">#############################################################################\n# Enable-ps1Preview.ps1\n# This script will enable preview for ps1 files in Windows Explorer.\n# Special thanks to Nate Bruneau for the idea.\n#\n# Created by \n# Bhargav Shukla\n# http:\/\/www.bhargavs.com\n# \n# DISCLAIMER\n# ==========\n# THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE \n# RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.\n#############################################################################\n\n# Check if OS is Windows 7 or Windows Server 2008 R2, quit if not.\n$OS = (Get-WmiObject -Class win32_OperatingSystem).caption\nswitch -wildcard ($OS)\n{\n  &quot;*Windows 7*&quot; {&quot;`nChecking Elevation...&quot;}\n  &quot;*Windows Server 2008 R2*&quot; {&quot;`nChecking Elevation...&quot;}\n  default {Write-Host -ForegroundColor Red &quot;`nYou are not running Windows 7 or Windows Server 2008 R2. You can't use this feature on older OS.&quot;; exit}\n}\n\n# Function to check if PowerShell is running elevated\nfunction Check-Elevated\n{\n  $wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()\n  $prp=new-object System.Security.Principal.WindowsPrincipal($wid)\n  $adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator\n  $IsAdmin=$prp.IsInRole($adm)\n  if ($IsAdmin)\n  {\n    Set-Variable -Name elevated -Value $true -Scope 1\n  }\n}\n\n# Make registry changes if running elevated, throw error if not\nCheck-Elevated\nIf ($elevated -eq $true)\n{\n\t# Set Registry Key variables\n\t$REG_KEY = &quot;.ps1&quot;\n\t\t\t\n\t# Open remote registry\n\t$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('ClassesRoot', &quot;.&quot;)\n\t\n\t# Open the targeted remote registry key\/subkey as read\/write\n\t$regKey = $reg.OpenSubKey($REG_KEY,$true)\n\t\t\n\t# Set PerceivedType to &quot;text&quot;\n\tif ($regKey -ne $null)\n\t{\n\t\t$regKey.Setvalue('PerceivedType', 'text', 'String')\n\t\t$regKey.Setvalue('Content Type', 'text\/plain', 'String')\n\t\t\n\t\t# Close the Reg Key\n\t\t$regKey.Close()\n\t\n\t\tWrite-Host -ForegroundColor Green -BackgroundColor Black &quot;Preview for .ps1 files is now enabled. Enable preview pane in Windows Explorer.`n&quot;\n\t\t\t\n\t}\n\n}\nelse\n{\n  Write-Host -ForegroundColor Red -BackgroundColor Black &quot;Please run PowerShell as administrator before you run this script.`n&quot;\n}<\/pre>\n<p>You can download the script here \u2013 <a href=\"http:\/\/cid-14adc5cf1e0cbccf.skydrive.live.com\/self.aspx\/.Public\/Blog-Bhargavs\/Exchange\/Enable-ps1Preview.ps1\" target=\"_blank\" rel=\"noopener noreferrer\">Enable-ps1Preview.ps1<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are running Windows 7, you probably know what preview pane is. And if you use PowerShell and create ps1 scripts, you may also wonder how can you enable [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_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},"jetpack_post_was_ever_published":false},"categories":[19],"tags":[],"class_list":["post-1650","post","type-post","status-publish","format-standard","hentry","category-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Script to enable preview pane for PowerShell scripts - Bhargav&#039;s IT Playground<\/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:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Script to enable preview pane for PowerShell scripts - Bhargav&#039;s IT Playground\" \/>\n<meta property=\"og:description\" content=\"If you are running Windows 7, you probably know what preview pane is. And if you use PowerShell and create ps1 scripts, you may also wonder how can you enable [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/\" \/>\n<meta property=\"og:site_name\" content=\"Bhargav&#039;s IT Playground\" \/>\n<meta property=\"article:published_time\" content=\"2010-03-30T07:17:17+00:00\" \/>\n<meta name=\"author\" content=\"Bhargav\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bhargav\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/03\\\/29\\\/script-to-enable-preview-pane-for-powershell-scripts\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/03\\\/29\\\/script-to-enable-preview-pane-for-powershell-scripts\\\/\"},\"author\":{\"name\":\"Bhargav\",\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#\\\/schema\\\/person\\\/28f6d8c9b29f3a879483d65fc2ab5e26\"},\"headline\":\"Script to enable preview pane for PowerShell scripts\",\"datePublished\":\"2010-03-30T07:17:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/03\\\/29\\\/script-to-enable-preview-pane-for-powershell-scripts\\\/\"},\"wordCount\":136,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#\\\/schema\\\/person\\\/28f6d8c9b29f3a879483d65fc2ab5e26\"},\"articleSection\":[\"PowerShell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/03\\\/29\\\/script-to-enable-preview-pane-for-powershell-scripts\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/03\\\/29\\\/script-to-enable-preview-pane-for-powershell-scripts\\\/\",\"url\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/03\\\/29\\\/script-to-enable-preview-pane-for-powershell-scripts\\\/\",\"name\":\"Script to enable preview pane for PowerShell scripts - Bhargav&#039;s IT Playground\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#website\"},\"datePublished\":\"2010-03-30T07:17:17+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/03\\\/29\\\/script-to-enable-preview-pane-for-powershell-scripts\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/03\\\/29\\\/script-to-enable-preview-pane-for-powershell-scripts\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/03\\\/29\\\/script-to-enable-preview-pane-for-powershell-scripts\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/bhargavs.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Script to enable preview pane for PowerShell scripts\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#website\",\"url\":\"https:\\\/\\\/bhargavs.com\\\/\",\"name\":\"Bhargav's IT Playground\",\"description\":\"Passion for Technology. Power of Collaboration.\",\"publisher\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#\\\/schema\\\/person\\\/28f6d8c9b29f3a879483d65fc2ab5e26\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/bhargavs.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#\\\/schema\\\/person\\\/28f6d8c9b29f3a879483d65fc2ab5e26\",\"name\":\"Bhargav\",\"logo\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/bhargavs.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Script to enable preview pane for PowerShell scripts - Bhargav&#039;s IT Playground","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:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/","og_locale":"en_US","og_type":"article","og_title":"Script to enable preview pane for PowerShell scripts - Bhargav&#039;s IT Playground","og_description":"If you are running Windows 7, you probably know what preview pane is. And if you use PowerShell and create ps1 scripts, you may also wonder how can you enable [&hellip;]","og_url":"https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/","og_site_name":"Bhargav&#039;s IT Playground","article_published_time":"2010-03-30T07:17:17+00:00","author":"Bhargav","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Bhargav","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/#article","isPartOf":{"@id":"https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/"},"author":{"name":"Bhargav","@id":"https:\/\/bhargavs.com\/#\/schema\/person\/28f6d8c9b29f3a879483d65fc2ab5e26"},"headline":"Script to enable preview pane for PowerShell scripts","datePublished":"2010-03-30T07:17:17+00:00","mainEntityOfPage":{"@id":"https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/"},"wordCount":136,"commentCount":0,"publisher":{"@id":"https:\/\/bhargavs.com\/#\/schema\/person\/28f6d8c9b29f3a879483d65fc2ab5e26"},"articleSection":["PowerShell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/","url":"https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/","name":"Script to enable preview pane for PowerShell scripts - Bhargav&#039;s IT Playground","isPartOf":{"@id":"https:\/\/bhargavs.com\/#website"},"datePublished":"2010-03-30T07:17:17+00:00","breadcrumb":{"@id":"https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/bhargavs.com\/"},{"@type":"ListItem","position":2,"name":"Script to enable preview pane for PowerShell scripts"}]},{"@type":"WebSite","@id":"https:\/\/bhargavs.com\/#website","url":"https:\/\/bhargavs.com\/","name":"Bhargav's IT Playground","description":"Passion for Technology. Power of Collaboration.","publisher":{"@id":"https:\/\/bhargavs.com\/#\/schema\/person\/28f6d8c9b29f3a879483d65fc2ab5e26"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/bhargavs.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/bhargavs.com\/#\/schema\/person\/28f6d8c9b29f3a879483d65fc2ab5e26","name":"Bhargav","logo":{"@id":"https:\/\/bhargavs.com\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/bhargavs.com"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1632,"url":"https:\/\/bhargavs.com\/index.php\/2009\/08\/17\/exchange-2007-powershell-scripts\/","url_meta":{"origin":1650,"position":0},"title":"Exchange 2007 PowerShell Scripts \u2013 What would you like to script?","author":"Bhargav","date":"August 17, 2009","format":false,"excerpt":"I am always thinking about how can I script\/automate tasks I have to do repeatedly or I see others ask for. I would like to go a step beyond. I would like to ask you \u2013 the readers: If you would want to script something for your Exchange 2007 environment,\u2026","rel":"","context":"In &quot;Announcements&quot;","block_context":{"text":"Announcements","link":"https:\/\/bhargavs.com\/index.php\/category\/announcements\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1673,"url":"https:\/\/bhargavs.com\/index.php\/2011\/10\/21\/powershell-script-to-edit-remote-registry\/","url_meta":{"origin":1650,"position":1},"title":"PowerShell script to edit remote registry","author":"Bhargav","date":"October 21, 2011","format":false,"excerpt":"Did you ever wanted to modify your registry or add a key\/value pair to registry? Wished there was a script to help you do that? Even better, wished it can run remotely without PowerShell WinRM listener configured on target server? I had custom script that would modify certain registry entry\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/bhargavs.com\/index.php\/category\/microsoft\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1667,"url":"https:\/\/bhargavs.com\/index.php\/2011\/05\/23\/exchange-team-blog-mobile-and-powershell-error-handling\/","url_meta":{"origin":1650,"position":2},"title":"Exchange Team Blog Mobile and PowerShell Error Handling","author":"Bhargav","date":"May 23, 2011","format":false,"excerpt":"I admit the two topics don\u2019t have anything in common except both has something to do with me. That\u2019s why they are both being talked about in same post! So If you haven\u2019t caught up on this yet, I created a Windows Phone App for the Exchange Team Blog. I\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/bhargavs.com\/index.php\/category\/microsoft\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1660,"url":"https:\/\/bhargavs.com\/index.php\/2011\/04\/04\/how-do-i-measure-how-long-a-command-took-to-run-in-powershell\/","url_meta":{"origin":1650,"position":3},"title":"How do I measure how long a command took to run in PowerShell?","author":"Bhargav","date":"April 4, 2011","format":false,"excerpt":"So this one might be pretty simple you say, just use measure-command right? But what if I already ran the command and didn\u2019t time it? What if it took really long time and running it again isn\u2019t an option? This is when built-in history helps! If you run Get-History |\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/bhargavs.com\/index.php\/category\/microsoft\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":34526,"url":"https:\/\/bhargavs.com\/index.php\/2024\/01\/30\/clearing-microsoft-teams-cache-with-powershell\/","url_meta":{"origin":1650,"position":4},"title":"Clearing Microsoft Teams Cache with PowerShell","author":"Bhargav","date":"January 30, 2024","format":false,"excerpt":"Introduction I recently came across a need to clear Teams cache. While the task might be simple, I ended up spending a little more time to address the scenarios I can foresee so the PowerShell script is more useful that a single use case. In this blog post, we'll be\u2026","rel":"","context":"In &quot;General&quot;","block_context":{"text":"General","link":"https:\/\/bhargavs.com\/index.php\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1629,"url":"https:\/\/bhargavs.com\/index.php\/2009\/06\/16\/measure-powershell-script-run-time\/","url_meta":{"origin":1650,"position":5},"title":"Measure script run time","author":"Bhargav","date":"June 16, 2009","format":false,"excerpt":"When I am writing PowerShell scripts, one thing that is always in my mind: How long will it take to run this script and what can I do to reduce the run time. While optimizing the code itself is not the scope of this article, what I am going to\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/bhargavs.com\/index.php\/category\/microsoft\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_shortlink":"https:\/\/wp.me\/pkROc-qC","_links":{"self":[{"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/posts\/1650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/comments?post=1650"}],"version-history":[{"count":0,"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/posts\/1650\/revisions"}],"wp:attachment":[{"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/media?parent=1650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/categories?post=1650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/tags?post=1650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}