Use PowerShell profile to set something for you when launching a new PowerShell session

In PowerShell, you can crate a profile to set something (e.g. setting, variable) for you when launching a new PowerShell session

Get started

Launch PowerShell with Adminitrator permission

Enter the following command.

> if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }

Then edit with Gvim.

> gvim $PROFILE

In this example we will set AWS profile to set set AWS credential and default region for us. Enter the following code in Vim and change to your user.

$credential = "my-credential" # Change to your AWS Credential
Set-AWSCredential $credential
Set-DefaultAWSRegion ap-southeast-2

Save and exit.

How to exit Vim? Use :wq command

Test your profile configuration.

Close the current session and launch a new PowerShell Session to test if the profile get loaded correctly.

If it loads correctly, you will see a message like "Loading personal and system profiles took xxxms" and no any error messages.