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:
- Start the Server Manager and select the option to add a feature.
- Select PowerShell as the feature to be added and click Next.
- 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)
Once the above steps are complete, PowerShell will be available available on your Windows Server installation .
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:
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:
- In your text editor, enter the command text for the aliases, variables, functions and any other command elements you wish to include.
- Save the file with the .ps1 extension eg. Profile.ps1.
- 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
- 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
- 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
- All Users, PowerShell Console : Profile which is applicable to all users but specific to just the PowerShell console.
- All Users, PowerShell ISE : Profile which is applicable to all users but specific to just the PowerShell application.
- All Users, All Hosts : Profile which is applicable to all users for both the PowerShell application and the PowerShell.