THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Buck Woody

Carpe Datum!

PowerShell Demo Prompt

When I teach I have to set my fonts really big so that folks in the back can see. I show PowerShell from time to time, and people keep asking me about my latest prompt.  Here’s what my prompt looks like:

 

{ univac\Buck on UNIVAC using AMD64 }

--    12/23/2009 7:54:10 PM    --

C:\Users\Buck

 

There’s a blank line under there, and all my text is green from there on. Having the prompt this way lets me have a long path display without affecting the display of the commands or their output. Here’s how to do that if you want something similar on your own PowerShell display (Don’t do any of this, of course, until you understand these commands and what their affect will be on your own test system, test before you put into production, all rights reserved, don’t run with scissors, never trust scripts, etc.):

 

You can save the prompt files in your “My Documents” folder by creating a folder underneath called “WindowsPowerShell” if it isn’t there already.

 

In that, set up a text file called “Microsoft.PowerShell_profile.PS1”. That’s your regular PowerShell prompt. For the SQL Server 2008 PowerShell provider, you can create another file called “Microsoft.SqlServer.Management.PowerShell.sqlps_profile.PS1” with a different (or the same) prompt if you like.

 

Note that for all these to work, you need to set your execution policy in PowerShell to at least “Remote Signed”, which lets you run scripts. You can set that with this command:

Set-ExecutionPolicy RemoteSigned

 

Here’s the script that makes it all happen:

 

# Remember - to run scripts you have to use this command as an admin:

# Set-ExecutionPolicy RemoteSigned

 

function prompt {   

$cPath = [ConsoleColor]::Red

$cComputerName = [ConsoleColor]::Cyan

$cTime = [ConsoleColor]::DarkCyan

$cCommand = [ConsoleColor]::Green

 

$host.UI.RawUI.WindowTitle = "PowerShell - $env:computername $pwd" 

   write-host "{"$env:userdomain"\"$env:username" on "$env:computername "using" $env:processor_architecture "}" -f $cComputerName

   write-host "--   " (get-date) "   --" -f $cTime

   write-host ($pwd) -f $cPath

   return ' '

}

Published Thursday, December 24, 2009 8:19 AM by BuckWoody

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(required) 
Submit

About BuckWoody

http://buckwoody.com/BResume.html

This Blog

Syndication

Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement