DESKTOP

Windows Server 2008 R2 : PowerShell V2 feature focus - Installing Powershell, Introduction to Powershell Scripting

2/27/2014 1:59:45 AM

Installing Powershell

The most important thing that needs to be done before PowerShell can be used is to make sure it is installed, and if it is not, you need to download and install it. If you have Windows 7 or Windows Server 2008 R2, then you do not have to do anything. They both include PowerShell 2.0. If you do not have Windows 7 or Windows Server 2008, however, then you will most likely need to download and install PowerShell yourself. Installing PowerShell is simple, but first, you will check to see if it is already there. By far, the easiest way to check is to open a run window. You do this by clicking on the start menu → run. This will bring up a dialogue box, now type PowerShell and hit enter. If a command window comes up, then you have PowerShell. Now, you check to see if you have the latest version. The easiest way is to run PowerShell, and then when the shell comes up, you type Get-help about_Windows_PowerShell_2.0.

If the command runs, then you have PowerShell version 2.0. If you do not have PowerShell at all or if you do not have the latest version, then you need to go and install it.

Before you install it, you need to make sure that the minimum system requirements are met. WinRM 2.0 and Windows PowerShell 2.0 can be installed on the following operating systems:

  • Windows Server 2003 Service Pack 2

  • Windows Server 2008 Service Pack 2

  • Windows XP with Service Pack 3

  • Windows Vista Service Pack 1 or later

In addition, Windows PowerShell requires the .NET framework with service Pack 1 to function, so that needs to be installed as well.

The recommended steps are as follows:

1.
Uninstall previous versions of Windows PowerShell from your computer.

2.
Uninstall previous versions of WinRM from your computer.

3.
Download and install the latest version of PowerShell 2.0 from http://support.microsoft.com/kb/968929

Introduction to Powershell Scripting

The mere mention of the word “scripting” sends many brave administrators running for the hills. Brave souls immediately pick up the phone and call their programmer friend. It does not have to be this way. PowerShell scripting is easy to grasp. In addition, PowerShell has easy help available for anything you need to use. I am not talking about online help, but built in, though it does have an online help option now in version 2.0 as well. Once you have PowerShell installed on your system, just open and run it. A window that looks a lot like a dos window should pop up. Now, you will type in a command. The way you issue commands to PowerShell is to type in a command and then hit enter. A commandlet or cmdlet is basically a windows PowerShell command. cmdlets are what allow you to accomplish what you want with PowerShell. All cmdlets follow a specific naming convention of “verb-noun” which makes them easier to learn and use.

The most important cmdlet in PowerShell is get-help. This cmdlet alone can get you the tools you need to get out of any bind. You can type Get-help followed by any PowerShell cmdlet to get some meaningful information about them. An alternative to the get-help cmdlet is the man command. It behaves just like the get-help cmdlet but will pause the screen for you and display a page at a time instead of displaying all the information at once.

To make sure you are ready to execute cmdlets, run scripts, and import modules in PowerShell, you want to make sure that your execution policy will let you run the cmdlets that you need. By default, the execution policy is set to restricted. You need to set it to RemoteSigned at the very least. RemoteSigned will allow you to run any script you write as well as any downloaded script that has been signed by a trusted publisher. The way you check your execution policy using the Get-ExecutionPolicy cmdlet is as follows:

Startup PowerShell as administrator. You will need to have administrator rights to change the execution policy.

Type Get-ExecutionPolicy. This command should return your current execution policy which will, by default, be Restricted. Your goal is to change it to RemoteSigned.

Type Set-ExecutionPolicy RemoteSigned. When the cmdlet runs, it will give you a warning that you are changing the Execution Policy and a confirmation dialogue (see Figure 1). The default is Yes, so just hit enter. Voila, you have just changed your execution policy to RemoteSigned. You can verify this by typing Get-ExecutionPolicy at the PowerShell prompt. Your new execution policy should show up as RemoteSigned if you did everything properly and this means that you are ready to proceed.

Figure 1. Changing Policy from Restricted to RemoteSigned.

PowerShell lets you write cmdlets one line at a time and hit enter just like a command line shell, but one of the main advantages is the ability to write scripts. Throughout these sections, you will see several steps illustrating how something is done. Everything is done in a step-by-step manner simply for illustration purposes. All these things could have been done by writing them in a text file, naming the file with a .ps1 extension, and simply calling the file. The file would be treated as if you were typing all the cmdlets in at the prompt. This is one of the biggest advantages of PowerShell. You write it once and then can use it multiple times whenever you need it. This eliminates the human error inherent in mindless repetition as well as making it easier to share solutions with other administrators.

Other  
  •  Windows Server 2008 R2 : PowerShell V2 feature focus - Introduction to Powershell
  •  Installing Windows 8 on startup VHD files (part 3) - Starting the system from the VHD, Removing VHD installations
  •  Installing Windows 8 on startup VHD files (part 2) - Creating the VHD during the installation by using DiskPart
  •  Installing Windows 8 on startup VHD files (part 1) - Creating a VHD from an existing installation
  •  Windows 8 : Upgrading or migrating from a previous version of Windows (part 4) - Migrating user data
  •  Windows 8 : Upgrading or migrating from a previous version of Windows (part 3) - Using an external hard disk or USB flash drive, Using the User State Migration Tool
  •  Windows 8 : Upgrading or migrating from a previous version of Windows (part 2) - Using removable media, Using a network connection
  •  Windows 8 : Upgrading or migrating from a previous version of Windows (part 1) - Running the Setup Wizard , Configuring your account
  •  Installing Windows 8 on a new or formatted system (part 3) - Installing Windows 8 with Windows To Go
  •  Installing Windows 8 on a new or formatted system (part 2) - Configuring your account
  •  
    Top 10
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    3 Tips for Maintaining Your Cell Phone Battery (part 1) - Charge Smart
    OPEL MERIVA : Making a grand entrance
    FORD MONDEO 2.0 ECOBOOST : Modern Mondeo
    BMW 650i COUPE : Sexy retooling of BMW's 6-series
    BMW 120d; M135i - Finely tuned
    PHP Tutorials : Storing Images in MySQL with PHP (part 2) - Creating the HTML, Inserting the Image into MySQL
    PHP Tutorials : Storing Images in MySQL with PHP (part 1) - Why store binary files in MySQL using PHP?
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS