Skip to content

Commit 84bba3e

Browse files
authored
Clarify profile locations (#11847)
1 parent 908f2b6 commit 84bba3e

File tree

1 file changed

+44
-29
lines changed

1 file changed

+44
-29
lines changed

reference/docs-conceptual/learn/shell/creating-profiles.md

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
description: >
33
This article explains how to use your profile to save preferred PowerShell settings and optimize
44
your shell experience.
5-
ms.date: 09/04/2024
5+
ms.date: 02/26/2025
66
title: Customizing your shell environment
77
---
88
# Customizing your shell environment
99

1010
A PowerShell profile is a script that runs when PowerShell starts. You can use the profile to
1111
customize the environment. You can:
1212

13-
- add aliases, functions, and variables
14-
- load modules
15-
- create PowerShell drives
16-
- run arbitrary commands
17-
- and change preference settings
13+
- Add aliases, functions, and variables
14+
- Load modules
15+
- Create PowerShell drives
16+
- Run arbitrary commands
17+
- Change preference settings
1818

1919
Putting these settings in your profile ensures that they're available whenever you start PowerShell
2020
on your system.
@@ -39,32 +39,47 @@ properties of `$PROFILE`.
3939
- **CurrentUserCurrentHost**
4040

4141
You can create profile scripts that run for all users or just one user, the **CurrentUser**.
42-
**CurrentUser** profiles are stored in the user's home directory.
43-
44-
There are also profiles that run for all PowerShell hosts or specific hosts. The profile script
45-
for each PowerShell host has a name unique for that host. For example, the filename for the standard
46-
Console Host on Windows or the default terminal application on other platforms is
47-
`Microsoft.PowerShell_profile.ps1`. For Visual Studio Code (VS Code), the filename is
48-
`Microsoft.VSCode_profile.ps1`.
49-
50-
For more information, see [about_Profiles][2].
42+
**CurrentUser** profiles are stored under the user's home directory path. The location varies
43+
depending on the operating system and the version of PowerShell you use.
5144

5245
By default, referencing the `$PROFILE` variable returns the path to the "Current User, Current Host"
5346
profile. The other profiles path can be accessed through the properties of the `$PROFILE` variable.
54-
For example:
47+
The following command shows the default profile locations on Windows.
5548

5649
```powershell
57-
PS> $PROFILE
58-
C:\Users\user1\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
59-
PS> $PROFILE.AllUsersAllHosts
60-
C:\Program Files\PowerShell\7\profile.ps1
50+
PS> $PROFILE | Select-Object *
51+
AllUsersAllHosts : C:\Program Files\PowerShell\7\profile.ps1
52+
AllUsersCurrentHost : C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1
53+
CurrentUserAllHosts : C:\Users\username\Documents\PowerShell\profile.ps1
54+
CurrentUserCurrentHost : C:\Users\username\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
55+
Length : 69
6156
```
6257

58+
The following command shows the default profile locations on Ubuntu Linux.
59+
60+
```powershell
61+
$PROFILE | Select-Object *
62+
63+
AllUsersAllHosts : /opt/microsoft/powershell/7/profile.ps1
64+
AllUsersCurrentHost : /opt/microsoft/powershell/7/Microsoft.PowerShell_profile.ps1
65+
CurrentUserAllHosts : /home/username/.config/powershell/profile.ps1
66+
CurrentUserCurrentHost : /home/username/.config/powershell/Microsoft.PowerShell_profile.ps1
67+
Length : 67
68+
```
69+
70+
There are also profiles that run for all PowerShell hosts or specific hosts. The profile script for
71+
each PowerShell host has a name unique for that host. For example, the filename for the standard
72+
Console Host on Windows or the default terminal application on other platforms is
73+
`Microsoft.PowerShell_profile.ps1`. For Visual Studio Code (VS Code), the filename is
74+
`Microsoft.VSCode_profile.ps1`.
75+
76+
For more information, see [about_Profiles][2].
77+
6378
## How to create your personal profile
6479

6580
When you first install PowerShell on a system, the profile script files and the directories they
66-
belong to don't exist. The following command creates the "Current User, Current Host"
67-
profile script file if it doesn't exist.
81+
belong to don't exist. The following command creates the "Current User, Current Host" profile script
82+
file if it doesn't exist.
6883

6984
```powershell
7085
if (!(Test-Path -Path $PROFILE)) {
@@ -73,14 +88,14 @@ if (!(Test-Path -Path $PROFILE)) {
7388
```
7489

7590
The **Force** parameter of `New-Item` cmdlet creates the necessary folders when they don't exist.
76-
Once you have created the script file, you can use your favorite editor to customize your shell
91+
After you create the script file, you can use your favorite editor to customize your shell
7792
environment.
7893

7994
## Adding customizations to your profile
8095

8196
The previous articles talked about using [tab completion][3], [command predictors][4], and
8297
[aliases][5]. These articles showed the commands used to load the required modules, create custom
83-
completers, define keybindings, and other settings. These are the kinds of customizations that you
98+
completers, define key bindings, and other settings. These are the kinds of customizations that you
8499
want to have available in every PowerShell interactive session. The profile script is the place for
85100
these settings.
86101

@@ -163,11 +178,11 @@ Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock $scriptblock
163178
This profile script provides examples for the following customization:
164179

165180
- Adds two new [PSDrives][7] for the other root registry hives.
166-
- Creates a [customized prompt][8] that changes if you are running in an elevated session.
167-
- Configures **PSReadLine** and adds keybinding. The color settings use the [$PSStyle][9] feature to
168-
define the ANSI color settings.
169-
- Adds tab completion for the [dotnet CLI][10] tool. The tool provides parameters to help resolve the
170-
command-line arguments. The script block for [Register-ArgumentCompleter][11] uses that
181+
- Creates a [customized prompt][8] that changes if you're running in an elevated session.
182+
- Configures **PSReadLine** and adds key binding. The color settings use the [$PSStyle][9] feature
183+
to define the ANSI color settings.
184+
- Adds tab completion for the [dotnet CLI][10] tool. The tool provides parameters to help resolve
185+
the command-line arguments. The script block for [Register-ArgumentCompleter][11] uses that
171186
feature to provide the tab completion.
172187

173188
<!-- link references -->

0 commit comments

Comments
 (0)