Share via


Windows PowerShell: Why You Should Care?

If you're one of the IT Pro guys whose their daily tasks are the administration of a set of desktops, servers, printers and other IT infrastructure components whether its software or hardware, or you're a software developer who develops hundreds of lines of code daily then of course you would always be trying to find a way to automate most of those tasks as much as you can. Actually, when we talk about automation of tasks from IT Professionals' perspective we are talking about the automation of tasks such as managing and troubleshooting Active Directory, DNS, MS Exchange Server 2007, MS Windows Server and the other tools and Products. And from Software Developers' perspective we would be talking about creating a User Interface (UI) test automation scenarios to test your own application easily and faster.

So, how do you think we can do it?? Yes, you're right.  The most appropriate ways for this kind of automation is scripting. Let's remember what script is. Script is a set of computer instructions written using one of the scripting languages (e.g. VBScripts, JavaScript, Perl, and of course PowerShell) that is executed on a sequential basis to do a specific task, for example you can write a script to join a computer domain and create a computer account in an Active Directory for that computer or whatever task. What I want to say is that scripting is a very powerful and important tool for any System administrator who is searching for a way to complete his tasks in less time with less efforts and best performance.

What is PowerShell (previously named Monad)?

Windows PowerShell is a new command-line interface, Dynamic Scripting Environment, new programming language, and an interactive shell which is designed specifically for Windows Platform and Microsoft technologies in order to provide a common management automation platform. Also, Windows PowerShell is designed to drastically reduce the time-to-results with consistent vocabulary and syntax. Moreover, reducing the semantic gap as Jeffrey Snover - PowerShell Architect - said "We wanted to close the semantic gap between what admins thought and what they had to type. "

Windows PowerShell is a powerful automation technology designed not only for IT Professionals but also Developers. Windows PowerShell is available in Windows Server 2008, Windows 7 by default and in the previous versions of windows (XP, Vista, and Server 2003) through optional windows updates.Unlike the other traditional text-based shells that deal with every output as string which requires to parse the output in order to use it as input to another command, PowerShell deals with everything as an object (.NET object) since its built-on .NET Framework and .NET Common Language Runtime (CLR).  Windows PowerShell is now part of Microsoft Common Engineering Criteria (CEC) since 2009 which means that any release for any of Microsoft product will support Windows PowerShell and have PowerShell built-in by default.

Why new scripting language? [Limitations of the current scripting languages]

  • Not providing too much component like Programming.
  • Not supplying Graphical Interface elements (Forms, textboxes, comboboxes , buttons, etc).
  • Not providing advanced programming features like Object Oriented, data binding, threading.
  • Using a lot of third party tools in order to deal with WMI, COM+, and ADSI components.

Why Windows PowerShell?

Since the powerfulness of any shell is measured by its support for pipelining, conditional, and recursive programming (conditional like IF...else statement, recursive like for Loop) and in compare to UNIX shell, Windows Shell was very limited and weak-just command-line console that perform some basic tasks- which doesn't fit administrators' needs and systems complications.

In the past; before windows PowerShell, since MS-DOS (the first MS Shell) the number of technical users was also limited compared to their number today and of course the growth of technology and users needs wasn't too complex like today. For this reason Microsoft started to focus on the non-technical users -the most of computer users - and tended to develop and enhance the Graphical User Interface (GUI). The GUI was introduced in Windows 3.1x with MS-DOS console included in order to provide DOS-Shell in addition to GUI. By the time, the users' needs increased and the IT problems complexity is growing up day to day. As we mentioned, since the basic shell and GUI doesn't fit administrators' needs, the administrators started to find an alternative ways to solve their problems via Scripts and Scripting Languages.

Finally, Microsoft decided that the GUI and the limited shell "CMD.exe" is not enough and their platform need a powerful shell to be designed specifically for Windows environments. Accordingly, they had introduced Windows PowerShell.

 

Why should you (developer) care?

  • PowerShell is based on .net framework and .net Common Language Runtime (CLR).
  • PowerShell is object-based shell.
  • PowerShell can deal easily with WMI, COM+, XML, and ADSI.
  • PowerShell is part of Microsoft Common Engineering Criteria (CEC).
  • Can run .Net code inside PowerShell
  • Can run PowerShell inside managed code
  • Can extend PowerShell and write your own Cmdlets, Modules, and Providers via PowerShell APIs

What makes PowerShell a different shell? (Key features)

  • PowerShell Remoting: Remoting feature allows the execution of PowerShell cmdlets on remote systems which help to manage a set of remote computers from one single machine. Remote execution feature relay-on Windows Remote Management (Win-RM) technology.
  • Background Job: PowerShell introduced the concept of Background Jobs which runs cmdlets and scripts asynchronously in the background without affecting the interface or interacting with the console. Background jobs can run on local and remote machines.
  • Steppable-Pinpline: Allows splitting of script-blocks into a steppable pipeline in order to ease the control of execution sequence.
  • Script debugging: As in Visual Studio now you can set breakpoints on lines, columns, functions, variables, and commands. You can also specify actions to run when the breakpoint is hit. Stepping into, over, or out of functions is also supported. You can also get the call stack.
  • Error-Handling: PowerShell provide Error handling mechanism through Try{ }, Catch{ }, Finally { } statements as in .NET  languages.
  • Constrained Runspace: Constrained Runspaces allows creation of PowerShell Runspaces with a set of Constraints. Constraints include the ability to restrict access and execution of Commands, scripts, and language elements when using the Constrained Runspace.
  • Tab-Expansion: This feature is an implementation of autocompletion that is completing the cmdlets, properties, and parameters once tab button pressed. It is similar to intellisense feature in Visual Studio.
  • Integrated Scripting Environment (ISE): It's a graphical version of PowerShell console that with Graphical User Interface (GUI) that provides a set of features:
    • Syntax Color Highlighting and Unicode Support
    • Open multiple runspace, up to eight runspaces in the same time

Windows PowerShell is now part of:

  • Windows 7
  • Windows Server 2008 including:
    • Active Directory (AD)
    • Active Directory Rights Management Services (AD RMS)
    • AppLocker
    • Best Practice Analyzer (BPA)
    • Background Intelligent Transfer Service (BITS)
    • Failover Cluster
    • Group Policy
    • Server Manager
    • Windows Server Backup
    • Windows Server Migration Tools
    • Internet Information Services (IIS)
    • DNS
    • Remote Registry
    • Terminal Services
    • Hyper-v
  • Windows Embedded
  • Exchange Server 2007, 2010.
  • LYNC
  • SQL Server 2008
  • SharePoint Server 2010
  • Microsoft FxCop
  • Team Foundation Server 2010
  • System Center suite
  • Forefront
  • VMware (PowerCLI)
  • Citrix Workflow Studio

Conclusion

Of course Windows PowerShell has a lot of new features that makes it a different shell. In this short article I just wanted to focus on the story of Windows PowerShell, why is it created, and it's most important features. Now, it's your turn to visit PowerShell official website, Team BlogPowerShell Survival Guide , to download, install, learn more, practice, and enjoy.