Subscribe

Powershell Prompt

I use the Powershell Tookit a LOT, to the point now where I do most of my controller management via Powershell. One issue I have doing this though is sometimes I'm not sure what controller I'm connected to. I wrote the following code blurb to help me always know what controller I'm connected to:

Edit your Powershell profile file ([my documents]\WindowsPowershell\profile.ps1). If this file does not exist, create it, then add this code:

function prompt
{
$label = "Not Connected"
$color = "gray"

if ( (Get-Variable | ? { $_.Name -ieq "currentNaController" }) )
{
if ( $global:currentNaController )
{
$label = $global:currentNaController
$color = "Green"
}
}

Write-Host ("[$label]") -ForegroundColor $color -NoNewline
return (" " + (Get-Location) + "> ");
}

When not connected, you see this:

When Connected, you get this:

I thought someone might find this handy.

Powershell Prompt

Using the toolkit alot: cool

Using the toolkit enough to change your default prompt: priceless

Thanks for the great example!

Re: Powershell Prompt

I have found this handy, but I had trouble getting this to work in Powershell 3.0, but I got it working again by excluding the Get-Variable if statement;

function prompt
{
$label = "Not Connected"
$color = "gray"


if ( $global:currentNaController )
{
$label = $global:currentNaController
$color = "Green"
}

Write-Host ("[$label]") -ForegroundColor $color -NoNewline
return (" " + (Get-Location) + "> ");
}

Hopefully this will save others some pain