Useful AWS powershell profile prompt

With having a number of AWS accounts to manage you might find yourself lost as to what account and or credentials you are currently using.

The below function when added to you profile.ps1 will modify your powershell prompt with the current shell AWS credentials and region you are using and add a bit of color to it to help you see it.

So when executing AWS commands you “shouldn’t” get lost as to what account you’re in.

 

It will also remove it if you open up a normal PowerShell window and don’t have any AWS Credentials loaded in the session.

 

function prompt 
{
 $realLASTEXITCODE = $LASTEXITCODE

 $prompt = ""
 $prompt1 = ""
 $prompt2 = "PS "
 if ($StoredAWSCredentials -ne $null)
 {
    $prompt1 += "$StoredAWSCredentials"
 }
 
 if ($StoredAWSRegion -ne $null) 
 { 
    $prompt1 += "@"
    $prompt1 += "$StoredAWSRegion"
    $prompt1 += " "
 }
 
 $prompt += $pwd.ProviderPath
 $prompt += ">"

 $global:LASTEXITCODE = $realLASTEXITCODE
 Write-Host $prompt2 -nonewline -foregroundcolor Green
 Write-Host $prompt1 -nonewline -foregroundcolor Yellow
 Write-Host $prompt -nonewline -foregroundcolor Green
 Write-Output " "
}

 

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s