Configure PowerShell to automatically run PowerShell Scripts/Functions/Commands when PowerShell is opened

Scenario: Do you have a common command, function, or script that you always execute manually within PowerShell at Startup? For example in my case, a .ps1 file that contains functions with how to connect to specific remote PowerShell instances.

Solution:

Run this within PowerShell:
New-item –type file –force $profile

Then edit the file it creates Microsoft.Powershell_profile.ps1 (usually located in this directory: C:\Users\<username>\Documents\PowerShell\) with the call to the script, the function, the commands, etc. Every time you open PowerShell, it will automatically run it and will be ready for you.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: