$PROFILE
Support in a PowerShell Notebook ¶For a while now, PowerShell has had this concept of "Profiles" which are scripts that run when a new instance of PowerShell is started. Inside of a profile, you can put any PowerShell script you'd like.
To see the location of the profile, simply run:
$PROFILE
You can create that file and fill it with anything you want to run before your Notebook runs the first cell of the session.
This profile path is specific to .NET Interactive and specific to the current user who's running it.
Let's add a definition of a global variable to our profile:
'$global:SET_IN_PROFILE = $true' >> $PROFILE
Now open a new Notebook and try running $global:SET_IN_PROFILE
. It should be set to True
!
In PowerShell, you often see a few different kinds of profiles that are accessible on the $PROFILE
object. Just running $PROFILE
is actually the same as running $PROFILE.CurrentUserCurrentHost
. Here are the possibilities:
$PROFILE Property Name |
Description |
---|---|
$PROFILE.CurrentUserCurrentHost |
The current user for the current host |
$PROFILE.AllUsersCurrentHost |
All users for the current host |
$PROFILE.CurrentUserAllHosts |
The current user for all hosts |
$PROFILE.AllUsersAllHost |
All users for all hosts |
NOTE: A "host" here refers to a PowerShell Host application or a "PSHost". These are applications that host a PowerShell runtime. Examples of these include:
- ConsoleHost (used by
pwsh.exe
/pwsh
)- PowerShell Editor Services Host (used by the PowerShell extension for Visual Studio Code's PowerShell Integrated Console)
- .NET Interactive Host (used by this experience in .NET Interactive)
Check out the PowerShell documentation on the $PROFILE
object for more information.
With all that said, .NET Interactive doesn't perfectly align with PowerShell profiles for a few good reasons:
$PROFILE.CurrentUserAllHosts
or $PROFILE.AllUsersAllHosts
¶A lot of folks customize their PowerShell prompt in the $PROFILE.CurrentUserAllHosts
or $PROFILE.AllUsersAllHosts
profiles. .NET Interactive doesn't have a concept of a prompt. Because of this, .NET Interactive does not run your $PROFILE.CurrentUserAllHosts
or $PROFILE.AllUsersAllHosts
profiles. If you feel like this isn't the right behavior, let us know!
$PROFILE.AllUsersCurrentHost
isn't in a system-wide location¶Try running it:
$PROFILE.AllUsersCurrentHost
You'll notice that it exists in the location that .NET Interactive was installed to.
This is typical for the AllUsersCurrentHost
profile as it typically installs in the result of:
$PSHOME
However, since .NET Interactive is a .NET Tool there is no such thing as a system-wide installation, so AllUsersCurrentHost
path is where it is today.