Take Command of Server 2008 with Windows PowerShell – Part 3By Jason Ensinger
Welcome to part three of taking command of Server 2008 with Windows PowerShell!
If you missed those two articles, I would suggest reading them first — just to make sure you’ve got all the basics. Now let’s get started with an exercise in customizing your Windows PowerShell.
Customizing Windows PowerShell
Windows PowerShell starts with the same look and feel of the Command Prompt, by default. Let’s make our first exercise of PowerShell power be to customize the PowerShell console.
The steps below will walk you through customizing the console options then saving those settings to be used every time PowerShell is launched.
1. Open Windows PowerShell
2. Create a variable to the PowerShell RawUI object with the command below:
$psui = (get-host).UI.RawUI
3. Use the $psui variable to change the background and text colors with the commands below:
$psui.WindowTitle = “PowerShell PowerStation” $psui.BackGroundColor = “Blue” $psui.ForeGroundColor = “Yellow”
Note: The PowerShell console supports 16 colors. They are; Black, White, Blue, Cyan, Gray, Green, Magenta, Red, Yellow, DarkBlue, DarkCyan, DarkGray, DarkGreen, DarkMagenta, DarkRed and DarkYellow.
4. Use the cls command to clear the console and fill the console with the background color specified
5. View the other properties available to the object by entering $psui
Note: If you wish to change RawUI objects with multiple properties such as the BufferSize property you must assign the property to another variable to modify the object’s properties like the example below:$psbs = $psui.BufferSize $psbs.Height = 3000 $psbs.Width = 120
6. Decide on how you want to customize the PowerShell console with the properties available
7. Open your PowerShell Profile with notepad with the command below:
8. Assuming that you are running Server 2008 and this is the first time creating a PowerShell profile, Notepad should display an error that the file was not found.
Click Ok to close the error and return to PowerShell to rectify the problem.
9. Try using the command below to create the profile file:
create-item $profile –type “file”
10. The previous command attempts to create the profile file under your ‘Documuents\Windows PowerShell’ directory, but with no Windows PowerShell directory, no file was created
11. Use some PowerShell power to create the directory then the profile file by entering the commands below:
new-item $profile.SubString(0, $profile.LastIndexOfAny(“\\”)) create-item $profile –type “file”
Note: If you have any experience with the .NET framework the first command of this step should look familiar. It utilizes the methods of the string object to parse the profile path out of the profile variable.
12. Open the newly created file by entering
notepad $profile again
13. Enter the property changes as you would in PowerShell into the profile file. Below is an example of the contents of a profile file with the same setting examples in these steps:
$psui = (get-host).UI.RawUI $psbs = $psui.BufferSize $psui.WindowTitle = “PowerShell PowerStation” $psui.BackGroundColor = “Blue” $psui.ForeGroundColor = “Yellow” $psbs.Height = 3000 $psbs.Width = 120 cls
14. Click File | Save to save the changes to the profile
If script execution is enabled, when you launch PowerShell it will automatically start with the configuration set in the profile file. If not enabled, proceed to the next section for information on enabling it.
This example only covers customizing the PowerShell console window. Keep in mind that any variables or functions you define in the profile file will be automatically available for use when you launch PowerShell.
This is it for today! Next week we’ll go into PowerShell scripting — so don’t miss the last article of taking command of Server 2008 with Windows PowerShell. See you next week!
About the Author
Jason Ensinger (A+) is experienced in both IT and development. He has completed training in computers, electronics and networking and obtained his A+ certification. Jason is a self-taught developer and over half of his career in technology has been in web and Windows development, while the rest has been IT orientated. He hopes to be able to use his cross industry expertise to be able to shed more light on the exciting life of a developer for those in IT considering making the move to software. Jason has written articles on various topics including SharePoint, CompTIA A+, and Windows Server 2008.
- Take Command of Server 2008 with Windows PowerShell – Part 2
- Take Command of Server 2008 with Windows PowerShell – Part 1
- 10 Steps to Installing the Web Server Role in Windows Server 2008
- 4 Improved Security Features in Windows Server 2008
- Windows Server 2008 (codename Longhorn) Certification Update
- Windows Server 2008 Certifications – Death to the MCSE
- How to Configure and Manage OWA on Exchange Server 2007
- Streamlining Functionality in IIS 7.0 with AppCmd.exe
- 5 Essential Administration Tasks for Exchange Server 2007
- Windows Vista Features that I Like, Part 2 – Windows Search