How to install PowerShell and create user profiles.
Be sure to check the options for adding to $PATH and VS Code.
- GitHub: PowerShell
- Microsoft: Install PowerShell on Windows, Linux, and macOS
- Microsoft: PowerShell Telemetry
You can skip this and add it to a profile later.
$env:POWERSHELL_TELEMETRY_OPTOUTThis is a one-time step that cannot be done via a profile. In PS as admin:
$value = Get-ExecutionPolicy
if ($value -eq 'RemoteSigned') {
Write-Host "Execution policy is currently 'RemoteSigned'. No changes made."
} else {
Set-ExecutionPolicy RemoteSigned
Write-Host "Execution policy changed to 'RemoteSigned'."
}At some point you'll want or need to create profiles. I found it best to use 2 profiles - 1 for all users and one for me as the current user.
- Micorsoft: PowerShell Profiles
To create and open profiles, from PowerShell as admin:
# All users, all hosts
Code $profile.AllUsersAllHosts
notepad $profile.AllUsersAllHosts
# Current user, all hosts
Code $Home\Documents\PowerShell\Profile.ps1
notepad $Home\Documents\PowerShell\Profile.ps1- The variable for this file is:
$PSHOME\Profile.ps1. - The command to locate this file is:
$profile.AllUsersAllHosts.
In PowerShell as an admin, test if this file exists and create if needed:
if (Test-Path $profile.AllUsersAllHosts) {
Write-Host "Profile exists."
} else {
New-Item -ItemType File -Path $profile.AllUsersAllHosts -Force
Write-Host "Profile created."
}Use this profile to share settings - like starting the OpenSSH server - across users. For example:
# Open profile
Code $profile.AllUsersAllHosts
# Variables
$env:POWERSHELL_TELEMETRY_OPTOUT = 1
$VerbosePreference = "SilentlyContinue"
# Command History
Set-PSReadlineOption -HistoryNoDuplicates
# Oh My Posh
oh-my-posh init pwsh --config ~/.default.omp.json | Invoke-Expression- The variable for this profile is:
$PROFILE.CurrentUserAllHosts. - The command to locate this file is:
$Home\Documents\PowerShell\Profile.ps1
In PowerShell test if this file exists and create if needed:
if (Test-Path $Home\Documents\PowerShell\Profile.ps1) {
Write-Host "Profile exists."
} else {
New-Item -ItemType File -Path $Home\Documents\PowerShell\Profile.ps1 -Force
Write-Host "Profile created."
}Use this profile for user-specific settings like SSH to remote servers.
# Open profile
Code $Home\Documents\PowerShell\Profile.ps1
# wce.red
function wcdred{ssh -i ~/.ssh/wcd-red.pem ubuntu@wcd.red}
# SSH to NAS
function NAS {ssh wcdogg@192.168.1.209 -p7022}
# SSH to wcdUbuntu
function wcdub {ssh -i ~/.ssh/wcd-ubuntu.pem ubuntu@23.20.11.194}You can set PowerShell 7 as the default terminal for VS Code.
# Check and note the installation path
Get-Command pwsh | Select-Object -ExpandProperty Path
C:\Program Files\PowerShell\7\pwsh.exeIn VS Code:
Ctrl + ,to open 'Settings'- Search for:
terminal.integrated.defaultProfile - On either or both of the 'User' and 'Workspace' tabs, locate the 'Terminal' dropdown and select 'PowerShell'.
Alternatively, you can add this to your settings.json:
"terminal.integrated.defaultProfile.windows": "PowerShell 7",
"terminal.integrated.profiles.windows": {
"PowerShell 7": {
"path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
}
}
- GitHub: Learn PowerShell
- Microsoft: Migrating from Windows PowerShell 5.1 to PowerShell 7
- Microsoft: About Prompts
- PSHostRawUserInterface Class
- GNU Bash
- mohitgoyal.co: Write Verbose Output in PowerShell using Write-Verbose