Automate creating a PowerShell $PROFILE script

Here is a little script to automate the creation of a PowerShell $PROFILE script which is a .PS1 file that is ran every time a Windows PowerShell Prompt is opened.

As you can see in the image below — you can find the location of your $PROFILE script by  typing “$PROFILE” (Don’t forget about tab completion!)


Okay so my $PROFILE is located at C:\users\mkerfoot\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1.

My $PROFILE is already configured but yours might not yet be created. To check if your $PROFILE actually exists run “Test-path $PROFILE



If “Test-path $PROFILE” returns “False” then you have to create this path by running the following command to force the creation of the $PROFILE script.

New-item -type file -force $PROFILE



Your $PROFILE script is all ready to be edited now! to edit you $PROFILE just type “notepad.exe $PROFILE” and type whatever you want to run every time you open up PowerShell!

Now that you known the basics… Let’s automate the $PROFILE creation (Shown Below)

## $NewPROFILE contains all of the lines of code that you wan to be ran every time PS is opened

$NewPROFILE = {}

## Creates the path C:\Users\mkerfoot\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

New-item -type file -force $PROFILE

## Redirects all of the code inserted into th $NewPROFILE variable into your PowerShell Startup $PROFILE script.



Link to the file Below —


Link to the file Below —

Leave a Reply

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

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

Google photo

You are commenting using your Google 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