Hi, I’m another novice PowerShell user looking to get some help as I try to familiarize myself with the basics.
I’m using a version of the following code (that I found online) to be able to switch between different prompt styles.
What I’d like to know is, how can I create a function to “query” (don’t know if that’s the right term) which prompt style is currently being used and display its name on screen?
In other words, I’d type a command (for example, something like get-prompt
or whatever) and it would then tell me the name of the currently active prompt style (as currently defined by set-prompt
).
I can think of many instances where this type of thing would be useful, so finding out how to do it for this set-prompt example would give me a template for how it could be applied to other situations.
Unfortunately, despite lots of reading on various sites, I still don’t really know where to start with this.
Hopefully someone can help. Thanks.
Function Set-Prompt
{
Param
(
[Parameter(Position=0)]
[ValidateSet("Default","Basic","Other")]
$Action
)
switch ($Action)
{
"Basic"
{
Function global:prompt
{
$Null
}
}
"Other"
{
function global:prompt {
#check and see if logon server is the same as the computername
if ( $env:logonserver -ne "\\$env:computername" ) {
#strip off the \\
$label = ($env:logonserver).Substring(2)
$color = "Green"
}
else {
$label = "Not Connected"
$color = "gray"
}
Write-Host ("[$label]") -ForegroundColor $color -NoNewline
Write (" PS " + (Get-Location) + "> ")
}
}
default
{
Function global:prompt
{
$(if (test-path variable:/PSDebugContext) { '[DBG]: ' }
else { '' }) + 'PS ' + $(Get-Location) `
+ $(if ($nestedpromptlevel -ge 1) { '>>' }) + '> '
}
}
}
}