Set-Prompt.ps1
<#PSScriptInfo
.VERSION 1.0 .GUID 46b4e057-552c-4c00-aa7b-5abb481a77db .AUTHOR Mosser Lee .COMPANYNAME PStips.NET .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI http://www.pstips.net/override-prompt-function.html .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .DESCRIPTION Custom the prompt style for PowerShell console. #> Param() <# .Synopsis Override default prompt function. #> Function Prompt() { switch ($PSPromptMode) { 'Cmd' { "$($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) " } 'Arrow' { '> ' } 'None' { ' ' } 'Simple' { 'PS> ' } 'NewLine' { Write-Host("PS: $pwd>") } Default { "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) " } } } <# .Synopsis Set the style of console prompt. .DESCRIPTION Set the style of console prompt, supported styles: Normal,Cmd,Arrow,Simple,None,NewLine #> Function Set-Prompt { param( [Parameter(Mandatory=$true)] [ValidateSet('Normal','Cmd','Arrow','Simple', 'None','NewLine',IgnoreCase = $true)] $Mode ) $varPSPromptMode = (Get-Variable 'PSPromptMode' -ea SilentlyContinue) if ( $varPSPromptMode -eq $null) { New-Variable -Name 'PSPromptMode' -Value $Mode -Scope 'Global' $varPSPromptMode = Get-Variable -Name 'PSPromptMode' $varPSPromptMode.Description ='Host configuration for custom console prompt.' $varPSPromptModeAtt = New-Object System.Management.Automation.ValidateSetAttribute('Normal','Cmd','Arrow','Simple','None','NewLine') $varPSPromptMode.Attributes.Add($varPSPromptModeAtt) $varPSPromptMode.Options = 'ReadOnly, AllScope' } Set-Variable -Name PSPromptMode -Value $Mode -Force } |