Introduction
The next major versions of PowerShell is already here and was announced on March 4th !
PowerShell v7 ships with some new shiny features, significant changes and slew of performance improvements and bug fixes, so lets just quickly go through them without going into the details before we can look into PowerShell 7 Profile:
- .NET Core 3.1 (LTS)
- Pipeline parallelization using
ForEach-Object -Parallel
- Windows compatibility wrapper
- Automatic new PowerShell version notifications.
- New error view (
ConciseView
) andGet-Error
cmdlet - Pipeline chain operators (
&&
and||
) - New Ternary operator (
a ? b : c
) - New Null assignment and coalescing operators (
??
and??=
) - Cross-platform
Invoke-DscResource
, which is still experimental - Legacy Windows GUI cmdlet
Out-GridView
,-ShowWindow
switch parameter are back.
Apart from these major feature releases there are some changes in directory paths as well if you are coming from Windows PowerShell v5.1, like the default locations where your $Profiles
are stored is changed.
First thing first, if you don’t know what are PowerShell profiles on worries. PowerShell Profiles are just like logon scripts, to be specific a fancy name of PowerShell scripts that is executed by the host when it is launched, which can be used to setup your PowerShell session specific to your needs. Use cases may vary from:
- Setting up Environment Variables
- Defining Aliases
- Loading custom functions into the session which you use very often.
- Preload Modules to current session.
- Overriding PowerShell prompt function
$function:prompt
to change the appearance and feel of the prompt.
All these customization are applied every time PowerShell.exe
or pwsh
is launched, unless the -noprofile
switch is explicitly specified.
Profile Files and Directory Changes
PowerShell supports the following profile paths and they are listed in the precedence order, that means the first profile “Current user, Current Host” has the highest precedence order to the profiles mentioned after that. It is important to understand this precedence order correctly, because all these profiles co-exist on your system and if they are miss configured you would observe undesirable outcomes.
Profile Path | Scope |
---|---|
$Home [My ]Documents\PowerShell\Microsoft.PowerShell_profile.ps1 |
Current user, Current Host |
$Home [My ]Documents\PowerShell\Profile.ps1 |
Current User, All Hosts |
$PsHome \Microsoft.PowerShell_profile.ps1 |
All Users, Current Host |
$PsHome \Profile.ps1 |
All Users, All Hosts |
Here, Automatic variable $PSHome
variable stores the installation directory of PowerShell and $Home
stores the current user’s home directory. One important thing to note here is, since PowerShell v6 it is open-sourced and cross-platform so it can run on Windows, Linux and Mac OS, hence the values of $PSHome
and $Home
variable will change on various Hosts, PowerShell versions and operating systems.
NOTE:
Following changes were introduced in PowerShell Core v6, not in the recent release version 7 and it is good to know if you have started using PowerShell v7 and coming from Windows PowerShell v5 background.
In Windows PowerShell v5.1, $PSHome
points to C:\Windows\System32\WindowsPowerShell\v1.0
so the profile for ‘All Users All Hosts’ can be located at: C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
Whereas, in PowerShell v7, $PSHome
becomes to C:\Program Files\PowerShell\7
and hence your $Profile
variable for ‘All Users All Hosts’ points to a different path now:
C:\Program Files\PowerShell\7\profile.ps1
But on the Linux systems, PowerShell v7 (pwsh
) is installed at: /opt/mcirosoft/powershell
directory, so your ‘All Users All Hosts’ profile is located at: /opt/microsoft/powershell/profile.ps1
PLEASE NOTE
If you already had PowerShell Core v6.x installed on your machine and then if you install PowerShell v7, it will overwrite the PowerShell Core 6.x directory and remove all the unnecessary files
, that is in place upgrade that removes the older version
.
But it can still run side-by-side with Windows PowerShell v5.1.
Profile Variable
PowerShell provides an automatic variable called $Profile
which stores profile paths for all the profiles, by default it only shows the path of ‘Current User, Current Host’ and if you want to view all the other profile paths, you have to then inspect this variable a little more for NoteProperty
where you will observe following Properties and pointing to files for a specific scope listed in the following table, and you can utilize these scopes to control how you want your session to be configured on different hosts (Like, VSCode) and users:
Variable/Property | Scope |
---|---|
$Profile | Current User, Current Host |
$Profile.CurrentUserCurrentHost | Current User, Current Host |
$Profile.CurrentUserAllHosts | Current User, All Hosts |
$Profile.AllUsersCurrentHost | All Users, Current Host |
$Profile.AllUsersAllHosts | All Users, All Hosts |
All Windows PowerShell v5.1 Profile Paths
All PowerShell v7 (Windows) Profile Paths
All PowerShell v7 (Linux) Profile Paths
#PS7Now #PSBlogWeek Community Contributors (Stay tuned!)
Checkout more amazing blog posts and articles on PowerShell v7 posted by fellow PowerShell community contributors or you can also follow: #PS7Now #PSBlogWeek hashtags on twitter to keep posted whenever a new post is out!
Author | Blog | |
---|---|---|
Adam Bertram | @adbertram | https://adamtheautomator.com/ |
Dave Carroll | @thedavecarroll | https://powershell.anovelidea.org/ |
Josh Duffney | @joshduffney | http://duffney.io/ |
Dan Franciscus | @danfranciscus | https://winsysblog.com/ |
Jeff Hicks | @jeffhicks | https://jdhitsolutions.com/ |
Mike Kanakos | @MikeKanakos | https://www.networkadm.in/ |
Josh King | @WindosNZ | https://toastit.dev/ |
Thomas Lee | @doctordns | https://tfl09.blogspot.com/ |
Tommy Maynard | @thetommymaynard | https://tommymaynard.com/ |
Jonathan Medd | @jonathanmedd | https://www.jonathanmedd.net/ |
Prateek Singh | @singhprateik | https://ridicurious.com/ |
If you haven’t already started PowerShell version 7 by now, give it a try and you would love it! 🙂
~ Author of “PowerShell Guide to Python“, and currently writing a Book on “Windows Subsystem for Linux (WSL)“
All my books are available as a discounted bundle:
-
- PowerShell Guide to Python : This PowerShell Scripting guide to Python is designed to make readers familiar with syntax, semantics and core concepts of Python language, in an approach that readers can totally relate with the concepts of PowerShell already in their arsenal, to learn Python fast and effectively, such that it sticks with readers for longer time.
- Windows Subsystem for Linux (WSL) : Keywords, definitions, and problems WSL solve and how it works under the hoods. From download to setup to interoperability this book even covers details like the architecture of Windows subsystem for Linux and new features in WSL 2 with some wonderful use cases.
Prateek Singh
Related posts
1 Comment
Leave a ReplyCancel reply
Categories
Author of Books
Awards
Open Sourced Projects
Author at
Blog Roll
Mike F RobbinsDamien Van Robaeys
Stéphane van Gulick
Kevin Marquette
Adam Bertram
Stephanos Constantinou
Francois-Xavier Cat
Ravikanth Chaganti
Roman Levchenko
Blog Stats
- 1,132,477 People Reached
Why would the $profile for Powershell 7 show as being in a Temp directory?
CurrentUserAllHosts=C:\Users\MYUSER\AppData\Local\Temp\01b1-bc90-a629-6ef1\Documents\PowerShell\pro
file.ps1