PowerShell Console Files and building an Administration Console

There are two ways to configure PowerShell. Profiles are scripts that run when a PowerShell console is started. There are four profile files which are documented in the PowerShell documentation pack. Profiles are in effect scripts that run as PowerShell starts. These profiles run automatically assuming that your execution policy is set to allow scripts to run.

Console files – are xml files that have an extension .psc1. They store configuration settings for a particular console. For example this is a console file produced from my current configuration

<?xml version="1.0" encoding="utf-8"?>

<PSConsoleFile ConsoleSchemaVersion="1.0">

<PSVersion>1.0</PSVersion>

<PSSnapIns>

<PSSnapIn Name="Pscx" />

</PSSnapIns>

</PSConsoleFile>

This adds the Snapin for the PowerShell Community Extensions to my default PowerShell configuration.

A console file can be produced by use the following cmdlet –

Export-Console filepath_for_console_file.psc1

Full details of Export-Console can be found by using

Get-Help Export-Console -full

Ok so this is all well and good but what does it mean for us in practice. If you have installed the Exchange 2007 Administration Tools you will know that a specific PowerShell console is available from the Start Menu. This console consists of the base PowerShell console with the Exchange Management Shell Snapin layered on top. If you look at the command used to start this shell you can see that it uses a PowerShell Console file for the configuration. The command is:

C:WINDOWSsystem32WindowsPowerShellv1.0PowerShell.exe -PSConsoleFile "C:Program FilesMicrosoftExchange Serverbinexshell.psc1" -noexit -command ". ‘C:Program FilesMicrosoftExchange ServerbinExchange.ps1’"

As you can see it starts a normal PowerShell console but adds in the extras via a PowerShell Console file. This explains why when you install Exchange 2007 PowerShell is a pre-requisite but after the installation you have access to pure PowerShell and the Exchange Management Shell that contains the additional Exchange specific PowerShell commands. I don’t particularly like the idea of having multiple versions of PowerShell available on a machine. It’s just too confusing. I want a single version of PowerShell on a machine that contains all of the commands I need to administer that environment. This situation will become more complicated as further products are released that utilise PowerShell.

The console file shows us which snapin is being loaded to create the customised shell. If you then go to the basic PowerShell console and use

Get-PSSnapin –registered

It will show you the Snapins that are available. All Snapins on a machine are available to all consoles though they might not be installed in a particular console. You can then use

Get-PSSnapin snapin_name

Which will load the particular snapin you need. This enables you to create a single console with all of the functionality you need.

You will also need to check any scripts that run when a customised console such as Exchange starts up and copy any needed parts into your profile.  

About these ads
This entry was posted in Powershell. Bookmark the permalink.

3 Responses to PowerShell Console Files and building an Administration Console

  1. Shay says:

    Hey Richard
     
    Multiple shells can be a pain.
    Im loading the Exchange Management Shell Snapin into powershell  with this line in my profile:
     
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
     
    I find it much shorter and flexible.
     
     

  2. Richard says:

    I totally agree.  Its so much easier to have a single console with everything in place.  One of the beaties of the Snapin model is that it makes this so easy

  3. victormr88 says:

    Im doing a Transport Agent for Exchange and I try RunspaceConfiguration rc = RunspaceConfiguration.Create(); PSSnapInException snapEx = null; PSSnapInInfo info = rc.AddPSSnapIn ("Microsoft.Exchange.Management.PowerShell.Admin", out snapEx); Runspace myRunSpace = RunspaceFactory.CreateRunspace(rc); myRunSpace.Open(); the problem is in the ADDSnapin… I can’t do it because If I do I have this problem :The process ‘EdgeTransport’ (PID = 200) has been initialized twice as Multiple instance type in the way we don’t understand: current App Name is ‘Transport’ and to-be-set App Name is ‘EMS’. How I can solve? have some idea?… I’m searching for configure the PowerShell profile, for .. everytime that I run the Powershell I will not to do Add-Snapin … some idea? Thanks

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