Run Powershell script when you open Powershell











up vote
7
down vote

favorite
1












Is it possible to run a Powershell script when you run Powershell? As in, double click the Powershell icon and open the window. Is there some type of "auto-run" setting somewhere?










share|improve this question


























    up vote
    7
    down vote

    favorite
    1












    Is it possible to run a Powershell script when you run Powershell? As in, double click the Powershell icon and open the window. Is there some type of "auto-run" setting somewhere?










    share|improve this question
























      up vote
      7
      down vote

      favorite
      1









      up vote
      7
      down vote

      favorite
      1






      1





      Is it possible to run a Powershell script when you run Powershell? As in, double click the Powershell icon and open the window. Is there some type of "auto-run" setting somewhere?










      share|improve this question













      Is it possible to run a Powershell script when you run Powershell? As in, double click the Powershell icon and open the window. Is there some type of "auto-run" setting somewhere?







      powershell






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 '15 at 10:29









      user9993

      127412




      127412






















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          11
          down vote



          accepted










          There is a PowerShell script that runs on ps startup, if it exists. The filespec for this script is in the variable $profile.



          You can use PowerShell commands to check to see if this script file exists, to create it if it doesn't, and to edit it with notepad. Here's the how to guide.






          share|improve this answer






























            up vote
            1
            down vote













            Type the following command:



            New-item –type file –force $profile


            A file Microsoft.PowerShell_profile.ps1 will be created in C:Users<username>DocumentsWindowsPowerShell for PowerShell 5 and older or C:Users<username>DocumentsPowerShell for PowerShell 6 Core (this folder will be automatically created).



            Then edit this file and you can add personalized PowerShell functions or load modules or snap-ins...



            Now when you run your powershell console, Microsoft.PowerShell_profile.ps1 will be triggered.






            share|improve this answer






























              up vote
              0
              down vote













              Update the Default $Profile Variable
              Edit the Default .PS1 file (if not exist, Create it)
              Add your Script to the .PS1 File






              share|improve this answer




























                up vote
                0
                down vote













                There are many ways to do this. A straight forward way is to a profile script in your default powershell home path.




                1. Navigate to $env:UserProfileDocumentsWindowsPowerShell.

                  Typically, this expands to C:Users<username>DocumentsWindowsPowerShell.

                  Create the folders if they do not exist.

                2. Create a file named profile.ps1. You can write your script in this file, and this file will be executed each time you start powershell as the user. If you have the script somewhere else, you can have profile.ps1 call those scripts.


                As a side note, the default profile name should be Microsoft.PowerShell_profile.ps1.

                But profile.ps1 also works.






                share|improve this answer





















                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "3"
                  };
                  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',
                  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%2fsuperuser.com%2fquestions%2f886951%2frun-powershell-script-when-you-open-powershell%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  11
                  down vote



                  accepted










                  There is a PowerShell script that runs on ps startup, if it exists. The filespec for this script is in the variable $profile.



                  You can use PowerShell commands to check to see if this script file exists, to create it if it doesn't, and to edit it with notepad. Here's the how to guide.






                  share|improve this answer



























                    up vote
                    11
                    down vote



                    accepted










                    There is a PowerShell script that runs on ps startup, if it exists. The filespec for this script is in the variable $profile.



                    You can use PowerShell commands to check to see if this script file exists, to create it if it doesn't, and to edit it with notepad. Here's the how to guide.






                    share|improve this answer

























                      up vote
                      11
                      down vote



                      accepted







                      up vote
                      11
                      down vote



                      accepted






                      There is a PowerShell script that runs on ps startup, if it exists. The filespec for this script is in the variable $profile.



                      You can use PowerShell commands to check to see if this script file exists, to create it if it doesn't, and to edit it with notepad. Here's the how to guide.






                      share|improve this answer














                      There is a PowerShell script that runs on ps startup, if it exists. The filespec for this script is in the variable $profile.



                      You can use PowerShell commands to check to see if this script file exists, to create it if it doesn't, and to edit it with notepad. Here's the how to guide.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 29 at 21:28









                      Dawid Ferenczy

                      323212




                      323212










                      answered Mar 8 '15 at 10:56









                      Walter Mitty

                      35629




                      35629
























                          up vote
                          1
                          down vote













                          Type the following command:



                          New-item –type file –force $profile


                          A file Microsoft.PowerShell_profile.ps1 will be created in C:Users<username>DocumentsWindowsPowerShell for PowerShell 5 and older or C:Users<username>DocumentsPowerShell for PowerShell 6 Core (this folder will be automatically created).



                          Then edit this file and you can add personalized PowerShell functions or load modules or snap-ins...



                          Now when you run your powershell console, Microsoft.PowerShell_profile.ps1 will be triggered.






                          share|improve this answer



























                            up vote
                            1
                            down vote













                            Type the following command:



                            New-item –type file –force $profile


                            A file Microsoft.PowerShell_profile.ps1 will be created in C:Users<username>DocumentsWindowsPowerShell for PowerShell 5 and older or C:Users<username>DocumentsPowerShell for PowerShell 6 Core (this folder will be automatically created).



                            Then edit this file and you can add personalized PowerShell functions or load modules or snap-ins...



                            Now when you run your powershell console, Microsoft.PowerShell_profile.ps1 will be triggered.






                            share|improve this answer

























                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote









                              Type the following command:



                              New-item –type file –force $profile


                              A file Microsoft.PowerShell_profile.ps1 will be created in C:Users<username>DocumentsWindowsPowerShell for PowerShell 5 and older or C:Users<username>DocumentsPowerShell for PowerShell 6 Core (this folder will be automatically created).



                              Then edit this file and you can add personalized PowerShell functions or load modules or snap-ins...



                              Now when you run your powershell console, Microsoft.PowerShell_profile.ps1 will be triggered.






                              share|improve this answer














                              Type the following command:



                              New-item –type file –force $profile


                              A file Microsoft.PowerShell_profile.ps1 will be created in C:Users<username>DocumentsWindowsPowerShell for PowerShell 5 and older or C:Users<username>DocumentsPowerShell for PowerShell 6 Core (this folder will be automatically created).



                              Then edit this file and you can add personalized PowerShell functions or load modules or snap-ins...



                              Now when you run your powershell console, Microsoft.PowerShell_profile.ps1 will be triggered.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Nov 29 at 21:28









                              Dawid Ferenczy

                              323212




                              323212










                              answered Dec 5 '15 at 18:02









                              N P

                              111




                              111






















                                  up vote
                                  0
                                  down vote













                                  Update the Default $Profile Variable
                                  Edit the Default .PS1 file (if not exist, Create it)
                                  Add your Script to the .PS1 File






                                  share|improve this answer

























                                    up vote
                                    0
                                    down vote













                                    Update the Default $Profile Variable
                                    Edit the Default .PS1 file (if not exist, Create it)
                                    Add your Script to the .PS1 File






                                    share|improve this answer























                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      Update the Default $Profile Variable
                                      Edit the Default .PS1 file (if not exist, Create it)
                                      Add your Script to the .PS1 File






                                      share|improve this answer












                                      Update the Default $Profile Variable
                                      Edit the Default .PS1 file (if not exist, Create it)
                                      Add your Script to the .PS1 File







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Mar 15 '15 at 13:52









                                      user428240

                                      1




                                      1






















                                          up vote
                                          0
                                          down vote













                                          There are many ways to do this. A straight forward way is to a profile script in your default powershell home path.




                                          1. Navigate to $env:UserProfileDocumentsWindowsPowerShell.

                                            Typically, this expands to C:Users<username>DocumentsWindowsPowerShell.

                                            Create the folders if they do not exist.

                                          2. Create a file named profile.ps1. You can write your script in this file, and this file will be executed each time you start powershell as the user. If you have the script somewhere else, you can have profile.ps1 call those scripts.


                                          As a side note, the default profile name should be Microsoft.PowerShell_profile.ps1.

                                          But profile.ps1 also works.






                                          share|improve this answer

























                                            up vote
                                            0
                                            down vote













                                            There are many ways to do this. A straight forward way is to a profile script in your default powershell home path.




                                            1. Navigate to $env:UserProfileDocumentsWindowsPowerShell.

                                              Typically, this expands to C:Users<username>DocumentsWindowsPowerShell.

                                              Create the folders if they do not exist.

                                            2. Create a file named profile.ps1. You can write your script in this file, and this file will be executed each time you start powershell as the user. If you have the script somewhere else, you can have profile.ps1 call those scripts.


                                            As a side note, the default profile name should be Microsoft.PowerShell_profile.ps1.

                                            But profile.ps1 also works.






                                            share|improve this answer























                                              up vote
                                              0
                                              down vote










                                              up vote
                                              0
                                              down vote









                                              There are many ways to do this. A straight forward way is to a profile script in your default powershell home path.




                                              1. Navigate to $env:UserProfileDocumentsWindowsPowerShell.

                                                Typically, this expands to C:Users<username>DocumentsWindowsPowerShell.

                                                Create the folders if they do not exist.

                                              2. Create a file named profile.ps1. You can write your script in this file, and this file will be executed each time you start powershell as the user. If you have the script somewhere else, you can have profile.ps1 call those scripts.


                                              As a side note, the default profile name should be Microsoft.PowerShell_profile.ps1.

                                              But profile.ps1 also works.






                                              share|improve this answer












                                              There are many ways to do this. A straight forward way is to a profile script in your default powershell home path.




                                              1. Navigate to $env:UserProfileDocumentsWindowsPowerShell.

                                                Typically, this expands to C:Users<username>DocumentsWindowsPowerShell.

                                                Create the folders if they do not exist.

                                              2. Create a file named profile.ps1. You can write your script in this file, and this file will be executed each time you start powershell as the user. If you have the script somewhere else, you can have profile.ps1 call those scripts.


                                              As a side note, the default profile name should be Microsoft.PowerShell_profile.ps1.

                                              But profile.ps1 also works.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Sep 7 '15 at 6:49









                                              nehcsivart

                                              413311




                                              413311






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Super User!


                                                  • 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.





                                                  Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                  Please pay close attention to the following guidance:


                                                  • 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%2fsuperuser.com%2fquestions%2f886951%2frun-powershell-script-when-you-open-powershell%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

                                                  Probability when a professor distributes a quiz and homework assignment to a class of n students.

                                                  Aardman Animations

                                                  Are they similar matrix