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"?>
<PSSnapIn Name="Pscx" />
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 –
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
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
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.