Explain PowerShell Profile.

PowerShellMicrosoft TechnologiesSoftware & Coding

When you open PowerShell, it loads the profile just like the Windows operating system. When you log in to windows OS you are logged into your profile and every user has their individual profile. It is called the current profile for the current host.

To check your profile, type $Profile command in the PowerShell console.

PS C:\Users\Administrator> $profile
C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.p
s1

This was for Powershell console but let's check if Powershell uses the same profile for ISE.

PS C:\> $profile
C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profil
e.ps1

So the ISE has its own profile too and both are stored in the $Home directory. What if we use the $profile for VSCode.

PS C:\> $profile
C:\Users\Administrator\Documents\PowerShell\Microsoft.VSCode_profile.ps1

This means each editor has its own profile for the current user and current host.

You might have noticed, whenever you start the PowerShell, you can access the commands and modules created by different users on the systems from the Module path because simply starting PowerShell also loads the modules which are stored on $PSHome location. Apart from the current users

PS C:\> $pshome
C:\Windows\System32\WindowsPowerShell\v1.0

The above example suggests that there could be also a profile that exists for all users. Let see how many total profiles exist for PowerShell ISE version.

PS C:\> $profile | fl * -Force
AllUsersAllHosts          : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost       : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.Pow
erShellISE_profile.ps1
CurrentUserAllHosts       : C:\Users\Administrator\Documents\WindowsPowerShell\profi
le.ps1
CurrentUserCurrentHost    : C:\Users\Administrator\Documents\WindowsPowerShell\Micro
soft.PowerShellISE_profile.ps1
Length                    : 86

The above command is executed from ISE, we will now check the same command in PowerShell Console,

PS C:\Users\Administrator> $PROFILE | fl * -Force
AllUsersAllHosts          : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost       : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.Pow
erShell_profile.ps1
CurrentUserAllHosts       : C:\Users\Administrator\Documents\WindowsPowerShell\profi
le.ps1
CurrentUserCurrentHost    : C:\Users\Administrator\Documents\WindowsPowerShell\Micro
soft.PowerShell_profile.ps1
Length                    : 83

When you compare the above two output, you can notice that the current Host (All Users and current user) profile depends on the editor you use. If you use PowerShell console, the profile name would contain PowerShell profile, If you use ISE or VSCode the current Host profile would contain name accordingly.

By comparing we come to know that basically profiles are stored at two locations. 1) $Home (C:\Users\<UserName>) and 2) $PSHome (C:\Windows\System32\WindowsPowerShell).

So there are total 6 profiles.

  • Current User, Current Host – PowerShell Console

  • Current User, All Hosts

  • All Users, Current Host - PowerShell Console

  • All Users, All Hosts

  • Current User, Current Host – Depends on Editor

  • All Users, Current Host – Depends on Editor.

raja
Published on 08-Aug-2020 07:39:22
Advertisements