Install PowerShell on Windows Server 2008

By default, PowerShell is not installed on versions of  Windows Server prior to Windows Server 2008 R2. For Windows Server 2008 and 2008 R2   the installation binaries are included with OS to simplify installation (for other versions of Windows you will need to download the binaries here). It should be noted that PowerShell is not confined to use on Windows Server operating systems – it can also run on consumer versions such as Windows 7, Vista and XP)

In terms of prerequisites, PowerShell only has one key requirement  .NET version 2.0 or above. In Windows Server 2008 and most recent versions of Windows operating systems, the .NET Framework is installed by default. In Windows Server 2008 and 2008 R2, PowerShell is an optional feature that can be installed   using either  Server Manager, or as part of an unattended installation.

Install PowerShell using the Server Manager  as follows:

  1. Start the  Server Manager  and  select the option to add a feature.
  2. Select PowerShell as the  feature to be added and click Next.
  3. Wait for the installation to complete.

Since PowerShell is an Operating System feature, the installer will place PowerShell’s core components in the %systemroot%\system32\windowspowershell\vx.xx folder (with x.xx being the version of PowerShell which was installed). In addition, the installer also  adds  help files, formatting XML,  ”getting started” docs, plus a sample profile file to this location.
As PowerShell is a managed application using  the .NET Framework, the installer also installs PowerShell’s core binaries in the .NET GAC (Global Assembly Cache).

Installing PowerShell will also update the Registry as follows:

  • Three new file types   added to HKEY_CLASSES_ROOT. These  are .ps1xml (PowerShell display XML), .ps1 (PowerShell script files), and .psc1 (PowerShell Console).
  • The installation  also populates  Registry key: KEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1.
  • The installer changes the system path to include %systemroot%\system32\WindowsPowerShell\vx.x (with x.x being the PowerShell version number)

Starting PowerShell

Once the above steps are complete, PowerShell will be available available on your Windows Server installation .


Getting Started with Profiles in PowerShell

PowerShell profiles end in a .ps1 file extension. Normally, profiles are always  loaded when working with PowerShell, However, there are several exceptions. When testing a script, you may want to invoke PowerShell  but not load a profile and then run the script, this will help ensure that  the script is properly coded and doesn’t use profile-specific settings.

Profiles can be used to store frequently used elements, including:

  • Aliases : Alias is an alternate name for a function, command, file, script, executable, or any other command element. After  an alias is created, it can be used as a keystroke shortcut or friendly name to call the designated command element. For example, gsv is the alias for Get-Service, and instead of entering get-service winrm to get info regarding WinRM, simply enter gsv winrm. For a listing of  all the available aliases, enter get-alias at the prompt.
    Get-Alias [-Exclude Strings] [[-Name Strings] |
    [-Definition Strings]] [-Scope String]
  • Functions  : Functions are named sets of PowerShell commands. When a function is called using its name, the set of commands runs as though they had been individually typed into the command line. For example, a function can be created to examine critical services and processes  on a machine and generate a report. By adding this function to a profile, it can then be run at any time by entering the function name at the PowerShell prompt.


Creating Profiles in Windows PowerShell

A  profile can be created in PowerShell  using a basic text editor. To create a profile enter the commands which define the aliases, variables, functions, or other elements you want to use, and save the file with a .ps1 extention in the appropriate location on your computer. The following is a detailed walkthrough:

  1. In your text editor, enter the command text for the aliases, variables, functions and any other command elements you wish to include.
  2. Save the file with the .ps1 extension eg. Profile.ps1.
  3. Copy the .sp1 file to the appropriate location, eg the  $pshome folder.

There are six different types of  Powershell profiles:

  • Current User, PowerShell Console : Profile specific to the current  user account and is only applicable to the PowerShell console.
    Location –  $home\[My ]Documents\WindowsPowerShell
    Name: profile.ps1
  • Current User, PowerShell ISE : Profile specific to the current user account for the current user context and is only applicable to the PowerShell application.
    Location: $home\[My ]Documents\WindowsPowerShell
    Name: Microsoft.PowerShellISE_profile.ps1
  • Current User,All Hosts : Profile specific only to the current user context  and is applicable to the PowerShell application as well as the PowerShell console.
    Location: $home\[My ]Documents
    Name:  profile.ps1
  • All Users, PowerShell Console : Profile which is applicable to all users but specific to just the PowerShell console.
    Location: $pshome
    Name: Microsoft.PowerShell_profile.ps1
  • All Users, PowerShell ISE : Profile which is applicable to all users but specific to just the PowerShell application.
    Location: $pshome
    Name: Microsoft.PowerShellISE_profile.ps1
  • All Users, All Hosts : Profile which is applicable to all users for both the PowerShell application and the  PowerShell.
    Location: $pshome
    Name: profile.ps1