How to run a PowerShell script in folder having space in its name?












0















Running a script in C:UsersOokerDesktop is fine, but yields error in C:UsersOokerAppDataRoamingMicrosoftWindowsStart MenuProgramsStartup.



I guess it's because of Start Menu have space in between, but I don't know how to double click the file and make it run. There seems to have no way to bracket the path beforehand.



I can run it in CLI, and it doesn't reference itself.










share|improve this question





























    0















    Running a script in C:UsersOokerDesktop is fine, but yields error in C:UsersOokerAppDataRoamingMicrosoftWindowsStart MenuProgramsStartup.



    I guess it's because of Start Menu have space in between, but I don't know how to double click the file and make it run. There seems to have no way to bracket the path beforehand.



    I can run it in CLI, and it doesn't reference itself.










    share|improve this question



























      0












      0








      0








      Running a script in C:UsersOokerDesktop is fine, but yields error in C:UsersOokerAppDataRoamingMicrosoftWindowsStart MenuProgramsStartup.



      I guess it's because of Start Menu have space in between, but I don't know how to double click the file and make it run. There seems to have no way to bracket the path beforehand.



      I can run it in CLI, and it doesn't reference itself.










      share|improve this question
















      Running a script in C:UsersOokerDesktop is fine, but yields error in C:UsersOokerAppDataRoamingMicrosoftWindowsStart MenuProgramsStartup.



      I guess it's because of Start Menu have space in between, but I don't know how to double click the file and make it run. There seems to have no way to bracket the path beforehand.



      I can run it in CLI, and it doesn't reference itself.







      powershell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 12:12









      James C.

      9,12622233




      9,12622233










      asked Nov 16 '18 at 5:39









      OokerOoker

      5891728




      5891728
























          1 Answer
          1






          active

          oldest

          votes


















          2














          Few ways to do it.



          Registry:
          Edit your reg key at



          HKEY_CLASSES_ROOTMicrosoft.PowerShellScript.1ShellOpenCommand


          to



          "C:WindowsSystem32WindowsPowerShellv1.0powershell.exe" -noLogo -ExecutionPolicy unrestricted -file "%1"


          or



          Shortcut: Create a shortcut with the target:



          powershell.exe -command "& 'C:UsersOokerAppDataRoamingMicrosoftWindowsStart MenuProgramsStartupMyScript.ps1'"


          keep in mind that the opening in a notepad is a safety measure in the event you accidentally run it when it is not intended.






          share|improve this answer


























          • Is there a way to tell it to run it in a specific file, and the rest is just opening in notepad?

            – Ooker
            Nov 16 '18 at 8:25






          • 1





            @Ooker - place the file in a location of your choice and create a shortcut in the start menu (eg: powershell.exe -file 'C:UsersOokerDesktopMyScript.ps1'). It will run the file on startup as you want and other files will act as normal.

            – James C.
            Nov 16 '18 at 12:24











          • @JamesC. it seems like the only way to do so is to create shortcut. Anyway, what is the different between -file flag and -command flag in your and Drew's version? Why should Drew's version have & before the path?

            – Ooker
            Nov 17 '18 at 7:28











          • The & is a call operator and will run the script you point at it. Effectively the command will launch powershell and launch the script.

            – Drew
            Nov 18 '18 at 21:51












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332054%2fhow-to-run-a-powershell-script-in-folder-having-space-in-its-name%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Few ways to do it.



          Registry:
          Edit your reg key at



          HKEY_CLASSES_ROOTMicrosoft.PowerShellScript.1ShellOpenCommand


          to



          "C:WindowsSystem32WindowsPowerShellv1.0powershell.exe" -noLogo -ExecutionPolicy unrestricted -file "%1"


          or



          Shortcut: Create a shortcut with the target:



          powershell.exe -command "& 'C:UsersOokerAppDataRoamingMicrosoftWindowsStart MenuProgramsStartupMyScript.ps1'"


          keep in mind that the opening in a notepad is a safety measure in the event you accidentally run it when it is not intended.






          share|improve this answer


























          • Is there a way to tell it to run it in a specific file, and the rest is just opening in notepad?

            – Ooker
            Nov 16 '18 at 8:25






          • 1





            @Ooker - place the file in a location of your choice and create a shortcut in the start menu (eg: powershell.exe -file 'C:UsersOokerDesktopMyScript.ps1'). It will run the file on startup as you want and other files will act as normal.

            – James C.
            Nov 16 '18 at 12:24











          • @JamesC. it seems like the only way to do so is to create shortcut. Anyway, what is the different between -file flag and -command flag in your and Drew's version? Why should Drew's version have & before the path?

            – Ooker
            Nov 17 '18 at 7:28











          • The & is a call operator and will run the script you point at it. Effectively the command will launch powershell and launch the script.

            – Drew
            Nov 18 '18 at 21:51
















          2














          Few ways to do it.



          Registry:
          Edit your reg key at



          HKEY_CLASSES_ROOTMicrosoft.PowerShellScript.1ShellOpenCommand


          to



          "C:WindowsSystem32WindowsPowerShellv1.0powershell.exe" -noLogo -ExecutionPolicy unrestricted -file "%1"


          or



          Shortcut: Create a shortcut with the target:



          powershell.exe -command "& 'C:UsersOokerAppDataRoamingMicrosoftWindowsStart MenuProgramsStartupMyScript.ps1'"


          keep in mind that the opening in a notepad is a safety measure in the event you accidentally run it when it is not intended.






          share|improve this answer


























          • Is there a way to tell it to run it in a specific file, and the rest is just opening in notepad?

            – Ooker
            Nov 16 '18 at 8:25






          • 1





            @Ooker - place the file in a location of your choice and create a shortcut in the start menu (eg: powershell.exe -file 'C:UsersOokerDesktopMyScript.ps1'). It will run the file on startup as you want and other files will act as normal.

            – James C.
            Nov 16 '18 at 12:24











          • @JamesC. it seems like the only way to do so is to create shortcut. Anyway, what is the different between -file flag and -command flag in your and Drew's version? Why should Drew's version have & before the path?

            – Ooker
            Nov 17 '18 at 7:28











          • The & is a call operator and will run the script you point at it. Effectively the command will launch powershell and launch the script.

            – Drew
            Nov 18 '18 at 21:51














          2












          2








          2







          Few ways to do it.



          Registry:
          Edit your reg key at



          HKEY_CLASSES_ROOTMicrosoft.PowerShellScript.1ShellOpenCommand


          to



          "C:WindowsSystem32WindowsPowerShellv1.0powershell.exe" -noLogo -ExecutionPolicy unrestricted -file "%1"


          or



          Shortcut: Create a shortcut with the target:



          powershell.exe -command "& 'C:UsersOokerAppDataRoamingMicrosoftWindowsStart MenuProgramsStartupMyScript.ps1'"


          keep in mind that the opening in a notepad is a safety measure in the event you accidentally run it when it is not intended.






          share|improve this answer















          Few ways to do it.



          Registry:
          Edit your reg key at



          HKEY_CLASSES_ROOTMicrosoft.PowerShellScript.1ShellOpenCommand


          to



          "C:WindowsSystem32WindowsPowerShellv1.0powershell.exe" -noLogo -ExecutionPolicy unrestricted -file "%1"


          or



          Shortcut: Create a shortcut with the target:



          powershell.exe -command "& 'C:UsersOokerAppDataRoamingMicrosoftWindowsStart MenuProgramsStartupMyScript.ps1'"


          keep in mind that the opening in a notepad is a safety measure in the event you accidentally run it when it is not intended.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 '18 at 12:13









          James C.

          9,12622233




          9,12622233










          answered Nov 16 '18 at 6:12









          DrewDrew

          1,466418




          1,466418













          • Is there a way to tell it to run it in a specific file, and the rest is just opening in notepad?

            – Ooker
            Nov 16 '18 at 8:25






          • 1





            @Ooker - place the file in a location of your choice and create a shortcut in the start menu (eg: powershell.exe -file 'C:UsersOokerDesktopMyScript.ps1'). It will run the file on startup as you want and other files will act as normal.

            – James C.
            Nov 16 '18 at 12:24











          • @JamesC. it seems like the only way to do so is to create shortcut. Anyway, what is the different between -file flag and -command flag in your and Drew's version? Why should Drew's version have & before the path?

            – Ooker
            Nov 17 '18 at 7:28











          • The & is a call operator and will run the script you point at it. Effectively the command will launch powershell and launch the script.

            – Drew
            Nov 18 '18 at 21:51



















          • Is there a way to tell it to run it in a specific file, and the rest is just opening in notepad?

            – Ooker
            Nov 16 '18 at 8:25






          • 1





            @Ooker - place the file in a location of your choice and create a shortcut in the start menu (eg: powershell.exe -file 'C:UsersOokerDesktopMyScript.ps1'). It will run the file on startup as you want and other files will act as normal.

            – James C.
            Nov 16 '18 at 12:24











          • @JamesC. it seems like the only way to do so is to create shortcut. Anyway, what is the different between -file flag and -command flag in your and Drew's version? Why should Drew's version have & before the path?

            – Ooker
            Nov 17 '18 at 7:28











          • The & is a call operator and will run the script you point at it. Effectively the command will launch powershell and launch the script.

            – Drew
            Nov 18 '18 at 21:51

















          Is there a way to tell it to run it in a specific file, and the rest is just opening in notepad?

          – Ooker
          Nov 16 '18 at 8:25





          Is there a way to tell it to run it in a specific file, and the rest is just opening in notepad?

          – Ooker
          Nov 16 '18 at 8:25




          1




          1





          @Ooker - place the file in a location of your choice and create a shortcut in the start menu (eg: powershell.exe -file 'C:UsersOokerDesktopMyScript.ps1'). It will run the file on startup as you want and other files will act as normal.

          – James C.
          Nov 16 '18 at 12:24





          @Ooker - place the file in a location of your choice and create a shortcut in the start menu (eg: powershell.exe -file 'C:UsersOokerDesktopMyScript.ps1'). It will run the file on startup as you want and other files will act as normal.

          – James C.
          Nov 16 '18 at 12:24













          @JamesC. it seems like the only way to do so is to create shortcut. Anyway, what is the different between -file flag and -command flag in your and Drew's version? Why should Drew's version have & before the path?

          – Ooker
          Nov 17 '18 at 7:28





          @JamesC. it seems like the only way to do so is to create shortcut. Anyway, what is the different between -file flag and -command flag in your and Drew's version? Why should Drew's version have & before the path?

          – Ooker
          Nov 17 '18 at 7:28













          The & is a call operator and will run the script you point at it. Effectively the command will launch powershell and launch the script.

          – Drew
          Nov 18 '18 at 21:51





          The & is a call operator and will run the script you point at it. Effectively the command will launch powershell and launch the script.

          – Drew
          Nov 18 '18 at 21:51




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332054%2fhow-to-run-a-powershell-script-in-folder-having-space-in-its-name%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Error while running script in elastic search , gateway timeout

          Adding quotations to stringified JSON object values