Creating and Changing a Powershell profile

In the previous tutorial, we showed you how to change your window size and colors of background and text. If you are not familiar with the previous tutorial, please look into it. You may have noticed that when you closed your window, the changes were not saved. This tutorial will show you how to have these settings saved and make them the default settings every time you open PowerShell.

Setup

If you have not already done so, open Windows PowerShell. If you are a frequent user, it should most likely show up on the most used programs list. Go ahead and open Windows PowerShell Command Shell.

Also, you will need notepad open as well.

Step one.

How to determine if you have a profile? Simple, in the command shell, type in:

Example


    $profile

Copy and Try it

Your profile will then be listed. It would normally resemble something like this:

Example


    Users\Your.Name\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

    PSH’s ISE has its own profile script, which is in the same
    location as the regular profile script by default. The only exception is
    that it is called: <br />

    <pre lang="powershell">

    Microsoft.PowerShellISE_profile.ps1
 

Copy and Try it

If you so happen to have an existing profile, open it up in Notepad; otherwise create a blank text file using Notepad in the pointed located by the profile command. The profile, in reality, is simply a PSH script that gets executed whenever a shell is launched.

If you are going to create a profile file, you will need a Windows PowerShell folder in your Documents folder if it doesn't already exist of course.

Example

$Shell = $Host.UI.RawUI 
$Shell.WindowTitle="I Rule PowerShell" 
$Shell.BackgroundColor="Blue" 
$Shell.ForegroundColor="White" 
$size = $Shell.WindowSize 
$size.width=125 
$size.height=60 
$Shell.WindowSize = $size 
$size.width=200 
$size.height=3000 
$Shell.BufferSize = $size 
Clear-Host

    

Copy and Try it

Step two.

Save this file and open a new PowerShell window. You will then be confronted with an error. No worries, this is simply Microsoft's way of protecting you. PowerShell has the ability to allow its users to make malicious scripts and deliver them for others to run. Most of the scripts are of course disabled with the proper settings placed in PowerShell. PSH will not let you run any script, not even your profile, unless it has been signed using a trusted certificate issued by a Certificate Authority or a self-generated certificate using the Microsoft .NET Framework Software Development Kit (SDK).

For now, to get rid of the error to run your own script and see how it looks like, simply run the following command:

Example


    Set-ExecutionPolicy RemoteSigned

    

Copy and Try it

And by default the execution policy is Restricted. In other words, no scripts can run and only interactive commands are allowed. Again, it is for your own protection as well as others.

Once this has taken place, close the current PSH window and open a new one, you will see the title, color and window size change at once.

Remarks last but not least…

Remember, the RemoteSigned command only works for locally stored scripts. By saving these changes to your profile, it will automatically save your settings as default and load PSH with these settings. Saves you from having to change them all the time! Join us next time for more PSH tutorials! Till then…