Beruflich Dokumente
Kultur Dokumente
about_Prompts
SHORT DESCRIPTION
Describes the Prompt function and demonstrates
how to create a custom
Prompt function.
LONG DESCRIPTION
The Windows PowerShell command prompt indicates
that Windows PowerShell
is ready to run a command:
PS C:\>
For example:
(get-item function:prompt).definition
PS>
function prompt
{
$(if (test-path variable:/PSDebugCont
ext) { '[DBG]: ' }
[DBG] PS C:\ps-test>
PS C:\ps-test>
[DBG] PS C:\ps-test>>>
function prompt { }
PS [Server01] >
01/01/2008 17:49:47>
function prompt
{
$(if (test-path variable:/PSDebugCont
ext) { '[DBG]: ' }
function prompt
{
$identity = [Security.Principal.Windo
wsIdentity]::GetCurrent()
$principal = [Security.Principal.Wind
owsPrincipal] $identity
elseif($principal.IsInRole([Security
.Principal.WindowsBuiltInRole] "Administrator"))
{ "[ADMIN]: " }
else { '' }) + 'PS ' + $(Get-Locatio
n) + $(if ($nestedpromptlevel -ge 1) { '>>' }) + '
> '
}
[ADMIN]: PS C:\ps-test>
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
{
$color = get-random -min 1 -max 16
write-host ("PS " + $(get-location)
+">") -nonewline -foregroundcolor $color
return " "
}
SEE ALSO
Get-Location
Enter-PSSession
Get-History
Get-Random
Write-Host
about_Profiles
about_Functions
about_Scopes
about_Debuggers
about_Automatic_Variables