Run Powershell script when you open Powershell
up vote
7
down vote
favorite
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
add a comment |
up vote
7
down vote
favorite
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
add a comment |
up vote
7
down vote
favorite
up vote
7
down vote
favorite
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
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
powershell
asked Mar 8 '15 at 10:29
user9993
127412
127412
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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
add a comment |
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.
- Navigate to
$env:UserProfileDocumentsWindowsPowerShell
.
Typically, this expands toC:Users<username>DocumentsWindowsPowerShell
.
Create the folders if they do not exist. - 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 haveprofile.ps1
call those scripts.
As a side note, the default profile name should be Microsoft.PowerShell_profile.ps1
.
But profile.ps1
also works.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 29 at 21:28
Dawid Ferenczy
323212
323212
answered Mar 8 '15 at 10:56
Walter Mitty
35629
35629
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 29 at 21:28
Dawid Ferenczy
323212
323212
answered Dec 5 '15 at 18:02
N P
111
111
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
Update the Default $Profile Variable
Edit the Default .PS1 file (if not exist, Create it)
Add your Script to the .PS1 File
answered Mar 15 '15 at 13:52
user428240
1
1
add a comment |
add a comment |
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.
- Navigate to
$env:UserProfileDocumentsWindowsPowerShell
.
Typically, this expands toC:Users<username>DocumentsWindowsPowerShell
.
Create the folders if they do not exist. - 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 haveprofile.ps1
call those scripts.
As a side note, the default profile name should be Microsoft.PowerShell_profile.ps1
.
But profile.ps1
also works.
add a comment |
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.
- Navigate to
$env:UserProfileDocumentsWindowsPowerShell
.
Typically, this expands toC:Users<username>DocumentsWindowsPowerShell
.
Create the folders if they do not exist. - 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 haveprofile.ps1
call those scripts.
As a side note, the default profile name should be Microsoft.PowerShell_profile.ps1
.
But profile.ps1
also works.
add a comment |
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.
- Navigate to
$env:UserProfileDocumentsWindowsPowerShell
.
Typically, this expands toC:Users<username>DocumentsWindowsPowerShell
.
Create the folders if they do not exist. - 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 haveprofile.ps1
call those scripts.
As a side note, the default profile name should be Microsoft.PowerShell_profile.ps1
.
But profile.ps1
also works.
There are many ways to do this. A straight forward way is to a profile script in your default powershell home path.
- Navigate to
$env:UserProfileDocumentsWindowsPowerShell
.
Typically, this expands toC:Users<username>DocumentsWindowsPowerShell
.
Create the folders if they do not exist. - 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 haveprofile.ps1
call those scripts.
As a side note, the default profile name should be Microsoft.PowerShell_profile.ps1
.
But profile.ps1
also works.
answered Sep 7 '15 at 6:49
nehcsivart
413311
413311
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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