Useful PowerShell’s $profile in Windows 11

What is Windows PowerShell $profile?

In Windows PowerShell, $profile is a special variable that represents the user-specific profile script. The profile script is a PowerShell script file that is automatically executed every time a PowerShell session starts for a particular user. It allows you to define custom settings, aliases, functions, variables, and other configurations that are specific to your user account and PowerShell sessions.

You can find the paths to your profile scripts by executing the following commands in a PowerShell session

$profile
$profile.CurrentUserCurrentHost
$profile.CurrentUserAllHosts
$profile.AllUsersCurrentHost
$profile.AllUsersAllHosts

Output
C:\Users\me\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
C:\Users\me\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
C:\Users\me\Documents\WindowsPowerShell\profile.ps1
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1

Create profile

New-item –type file –force $PROFILE
Edit profile
notepad $profile
ise $profile

Powershell Shortcut CLI for folder navigation

One frustrating aspect of PowerShell is that you can’t easily create folder navigation aliases like %alias me= “cd me” as in the regular linux style bash shell. However, you can achieve similar functionality with the following:

1. Define variables in $profile

If you define $me= “C:\Users\me\me”, you can navigate to that folder using > cd $me.

2. Define functions in $profile

If you define function me(){cd “C:\Users\me\me”}, you can navigate to the desired folder using > me.

If your goal is just navigation, defining a function is better, but if you frequently refer to a specific folder, defining a variable can be more convenient.

3. Reloading $profile

You can reload the settings with

. $profile

4. Sample $profle

####################################################
# Windows Powershell Profile
# Path C:\Users\user\Documents\WindowsPowerShell\Microsoft.PowerShell_profile
# Profile Type Command Host Profile File Name Profile File Location
# $PSHOME
#
# PATH
# 1 CurrentUserCurrentHost 
# $profile
#
# 2 CurrentUserAllHosts 
# $profile.CurrentUserAllHosts
#
# 3 AllUsersCurrentHost 
# $profile.AllUsersCurrentHost
#
# 4 AllUsersAllHosts 
# $profile.AllUsersAllHosts
#
# CLI crud
# Check profile existency
# $PROFILE
# $PROFILE | Get-Member -Type NoteProperty
#
# Create new profile
# New-Item -Type File -Force $PROFILE
# 
# Update or Edit profile
# notepad $PROFILE
# ise $PROFILE
#
# Powershell version
# Get-Host
#
# Reference
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.2
####################################################
Get-TimeZone

# v2023.2.029
# Aliase to C:\Users\me\me
$me="C:\Users\me\me"