{"id":16011,"date":"2011-01-04T00:01:00","date_gmt":"2011-01-04T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/01\/04\/run-powershell-scripts-stored-on-a-central-file-share\/"},"modified":"2011-01-04T00:01:00","modified_gmt":"2011-01-04T00:01:00","slug":"run-powershell-scripts-stored-on-a-central-file-share","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/run-powershell-scripts-stored-on-a-central-file-share\/","title":{"rendered":"Run PowerShell Scripts Stored on a Central File Share"},"content":{"rendered":"<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><b><span style=\"font-size:10.0pt\">Summary:<\/span><\/b><span style=\"font-size:10.0pt\"> Learn about Windows PowerShell Script Execution policies and how they effect running scripts from a central file share.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" \/><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>Hey, Scripting Guy! I am curious as to the best place to store scripts. I want to maintain a master list of approved scripts, but I am not certain as to the best way to do this. I am wondering if a simple file share inside the network will be sufficient for my purposes. What do you think? Will a file share work for sharing scripts inside the network?<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&#8212; SG<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" \/><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>Hello SG, Microsoft Scripting Guy Ed Wilson here. When it is 31 degrees Fahrenheit outside (-0.5 degrees Celsius) the <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/scripting+wife\/\">Scripting Wife<\/a> begins to whine that it is cold. In fact, she interrupted me last night while I was reading a novel by <a href=\"http:\/\/en.wikipedia.org\/wiki\/Dorothy_L._Sayers\">Dorothy Sayers<\/a> that I picked up at the public library over the weekend, to &ldquo;come look at the snow.&rdquo; Seeing our <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2010\/02\/06\/hey-scripting-guy-february-6-2010.aspx\">snowfall<\/a> last night was somewhat of a trick. First, I had to turn on the outside light. Next, I had to stand in a certain position and gaze up toward the moon. If I held my head real still, I could see a few flakes as they tumbled to earth. There was no accumulation. In fact, I believe that the flakes were doomed to revert to raindrops before even touching the ground. But it was a nice treat to see the snow. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">Anyway, as I started to say, the Scripting Wife began to whine. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&ldquo;It is cold. See it is snowing. I want to go to <a href=\"http:\/\/encarta.msn.com\/encyclopedia_761576662\/Hawaii_(island).html\">Hawaii<\/a>,&rdquo; she said.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&ldquo;I want to go to Hawaii too, but I am not allowed to fly,&rdquo; I replied.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&ldquo;So I will go by myself to help out at <a href=\"http:\/\/www.sqlsaturday.com\/\">SQL Saturday<\/a> in Honolulu,&rdquo; she threatened. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">I pulled up a picture I had taken during our last trip to Honolulu to teach a Windows PowerShell class. Warm aqua water, deep sapphire blue skies, and snowflake white beaches peer playfully in the distance behind my favorite tree, the palm tree. This idyllic scene appears in the following figure.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7288.HSG-01-04-11-01.jpg\" border=\"0\" \/><\/span><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&ldquo;Hmmm &hellip;,&rdquo; I uttered, &ldquo;if I am still unable to fly when SQL Saturday rolls around, why don&rsquo;t you go ahead and pop out there. You can bring me back some <a href=\"http:\/\/en.wikipedia.org\/wiki\/Kona_coffee\">Kona coffee<\/a>, a box of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Chocolate\">chocolate<\/a> covered Macadamia nuts, and a Sugar Loaf Pineapple.&rdquo;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">Speaking of things that are sweet, SG, you can indeed store your scripts on a centralized network share. In fact, I do this very thing because it provides quick access to the scripts I use for both client and server deployment. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">Of course, accessing scripts from a remote share could cause you to have problems with the script execution policy. In fact, running scripts in and of themselves can sometimes cause problems with the script execution policy. For more information, see &ldquo;<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/04\/18\/hey-scripting-guy-april-18-2010.aspx\">The Scripting Wife Sets the Script Execution Policy<\/a>&rdquo; Hey, Scripting Guy! Blog post. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">By default, when <a href=\"http:\/\/www.microsoft.com\/windows\/windows-7\/default.aspx\">Windows 7<\/a> is installed, or when Windows PowerShell is installed, the script execution policy is set to <i>restricted<\/i>. You can use the <b>Get-ExecutionPolicy<\/b> Windows PowerShell cmdlet to verify the setting of the Windows PowerShell execution policy. This is seen here.<\/span><\/p>\n<blockquote>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">PS C:\\&gt; Get-ExecutionPolicy<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Restricted<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">PS C:\\&gt;<\/span><\/span><\/p>\n<\/blockquote>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">When the script execution policy is set to <i>restricted<\/i> no Windows PowerShell scripts will run. It does not matter if the script resides on a remote server in a file share, or if the script is located in a local folder. This is seen in the following figure.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6320.HSG-1-4-10-02.jpg\" border=\"0\" \/><\/span><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">If you only want to run a script from a remote share without modifying the default script execution policy, you can use the <i>bypass<\/i> switch when launching Windows PowerShell. You can specify the path to the script by using the <i>file<\/i> parameter. This is seen in the following figure.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2273.HSG-1-4-10-03.jpg\" border=\"0\" \/><\/span><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">You can also open up a Windows PowerShell console with the bypass policy set by using the following command to launch Windows PowerShell.<\/span><\/p>\n<blockquote>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">powershell -executionpolicy bypass<\/span><\/span><\/p>\n<\/blockquote>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">After you have a Windows PowerShell console that is running in bypass mode for the execution policy, you can run the remote script. This seen here.<\/span><\/p>\n<blockquote>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">PS C:\\Users\\ed.NWTRADERS&gt; \\\\hyperv-box\\shared\\bios.ps1<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">SMBIOSBIOSVersion : A06<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Manufacturer<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: Dell Inc.<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: Phoenix ROM BIOS PLUS Version 1.10 A06<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">SerialNumber<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: BDY91L1<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Version<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: DELL<span>&nbsp;&nbsp; <\/span>&#8211; 15<\/span><\/span><\/p>\n<\/blockquote>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">To modify the Windows PowerShell script execution policy, use the <b>Set-ExecutionPolicy<\/b> Windows PowerShell cmdlet and specify the desired new level. This command must be launched as an Administrator. On Windows Vista or later, this means right-clicking on the Windows PowerShell console, and selecting <b>Run As Administrator<\/b> from the action menu. On earlier versions of Windows it means using the <b>RunAs<\/b> command to run with different credentials. If you try to use the <b>Set-ExecutionPolicy<\/b> cmdlet without admin rights, an error will be displayed. This is seen in the following figure.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2364.HSG-1-4-10-04.jpg\" border=\"0\" \/><\/span><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">In an enterprise setting, <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/windows+powershell\/group+policy\/\">Group Policy<\/a> should be used to control the Script Execution policy. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">Interestingly, admin rights are not required to launch PowerShell in bypass mode. Remember, the script execution policy is not a Security feature. It is a convenience feature. In a car, a seat belt actually protects you, and is therefore a security feature. The beeper that annoys you until you put the seat belt on is a convenience feature (i.e., it does not actually protect you). Because Windows PowerShell is simply an application such as Microsoft Word or even Solitaire, the user has the rights to launch and to use Windows PowerShell. If you want to restrict it from users, then you should use software restriction policies. But keep in mind, that would preclude you from using Windows PowerShell for your logon scripts and for many other administrative purposes. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">To set the execution policy to require digital signatures if the script comes from a remote location, set the execution policy to <b>remotesigned<\/b>. The command is seen here.<\/span><\/p>\n<blockquote>\n<p class=\"CodeBlock\" style=\"margin-left:1.0in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Set-ExecutionPolicy remotesigned<\/span><\/span><\/p>\n<\/blockquote>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">When setting the script execution policy, I generally first see what it is, then set the policy, and then check again to make sure that I have properly set the policy. This is seen in the following figure.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6378.HSG-1-4-10-05.jpg\" border=\"0\" \/><\/span><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">After I have made the change, I immediately close the Windows PowerShell console, and open up a non-elevated Windows PowerShell console. If I try to launch a script that comes from a remote location that is not digitally signed, the error seen in the following figure appears. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4263.HSG-1-4-10-06.jpg\" border=\"0\" \/><\/span><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">The error seen in this figure is because the script was downloaded from the Internet. The file itself has the <b>block<\/b> property set. To unblock the script, right-click the script, click <b>Properties<\/b> and then click the unblock button as seen in the following figure. After the script is unblocked, it will run without any problems. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8814.HSG-1-4-10-07.jpg\" border=\"0\" \/><\/span><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">Be aware you should first examine a script to make sure that you know what it actually does! In addition, testing scripts in a Virtual Machine is a great practice to enter. Scripts that are copied from the Scripting Guys Script Repository will not be blocked (as of this writing) because you do not actually download the script. You copy it to the clipboard, and then paste it into your script editor. This makes Windows PowerShell think the script was locally generated. Therefore, it will not be blocked. As with any other script, you should also ensure you know what scripts downloaded from the Scripting Guys Script Repository do also. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">What about scripts that reside on a file share inside the network? On my computer they run just fine. Keep in mind, that Windows PowerShell honors the Internet Explorer Security Zones. Therefore it depends on which security zone your intranet servers live in. The Internet Explorer Security Zones can be configured through Group Policy. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">SG, that is all there is to using a file share to store Windows PowerShell scripts. Script location week will continue tomorrow when I will talk about modules. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a target=\"_blank\" href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a> or post them on the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><b><span style=\"font-size:10.0pt\">Ed Wilson, Microsoft Scripting Guy<\/span><\/b><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp; Summary: Learn about Windows PowerShell Script Execution policies and how they effect running scripts from a central file share. &nbsp; Hey, Scripting Guy! I am curious as to the best place to store scripts. I want to maintain a master list of approved scripts, but I am not certain as to the best way [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[51,3,4,45],"class_list":["post-16011","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp;&nbsp; Summary: Learn about Windows PowerShell Script Execution policies and how they effect running scripts from a central file share. &nbsp; Hey, Scripting Guy! I am curious as to the best place to store scripts. I want to maintain a master list of approved scripts, but I am not certain as to the best way [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16011","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=16011"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16011\/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=16011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=16011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=16011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}