Run Powershell script when you open Powershell

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.


Type the following command:

New-item –type file –force $profile

A file Microsoft.PowerShell_profile.ps1 will be created in C:\Users\<username>\Documents\WindowsPowerShell\ for PowerShell 5 and older or C:\Users\<username>\Documents\PowerShell\ 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.

Tags:

Powershell