{"id":5641,"date":"2015-06-10T00:01:00","date_gmt":"2015-06-10T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/06\/10\/help-it-says-run-a-powershell-script\/"},"modified":"2019-02-18T09:47:30","modified_gmt":"2019-02-18T16:47:30","slug":"help-it-says-run-a-powershell-script","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/help-it-says-run-a-powershell-script\/","title":{"rendered":"Help: It Says Run a PowerShell Script"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Ed Wilson, Microsoft Scripting Guy, talks about running a Windows PowerShell script.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Ninety two degrees Fahrenheit and sunny&mdash;that is what the weather is supposed to be this Saturday in Jacksonville when Teresa and I will be speaking at the <a href=\"http:\/\/www.itprocamp.com\/jacksonville2015\/\" target=\"_blank\">Jacksonville IT Pro Camp<\/a>.<\/p>\n<p>I can&rsquo;t think of a better way to spend a sunny day in Jacksonville, Florida than in a building with the air conditioning on high, and talking about the way cool stuff in Windows PowerShell. Well, maybe I could think of one or two other things to do, but certainly, IT Pro Camp is at the top of the list.<\/p>\n<h2>Is it a script?<\/h2>\n<p>A Windows PowerShell script is not a script until it is saved with a .ps1 file extension. So, if I copy a script directly from anywhere, and paste it into the Windows PowerShell ISE, <b>and I do not save it<\/b>, it is not a script.<\/p>\n<p>In the following image, I have copied a random script from the Script Center Repository. I pasted it into the Windows PowerShell ISE, but I have not saved it.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-6-10-15-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-6-10-15-01.png\" alt=\"Image of script\" title=\"Image of script\" \/><\/a><\/p>\n<p>I could run the script, modify the script, or whatever I want to do with it. But if the title pane says <b>Untitled*.ps1<\/b>, it is not actually a script. So regardless of the Windows PowerShell script execution policy, I can run a script here.<\/p>\n<h2>Script execution policies<\/h2>\n<p>When I first open Windows PowerShell on a client computer running Windows 7 or later, the script execution policy is set to <b>Restricted<\/b> (actually, this was also the case for Windows PowerShell&nbsp;1.0). On the server side of the house, beginning with Windows Server&nbsp;2008&nbsp;R2, the Windows PowerShell script execution policy was set to <b>Remote Signed<\/b>, which means that scripts downloaded from a remote location must be signed to run without prompting.<\/p>\n<p>I can see the script execution policy by using the <b>Get-ExecutionPolicy<\/b> cmdlet:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-ExecutionPolicy<\/p>\n<p style=\"margin-left:30px\">Unrestricted<\/p>\n<p>But there is more than one script execution policy. To see the value of all of the script execution policies, I use the <b>Get-ExecutionPolicy<\/b> cmdlet with the <b>&ndash;List<\/b> parameter. This is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-6-10-15-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-6-10-15-02.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>To change the script execution policy, I use <b>Set-ExecutionPolicy<\/b> cmdlet. If I want to change the script execution policy for only myself, I can use the <b>&ndash;Scope<\/b> and specify <b>CurrentUser<\/b>, for example:<\/p>\n<p style=\"margin-left:30px\">Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned<\/p>\n<p>When I run the <b>Set-ExecutionPolicy<\/b> cmdlet, the following prompt appears:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6242.hsg-6-10-15-03.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6242.hsg-6-10-15-03.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>To bypass this prompt, use the <b>&ndash;Force<\/b> parameter. The command is shown here:<\/p>\n<p style=\"margin-left:30px\">Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force<\/p>\n<h2>Script execution policy via Group Policy settings<\/h2>\n<p>If the network administrator sets a Windows PowerShell script execution policy with a Group Policy setting, I cannot change my local script execution policy&mdash;even to make it more restrictive. &nbsp;For example, if the network administrator set the script execution policy to <b>Remote Signed<\/b>, but I thought it would make more sense to set it to <b>All Signed<\/b>, I could not do that. This is why it is important to look at the results of <b>Get-ExecutionPolicy &ndash;List<\/b> when troubleshooting script execution in Windows PowerShell.<\/p>\n<p>If no policy is set via Group Policy (these are the <b>Computer Configuration&nbsp;<\/b>and the <b>User Configuration<\/b>&nbsp;settings), I can set a script execution policy for all users on a computer (<b>Local&nbsp;Computer&nbsp;<\/b>Group Policy setting) if I have local admin rights and if I open the Windows PowerShell console with elevated rights.<\/p>\n<p>I normally, do not do that however. Instead, I prefer to set the policy only for the current user (which is me), and I do not have to open the Windows PowerShell console with elevated rights to do that. I can do it in a non-elevated manner. I did this earlier when I set the <b>&ndash;Scope<\/b> for <b>CurrentUser<\/b>.<\/p>\n<p>If I need to run scripts, and I am running with non-elevated rights, and if a Group Policy setting has not disallowed me from running scripts, I can set my Windows PowerShell script execution policy easily. I just use <b>Set-ExecutionPolicy<\/b> and apply the appropriate policy to the <b>CurrentUser<\/b> scope.<\/p>\n<p>Of course, there are lots of caveats to consider, but this will get you up and running quickly.<\/p>\n<p>Windows PowerShell Fundamentals Week will continue tomorrow when I will talk about more cool stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><span style=\"font-size:12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Ed Wilson, Microsoft Scripting Guy, talks about running a Windows PowerShell script. Microsoft Scripting Guy, Ed Wilson, is here. Ninety two degrees Fahrenheit and sunny&mdash;that is what the weather is supposed to be this Saturday in Jacksonville when Teresa and I will be speaking at the Jacksonville IT Pro Camp. I can&rsquo;t think of [&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":[51,2,590,3,4,45],"class_list":["post-5641","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-running","tag-scripting","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Ed Wilson, Microsoft Scripting Guy, talks about running a Windows PowerShell script. Microsoft Scripting Guy, Ed Wilson, is here. Ninety two degrees Fahrenheit and sunny&mdash;that is what the weather is supposed to be this Saturday in Jacksonville when Teresa and I will be speaking at the Jacksonville IT Pro Camp. I can&rsquo;t think of [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/5641","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=5641"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/5641\/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=5641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=5641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=5641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}