{"id":3064,"date":"2013-08-11T00:01:00","date_gmt":"2013-08-11T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/08\/11\/weekend-scripter-run-powershell-scripts-from-remote-file-share-part-3\/"},"modified":"2013-08-11T00:01:00","modified_gmt":"2013-08-11T00:01:00","slug":"weekend-scripter-run-powershell-scripts-from-remote-file-share-part-3","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-run-powershell-scripts-from-remote-file-share-part-3\/","title":{"rendered":"Weekend Scripter: Run PowerShell Scripts from Remote File Share: Part 3"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary<\/strong><span style=\"font-size: 12px\">: Microsoft Scripting Guy, Ed Wilson, continues his discussion about running scripts from a remote file share.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Some things should just be easier. For example, I should have access to client-side cmdlets to work with SharePoint. Many times, as a user, I need to accomplish repetitive tasks, and a few cmdlets could really come in handy. Running scripts from remote file shares should be easier as well.<\/p>\n<p>Easier? What am I talking about? Well when someone asks a question, there are so many &ldquo;it depends,&rdquo; &ldquo;maybe,&rdquo; and &ldquo;whatever&rdquo; stuff going on that it really makes what should be easy very complicated. For example, in a freshly created Windows Server&nbsp;2012 forest, I created a share on the domain controller. I modified the script execution policy on the client, and I could run scripts from the share just fine. No configuration, no signing, no nothing. It just worked. But to make a proclamation would take hours of testing in all different sorts of variables.<\/p>\n<h2>The easy way to run a script<\/h2>\n<p style=\"padding-left: 30px\"><strong>Note&nbsp;&nbsp;<\/strong>This is the third in a multipart series of posts. The first post was <a href=\"http:\/\/blogs.technet.com\/controlpanel\/blogs\/posteditor.aspx?SelectedNavItem=Posts&amp;WeblogID=7618&amp;WeblogPostID=3589344\" target=\"_blank\">Running Scripts from a Remote File Share<\/a>.<em> <\/em>The second post was <a href=\"https:\/\/microsoft.sharepoint.com\/teams\/HeyScriptingGuy\/_layouts\/15\/start.aspx#\/Shared%20Documents\/Forms\/AllItems.aspx?RootFolder=%2Fteams%2FHeyScriptingGuy%2FShared%20Documents%2F2013%2Fh%5FAugust%5F2013%2F08122013&amp;FolderCTID=0x012000B9284987DE5F47439BA6992CE6CB7AB8&amp;View=%7B5http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/08\/10\/weekend-scripter-run-powershell-scripts-from-remote-file-share-part-2.aspx\" target=\"_blank\">Weekend Scripter: Run PowerShell Scripts from Remote File Share: Part 2<\/a>. For good background info about running Windows PowerShell scripts from a remote file share, check out the guest blog post written by June Blender and Judith Herman: <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/10\/29\/how-to-run-powershell-scripts-from-a-shared-directory.aspx\" target=\"_blank\">How to Run PowerShell Scripts from a Shared Directory<\/a><em>.<\/em><\/p>\n<p>The easy way to run a script from a remote file share is to use the <strong>Bypass<\/strong><em> <\/em>methodology. This is not a security hole, because the script execution policy and the associated settings are not really security features&mdash;they are a security convenience. This means that they are in place to remind me to do the right thing&mdash;to encourage me to follow best practices. But they are not put in place to discourage getting the job done.<\/p>\n<p>So, all the discussion about the script execution policy and signed scripts can be bypassed if I need to do so. What is a common requirement? Well, running a script from a scheduled task, or from within a Group Policy Object. If the desktop and network configuration are complicated to the point of not knowing what will go on, I can use <strong>Bypass<\/strong><em> <\/em>mode<em> <\/em>and still get my scripts to run.<\/p>\n<p>To illustrate this point, I change my script execution policy to <strong>Restricted<\/strong>. This is the way it comes out of the box. Scripts do not run.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2146.wes-8-11-13-01.png\"><img decoding=\"async\" title=\"Image of error message\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2146.wes-8-11-13-01.png\" alt=\"Image of error message\" \/><\/a><\/p>\n<h2>Using Bypass mode<\/h2>\n<p>So, if I want to run a script in <strong>Bypass<\/strong> mode, I can use the Run dialog box. One problem I have with the Run dialog box is that it is very small, and it does not resize. The Run box is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1805.wes-8-11-13-02.png\"><img decoding=\"async\" title=\"Image of dialog box\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1805.wes-8-11-13-02.png\" alt=\"Image of dialog box\" \/><\/a><\/p>\n<p>So, what I like to do is open Notepad, compose my command, and then paste it into the run dialog box. There are a couple of things that are important to the command. First, I add <strong>&ndash;NoExit<\/strong>. From a scheduled task, I would not do this. I would, instead, have my script output to a log file. I added <strong>&ndash;NoExit<\/strong> so that I could see the output. The key to making this work is specifying the <strong>&ndash;ExecutionPolicy<\/strong> parameter of <strong>Bypass<\/strong>. I then provide the UNC path to the script that I want to run. I would use this exact sort of syntax (without the <strong>NoExit<\/strong>) to run a script from a scheduled task.&nbsp; Here is my command:<\/p>\n<p style=\"padding-left: 30px\">powershell -noexit -executionpolicy bypass -file \\\\dc1\\Share\\ServerNameBios.ps1<\/p>\n<p>Here is the command in Notepad:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6102.wes-8-11-13-03.png\"><img decoding=\"async\" title=\"Image of command\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6102.wes-8-11-13-03.png\" alt=\"Image of command\" \/><\/a><\/p>\n<p>When the command runs, it opens a new instance of Windows PowerShell, executes the script, and displays the output from the script. The execution policy of the newly created instance of Windows PowerShell is <strong>Bypass<\/strong>. This is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0880.wes-8-11-13-04.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0880.wes-8-11-13-04.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Well, that is it for today. I am heading outside, so have a great day, and join me tomorrow as I begin Active Directory Domain Services Migration Week.<\/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><strong>Ed Wilson, Microsoft Scripting Guy<\/strong><span style=\"font-size: 12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, continues his discussion about running scripts from a remote file share. Microsoft Scripting Guy, Ed Wilson, is here. Some things should just be easier. For example, I should have access to client-side cmdlets to work with SharePoint. Many times, as a user, I need to accomplish repetitive tasks, and [&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":[57,3,4,63,61,45],"class_list":["post-3064","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-remoting","tag-scripting-guy","tag-scripting-techniques","tag-security","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, continues his discussion about running scripts from a remote file share. Microsoft Scripting Guy, Ed Wilson, is here. Some things should just be easier. For example, I should have access to client-side cmdlets to work with SharePoint. Many times, as a user, I need to accomplish repetitive tasks, and [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3064","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=3064"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3064\/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=3064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}