In WSL, as on any Linux distribution, there’s no PowerShell User Profile file(“Microsoft.PowerShell_Profile.ps1“). So, it needs to be created manually.
Creating the profile folder
This profile is stored in the user home configuration folder “~/.config/powershell” folder.
But, the “powershell” folder doesn’t exist, it needs to be created in the configuration folder:
From the bash prompt, follow these steps:
1. Make sure you are in the user home folder:
pwd cd /home/yourUserFolder
2. Verify the PowerShell folder doesn’t exist:
3. Change to the configuration folder:
3. Create the “powershell” folder, and assign permissions:
cd ~/.config mkdir powershell chmod 755 ll
Creating Microsoft.PowerShell_profile file
1. Using your Linux editor, create the Microsoft.PowerShell_Profile.ps1 file, and add code to the file: (Below using “vim” editor)
sudo vim /home/yourUserFolder/.config/powershell/Microsoft.PowerShell_profile.ps1
-> Write-Host "Welcome to PowerShell in Linux" -foreground 'Yellow'; -> Import-Module Microsoft.PowerShell.UnixCompleters -> Import-UnixCompleters -> Write-Host "UnixCompleters is loaded!" -foreground 'Yellow';
5. When done, save changes and exit “vim’ editor by typing:
Testing the PowerShell Profile
Open PowerShell and the “Welcome to PowerShell in Linux” with any other text will be displayed. At the same time, anything else in the profile will be executed.
Now, you can add more commands to the file when needed.
Keep on PowerShelling!