Skip to content

Instantly share code, notes, and snippets.

@datavudeja
Forked from Computer-Tsu/PSInfo.md
Created October 21, 2025 13:20
Show Gist options
  • Save datavudeja/502b1596f78ee745676e34a98e951dfe to your computer and use it in GitHub Desktop.
Save datavudeja/502b1596f78ee745676e34a98e951dfe to your computer and use it in GitHub Desktop.
PowerShell Profiles

Comments

# Comment line

<#
comment block
#>

Function Help Comments

function Get-UserInfo {
<#
.SYNOPSIS
Get the Microsoft 365 user information

.DESCRIPTION
Retrieves detailed information about a specified Microsoft 365 user

.PARAMETER Username
The username of the Microsoft 365 user

.EXAMPLE
Get-UserInfo -Username '[email protected]'
Retrieves information for the user '[email protected]'
#>

[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Username
)

# Function code here
}

Usage: Get-Help -Name My-Function -Detailed

Profile

List the various PowerShell Profile locations
$profile | Format-List -Force

Load PowerShell without profile
powershell.exe -noprofile
powershell_ise.exe -NoProfile

Profile script Variables load in to global scope context by default.
Help about_profiles and about_scopes

  • Windows PowerShell
  • Windows PowerShell ISE
  • PowerShell on Windows
  • PowerShell Core on Windows
  • PowerShell Core on Linux
  • PowerShell Core on Mac OS

Change unsigned script permissions for single session: ...


AllUsersAllHosts       : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost    : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts    : C:\Users\Admin\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\Admin\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

Windows PowerShell ISE

AllUsersAllHosts       : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost    : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1
CurrentUserAllHosts    : C:\Users\Admin\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\Admin\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1

Alternate sort order

The PowerShell console supports the following basic profile files. These file paths are the default locations.

  • All Users, All Hosts
    • Windows - $PSHOME\Profile.ps1
    • Linux - /opt/microsoft/powershell/7/profile.ps1
    • macOS - /usr/local/microsoft/powershell/7/profile.ps1
  • All Users, Current Host
    • Windows - $PSHOME\Microsoft.PowerShell_profile.ps1
    • Linux - /opt/microsoft/powershell/7/Microsoft.PowerShell_profile.ps1
    • macOS - /usr/local/microsoft/powershell/7/Microsoft.PowerShell_profile.ps1
  • Current User, All Hosts
    • Windows - $HOME\Documents\PowerShell\Profile.ps1
    • Linux - ~/.config/powershell/profile.ps1
    • macOS - ~/.config/powershell/profile.ps1
  • Current user, Current Host
    • Windows - $HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
    • Linux - ~/.config/powershell/Microsoft.PowerShell_profile.ps1
    • macOS - ~/.config/powershell/Microsoft.PowerShell_profile.ps1

    Microsoft advises against redirecting the Documents folder with GPO or OneDrive as this may break PowerShell Profile and Module load paths.

    The profile scripts are executed in the order listed. This means that changes made in the **AllUsersAllHosts** profile can be overridden by any of the other profile scripts. The **CurrentUserCurrentHost** profile always runs last. In PowerShell Help, the **CurrentUserCurrentHost** profile is the profile most often referred to as *your PowerShell profile*.


Visual Studio Code

Other programs that host PowerShell can support their own profiles. For example, Visual Studio Code (VS Code) supports the following host-specific profiles.

  • All users, Current Host - $PSHOME\Microsoft.VSCode_profile.ps1
  • Current user, Current Host - $HOME\Documents\PowerShell\Microsoft.VSCode_profile.ps1

The profile paths include the following variables:

  • The $PSHOME variable stores the installation directory for PowerShell
  • The $HOME variable stores the current user's home directory

Windows Terminal

https://code.visualstudio.com/docs/terminal/profiles

C:\Users\{USERNAME}\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState
C:\Users\{username}\AppData\Local\Microsoft\Windows Terminal\settings.json
%userprofile%\AppData\Local\Microsoft\Windows Terminal\settings.json

$settings = (Get-Item "C:\users\$env:UserName\AppData\Local\Packages\Microsoft.WindowsTerminal_*\LocalState\settings.json")
$settings.DirectoryName

The powershell.config.json file contains configuration settings for PowerShell. PowerShell loads this configuration at startup.

      https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_config

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_session_configuration_files


PowerShell varieties

(not including the previews)

