Microsoft Virtualization Discussions

Powershell Prompt

bsti

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.

2 REPLIES 2

david_ovenden

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

timothyn

Using the toolkit alot: cool

Using the toolkit enough to change your default prompt: priceless

Thanks for the great example!

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public