{"id":822,"date":"2009-02-01T17:07:45","date_gmt":"2009-02-02T01:07:45","guid":{"rendered":"https:\/\/www.zubairalexander.com\/stage\/?p=822"},"modified":"2009-02-01T17:16:41","modified_gmt":"2009-02-02T01:16:41","slug":"unable-to-execute-powershell-scripts-on-windows-server-2008","status":"publish","type":"post","link":"https:\/\/www.zubairalexander.com\/blog\/unable-to-execute-powershell-scripts-on-windows-server-2008\/","title":{"rendered":"Unable to Execute PowerShell Scripts on Windows Server 2008"},"content":{"rendered":"<p>Have you run into a situation where you try to execute a\u00a0 wonderful PowerShell script that you found on the Internet and instead of executing the script you end up getting a Notepad window that opens up your script? As a workaround you open Windows\u00a0PowerShell\u00a0and\u00a0run the script and what you get is rather bizarre. You get an error that says that scripting is disabled on your server. Hmmmm! who did that without your permission? The error says something like:<\/p>\n<p><span style=\"color: #ff0000;\">File C:\\scripts\\test.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see &#8220;get-<br \/>\nhelp about_signing&#8221; for more details.<br \/>\nAt line:1 char:19<br \/>\n+ c:\\scripts\\test.ps1 &lt;&lt;&lt;&lt;<\/span><\/p>\n<p>Well, there are a couple of things to know about PowerShell before you start executing PowerShell scripts.<\/p>\n<p><span style=\"color: #000000;\">1. PowerShell is available in Windows Server 2008 as a feature. To install PowerShell, start\u00a0the Server Manager. go to Features, Add features,\u00a0check the Windows PowerShell box and click Install.<\/span><\/p>\n<p><span style=\"color: #000000;\">2. Just because you&#8217;ve installed PowerShell it doesn&#8217;t mean that you can execute scripts. Scripts can be dangerous, especially when they are allowed to run on a server. The ability to &#8220;execute&#8221; PowerShell scripts is disabled by default in Windows Server 2008. You can allow the execution by using the ExecutionPolicy option.<\/span><\/p>\n<p>To view your current PowerShell Excecution Policy status, open the PowerShell console and type:<\/p>\n<p><span style=\"color: #800000;\"><strong><span style=\"color: #008000;\">Get-ExecutionPolicy<\/span><\/strong><\/span><\/p>\n<p>The response you will see is &#8220;Restricted&#8221;, which is the default status. You can change the status to\u00a0AllSigned, RemoteSigned, or Unrestricted.<\/p>\n<p><strong>Restricted<\/strong>: This default setting does not allow execution of scripts at all.<\/p>\n<p><strong>AllSigned<\/strong>: Allows you to\u00a0only execute digitally signed scripts. This is the most secure, other than Restricted setting.<\/p>\n<p><strong>RemoteSigned<\/strong>: Scripts downloaded from a remote site must be digitally signed before they can be executed. This is a good setting to have for a lot of environments.<\/p>\n<p><strong>Unrestricted<\/strong>: All scripts can be executed but technically this isn&#8217;t what I consider a fully\u00a0unrestricted setting in the sense that downloaded scripts will still offer user a prompt before executing. This should be used in rare situations and is not the recommended setting.<\/p>\n<p>To change the default\u00a0ExecutionPolicy, run the PowerShell as an administrator and type the appropriate command. For example, to change the Execution Policy to RemoteSigned, type:<\/p>\n<p><span style=\"color: #0000ff;\"><strong><span style=\"color: #008000;\">Set-ExecutionPolicy RemoteSigned<\/span><\/strong><\/span><\/p>\n<p>To switch it back to default Restricted setting, type:<\/p>\n<p><span style=\"color: #008000;\"><strong>Set-ExecutionPolicy Unrestricted<\/strong><\/span><\/p>\n<p>Always verify by running <em>Get-ExecutionPolicy<\/em> to ensure that you have configured the proper settings.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you run into a situation where you try to execute a\u00a0 wonderful PowerShell script that you found on the Internet and instead of executing the script you end up getting a Notepad window that opens up your script? As a workaround you open Windows\u00a0PowerShell\u00a0and\u00a0run the script and what you get is rather bizarre. You [&hellip;]<\/p>\n","protected":false},"author":7,"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,"footnotes":""},"categories":[57,11,30],"tags":[],"class_list":["post-822","post","type-post","status-publish","format-standard","hentry","category-scripting","category-tips-tricks","category-longhorn-server"],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.zubairalexander.com\/blog\/wp-json\/wp\/v2\/posts\/822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zubairalexander.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zubairalexander.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zubairalexander.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zubairalexander.com\/blog\/wp-json\/wp\/v2\/comments?post=822"}],"version-history":[{"count":0,"href":"https:\/\/www.zubairalexander.com\/blog\/wp-json\/wp\/v2\/posts\/822\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zubairalexander.com\/blog\/wp-json\/wp\/v2\/media?parent=822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zubairalexander.com\/blog\/wp-json\/wp\/v2\/categories?post=822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zubairalexander.com\/blog\/wp-json\/wp\/v2\/tags?post=822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}