There are multiple ways to install PowerShell in Windows. Each install method is designed to support different scenarios and workflows. Choose the method that best suits your needs.

  • Winget - Recommended way to install PowerShell on Windows clients
  • MSI package - Best choice for Windows Servers and enterprise deployment scenarios
  • ZIP package - Easiest way to "side load" or install multiple versions
    • Use this method for Windows Nano Server, Windows IoT, and Arm-based systems
  • .NET Global tool - A good choice for .NET developers that install and use other global tools
  • Microsoft Store package - An easy way to install for casual users of PowerShell but has limitations

** Note**

The installation commands in this article are for the latest stable release of PowerShell. To install a different version of PowerShell, adjust the command to match the version you need. The following links direct you to the release page for each version in the PowerShell repository on GitHub.

Download links for every package are found in the Assets section of the Release page. The Assets section may be collapsed, so you may need to click to expand it.

Note: PowerShell 7.4 installs to a new directory and runs side-by-side with Windows PowerShell 5.1. PowerShell 7.4 is an in-place upgrade that removes previous versions of PowerShell 7

Windows Microsoft Store source install

Known limitations

By default, Windows Store packages run in an application sandbox that virtualizes access to some filesystem and registry locations. Changes to virtualized file and registry locations don't persist outside of the application sandbox.

This sandbox blocks all changes to the application's root folder. Any system-level configuration settings stored in $PSHOME can't be modified. This includes the WSMAN configuration. This prevents remote sessions from connecting to Store-based installs of PowerShell. User-level configurations and SSH remoting are supported.

The following commands need write to $PSHOME. These commands aren't supported in a Microsoft Store instance of PowerShell.

  • Register-PSSessionConfiguration
  • Update-Help -Scope AllUsers
  • Enable-ExperimentalFeature -Scope AllUsers
  • Set-ExecutionPolicy -Scope LocalMachine
$PROFILE | Format-List -Force
Test-Path -Path $PROFILE.AllUsersAllHosts
Test-Path -Path $PROFILE.AllUsersCurrentHost
Test-Path -Path $PROFILE.CurrentUserAllHosts
Test-Path -Path $PROFILE.CurrentUserCurrentHost
function CustomizeConsole {
$hosttime = (Get-ChildItem -Path $PSHOME\pwsh.exe).CreationTime
$hostversion="$($Host.Version.Major)`.$($Host.Version.Minor)"
$Host.UI.RawUI.WindowTitle = "PowerShell $hostversion ($hosttime)"
# Clear-Host
}
CustomizeConsole
function Get-CmdletAlias ($cmdletname) {
Get-Alias |
Where-Object -FilterScript {$_.Definition -like "$cmdletname"} |
Format-Table -Property Definition, Name -AutoSize
}
function Prompt {
$env:COMPUTERNAME + "\" + (Get-Location) + "> "
}
(Get-Command Prompt).ScriptBlock
# Array of profile paths
$profiles = @($PROFILE, $PROFILE.CurrentUserAllHosts, $PROFILE.AllUsersCurrentHost, $PROFILE.AllUsersAllHosts)
# Function to check profile details
function Get-ProfileDetails {
param (
[string]$profilePath
)
if (Test-Path $profilePath) {
$fileInfo = Get-Item $profilePath
Write-Host "Profile: $profilePath" -ForegroundColor Green
Write-Host " Exists: Yes" -ForegroundColor Green
Write-Host " Size: $($fileInfo.Length) bytes" -ForegroundColor Green
Write-Host " Last Modified: $($fileInfo.LastWriteTime)" -ForegroundColor Green
} else {
Write-Host "Profile: $profilePath" -ForegroundColor Red
Write-Host " Exists: No" -ForegroundColor Red
}
}
# Check each profile
foreach ($profile in $profiles) {
Get-ProfileDetails -profilePath $profile
}
function prompt {
$adminCheck = [Security.Principal.WindowsPrincipal]::new([Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
$adminStatus = if ($adminCheck) { "[Admin]" } else { "[User]" }
"$adminStatus PS " + (Get-Location) + "> "
}
function prompt {
$adminCheck = [Security.Principal.WindowsPrincipal]::new([Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
if ($adminCheck) {
Write-Host -NoNewline -ForegroundColor Red "[Admin] PS " + (Get-Location) + "> "
} else {
Write-Host -NoNewline -ForegroundColor Green "[User] PS " + (Get-Location) + "> "
}
return " "
}
function prompt {
$gitBranch = ""
if (Test-Path .git) {
$gitBranch = " (" + (git branch --show-current) + ")"
}
"PS " + (Get-Location) + "$gitBranch> "
}function prompt {
$gitBranch = ""
if (Test-Path .git) {
$gitBranch = " (" + (git branch --show-current) + ")"
}
"PS " + (Get-Location) + "$gitBranch> "
}
function prompt {
"PS [" + (Get-Date -Format "HH:mm:ss") + "] " + (Get-Location) + "> "
}
function prompt {
$os = Get-CimInstance Win32_OperatingSystem
$uptime = (Get-Date) - $os.LastBootUpTime
"PS [Uptime: $([math]::Round($uptime.TotalHours, 2)) hrs] " + (Get-Location) + "> "
}
function prompt {
$errorCount = $global:Error.Count
"PS [Errors: $errorCount] " + (Get-Location) + "> "
}
function prompt {
$host.UI.RawUI.ForegroundColor = "Yellow"
$location = Get-Location
$host.UI.RawUI.ForegroundColor = "White"
"PS $location> "
}
function prompt {
$executionTime = (Get-Date) - $global:LASTEXITCODE
"PS [Exec Time: $($executionTime.TotalSeconds) sec] " + (Get-Location) + "> "
}
function prompt {
$user = $env:USERNAME
$hostname = $env:COMPUTERNAME
"[$user@$hostname] PS " + (Get-Location) + "> "
}
function prompt {
$psVersion = $PSVersionTable.PSVersion
"PS [v$psVersion] " + (Get-Location) + "> "
}

(Get-Command Prompt).ScriptBlock

function prompt {
  "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) ";
  # .Link
  # https://go.microsoft.com/fwlink/?LinkID=225750
  # .ExternalHelp System.Management.Automation.dll-help.xml
}

about_prompts - PowerShell | Microsoft Learn

function prompt {
  $identity = [Security.Principal.WindowsIdentity]::GetCurrent()
  $principal = [Security.Principal.WindowsPrincipal] $identity
  $adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator

$(if (Test-Path variable:/PSDebugContext) { '[DBG]: ' }
    elseif($principal.IsInRole($adminRole)) { "[ADMIN]: " }
    else { '' }
  ) + 'PS ' + $(Get-Location) +
    $(if ($NestedPromptLevel -ge 1) { '>>' }) + '> '
}
function prompt {
   # The at sign creates an array in case only one history item exists.
   $history = @(Get-History)
   if($history.Count -gt 0)
   {
      $lastItem = $history[$history.Count - 1]
      $lastId = $lastItem.Id
   }

$nextCommand = $lastId + 1
   $currentDirectory = Get-Location
   "PS: $nextCommand $currentDirectory >"
}

function prompt {"PS [$env:COMPUTERNAME]> "}

function Prompt {
    $env:COMPUTERNAME + "\" + (Get-Location) + "> "
}

function prompt { # Get the last command execution time if ((Get-History).Count -gt 0) { $lastCommand = Get-History -Count 1 $executionTime = ($lastCommand.EndExecutionTime - $lastCommand.StartExecutionTime).TotalMilliseconds $executionTimeString = "{0:N2} ms" -f $executionTime } else { $executionTimeString = "N/A" }

# Get the last exit code
$lastExitCode = $global:LASTEXITCODE

# Determine admin status
$adminCheck = [Security.Principal.WindowsPrincipal]::new([Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
$adminStatus = if ($adminCheck) { "[Admin]" } else { "[User]" }
$adminColor = if ($adminCheck) { "Red" } else { "Green" }

# Get current time
$currentTime = Get-Date -Format "HH:mm:ss"

# Get computer and user name
$computerName = $env:COMPUTERNAME
$userName = $env:USERNAME

# Get current path
$currentPath = Get-Location

# Get nested prompt level
$nestedPromptLevel = if ($nestedPromptLevel -gt 0) { "[$nestedPromptLevel]" } else { "" }

# Get Git branch if applicable
$gitBranch = ""
if (Test-Path .git) {
    $gitBranch = " ($(git branch --show-current))"
}

# Construct the prompt
$promptLine1 = "$executionTimeString | Exit: $lastExitCode"
$promptLine2 = "$adminStatus $currentTime [$computerName\\$userName] $currentPath$nestedPromptLevel$gitBranch> "

# Display the prompt
Write-Host $promptLine1 -ForegroundColor Cyan
Write-Host $promptLine2 -ForegroundColor $adminColor -NoNewline

return " "

}

Example usage

prompt


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment