Like the standard PowerShell window, the SharePoint Management Shell, can be customized to fit your personal style. To see this in action, open up the SharePoint Management Shell and enter the following line:

$Host

Figure 1.1

$Host is an Automatic Variable to the console host object. When you type in a variable name into the Shell window, PowerShell will return the value of that object or properties. Notice the value returned for UI. You should see System.Managmeent.Automation.Internal.Host.InternalHostUserInterface. Now enter the following line:

$Host.UI

Figure 1.2

 

You should get a response that references the RawUI object. We will now modify the appearance of our SharePoint 2010 Management Shell by changing the properties of the RawUI object. To do this, we will assign the RawUI object to a variable. This will allow us to access this object without having to type the entire name of $Host.UI.RawUI. In order to do this, type the following line:

$SPShell = $Host.UI.RawUI

We can now access this object simply by typing $SPShell in the window.

Figure 1.3

 

Notice that we see several items returned. Of these, the ones of interest to us now will be: ForegroundColor, BackgroundColor, and BufferSize.

ForegroundColor will change the color of the text. BackgroundColor will change the color of the background. BuzzerSize contains a height and width properties that will change the size of the screen. The PowerShell window is restricted to the number of characters that fit across the width and height. These values are stored in an object called WindowSize.

Figure 1.4

 

We will now modify the fore mentioned colors and the screen size. Enter the following lines:

$SPShell.BackgroundColor=”White”

$SPShell.ForegroundColor = “Blue”

Clear-Host

Figure 1.5

 

Your SharePoint 2010 Management Shell should look like figure 1.x. From here, we will modify the size of the window and the title.

$size = $SPShell.WindowSize

$size.width = 100

$size.height = 50

$SPShell.BufferSize = $size

$SPShell.WindowTitle = “PowerShell V2 for SharePoint 2010”

Figure 1.6

 

Now that you have successfully modified your environment, close it and reopen it. You will see that everything has returned to its original state. This is because the changes you make are not persisted. If you want to modify your environment and keep these changes, you will need to create or modify the PowerShell profile file.

Profiles in PowerShell

 

Your PowerShell environment is configured with the use of Profile files located throughout the file system. Type the following into your Shell window:

$Profile

Figure 1.7

This will return the profile location that applies to the current user, but only the Microsoft.PowerShell. You have three other profile locations to choose from.

  • %UserProfile%My DocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1
  • %UserProfile%My DocumentsWindowsPowerShellprofile.ps1
  • %windir%system32WindowsPowerShellv1.0 Microsoft.PowerShell_profile.ps1
  • %windir%system32WindowsPowerShellv1.0profile.ps1

The second file listed will only affect the current user, but will be applied to all of the Shells. The second applies to all users on the system, but only the Microsoft.PowerShell. Finally, the fourth location applies to all users and all shells.

We will focus on the first file. You will need to create the first location, as it is not created by default. To do this, simply create a folder named WindowsPowerShell in the My Documents location.

Figure 1.8

 

You may now create a text file similar to the one below and save it as Microsoft.PowerShell_profile.

Figure 1.9

Once this file is saved, you will be able to open up the SharePoint 2010 Management Shell and see the customized environment.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

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