Created
July 24, 2026 08:54
-
-
Save scriptingstudio/1cc9a68d7315dfd8c0b106e151b2c976 to your computer and use it in GitHub Desktop.
My PowerShell profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function prompt { | |
| function Get-LastCmdTime { | |
| $diffPromptTime = $null | |
| $lastCmd = Get-History -Count 1 | |
| if ($lastCmd -ne $null) { | |
| $diff = $lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime | |
| $msfractional = $diff.TotalMilliseconds - [Math]::Truncate($diff.TotalMilliseconds) | |
| $ms = $msfractional + $diff.Milliseconds | |
| if ($diff.Hours) {'{0}h:{1}m:{2}s:{3:N2}ms' -f $diff.Hours,$diff.Minutes,$diff.Seconds,$ms} | |
| elseif ($diff.Minutes) {'{0}m:{1}s:{2:N2}ms' -f $diff.Minutes,$diff.Seconds,$ms} | |
| elseif ($diff.Seconds) {'{0}s:{1:N2}ms' -f $diff.Seconds,$ms} | |
| else {'{0:N2}ms' -f $diff.TotalMilliseconds} | |
| } | |
| } | |
| $admin = ( ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator') ) | |
| $shellprompt = if ($admin) {'PS$>'} else {'PS#>'} | |
| $lastCmd = Get-LastCmdTime | |
| $lastCmd = if ($lastCmd) {"[$lastCmd] "} else {''} | |
| write-host "`n$lastCmd$($executionContext.SessionState.Path.CurrentLocation)" -ForegroundColor DarkCyan | |
| write-host $shellprompt -NoNewline | |
| return " " | |
| } | |
| Set-PSReadLineOption -AddToHistoryHandler { | |
| param([string]$line) | |
| return $line.Length -gt 3 -and $line[0] -ne ' ' -and $line[-1] -ne ';' | |
| } | |
| if ($psVersionTable.PSVersion.Major -eq 5) { | |
| $OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = [System.Text.UTF8Encoding]::new() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment