Wednesday, May 6, 2009

PowerShell 2.0: Introduction

PowerShell is a command line tool used to manage Windows based computers. Ok, that's a beautiful theoretical definition...

Theory is good but practice is sometimes better ! So let's go !

Oh, just another thing ! For my first post, we will set up our environment to test our PowerShell script.

PowerShell current version is 1.0 however we will use PowerShell 2 ! (Which is actually in CTP3 version). This new version is just awesome : we will play with some cool features !

So, the first thing to do is to check prerequires !
Operating system version has to be at least Windows XP SP3 or Windows Server 2003 SP2. To use some PowerShell V2 features we need at least Windows Vista SP1 or Windows Server 2008.

Next, we have to uninstall PowerShell 1.0 if installed and download then install the following prerequires :
1. .NET Framework 2.0 : PowerShell is based on .NET Framework !
2. Framework .NET 3.5.1 : if we want to use PowerShell Integrated Script Environment (ISE)... And we want !
3. PowerShell V2 CTP3 : our command line tool and its editor (ISE) : all in one !
4. WinRM 2.0 CTP3 : for remoting ! Because it is cool to manage thousand of computers from the sofa...

After having installed theses components observing order we can start to play !

Well, maybe we have to configure some component in order to use the coolest feature of PowerShell V2 : remote management using WinRM 2.0 !

WinRM is an implementation of WS-Management protocol by Microsoft. It is used to manage computer using HTTP as transport protocol (which can be secured with HTTPS).

In fact, WinRM is a Windows service installed on the computer : we have to start it before using PowerShell V2 remote management features.

So, in a PowerShell session running as local Administrator, execute the following command to start WinRM service :

PS> Start-Service WinRM

Now, we can use the PowerShell V2 WinRM provider to configure the remote management.

PowerShell V2 is a client and a server. In other terms, we need PowerShell V2 installed and configured on the local machine and the remote machine !

Well, stop talking and let's configure the port used to listen requests and the protocol to use :

PS> cd WSMan:\localhost\Listener                          
PS> New-Item –Path . –Address * -Transport HTTP –Port 8080

PowerShell will use HTTP as transport protocol, the port 8080 and will listen on all interfaces. If an other application uses the same port (as a web server) there is no problem because WinRM shares the port.

This configuration has to be done on all managed computers.

Now, we are ready to start playing with our tool.
You will discover PowerShell V2 across posts on this blog and how to use it in your production environment.

See you soon !

No comments:

Post a Comment