Windows PowerShell : Variables, Types, and Operators

Play Windows PowerShell : Variables, Types, and Operators
Sign in to queue


Join James Brundage, PowerShell Test Team SDE, as he introduces Variables, Types, and Operators.  

Windows PowerShell is a Windows command-line shell designed for ease-of-use not only by system administrators but also for application and system developers.  The shell includes an interactive prompt and a scripting environment that can be used independently or in combination.  PowerShell V2 is available by default with both R2 and Windows 7 and, via an optional update, previous versions of Windows.

For Developers specifically, Windows PowerShell in combination with the Windows Management Infrastructure (WinRM, WS-Management, WMI) provides a great way to automate server hosted solutions.   For example, if you implement all your administration logic via PowerShell, then layer the MMC GUI over the top (i.e. MMC calls PowerShell to get the work done) - you will have given your Enterprise customers the absolute best of all worlds; GUIs, scripting, and delegated, remote automation.

Unlike most scripting shells, which accept and return text, Windows PowerShell is integrated with the .NET Common Language Runtime (CLR) and the .NET Framework, and thus deals in .NET objects instead of just text strings.  This fundamental change in the environment brings entirely new tools and methods to the management and configuration of Windows.   Application Developers may extend their solutions with custom PowerShell based object models that integrate seamlessly with platform management solutions.

Like many shells, Windows PowerShell gives you access to the file system on the computer.  In addition, Windows PowerShell providers enable you to access other data stores, such as the registry and the digital signature certificate stores, as easily as you access the file system.

Version 2 of Windows Powershell introduces an array of new features including remote sessions, an integrated script environment, debugging tools, and much more. 

Continue your video tour of PowerShell V2 via MSDN Channel9 and TechNET Edge.  Don't miss the reusable scripts and techniques at the PowerShell Script-Center website.  Subscribe to the PowerShell Team Blog RSS Feed for the latest info.

See related episodes here.



Right click to download this episode

The Discussion

  • User profile image

    I don't like the choice of the relational operators. Everything in Powershell flows and looks natural, except these relational operators. Less than, equals, greater than, etc. Instead of using the natural and easy to remember and easy to type <, >, <=, >=, != and == symbols, which every programmer, from the beginner to the advanced, knows, you used the counter-intuitive -lt, -gt, -ge, -ne, etc, strings. I know, I know what you are going to say: "Other shell languages use similar things." But isn't this what Powershell wanted to change, namely the mess of the other shells. Instead of using inconsistent esac and fi and other end of block delimiters, Powershell simply uses the highly intuitive { and }. Very good! Instead of words which one has to memorize, Powershell uses punctuation like () and [] and , which is common to most imperative languages. Easy to learn and also easy to reuse in other programming tasks using other languages. Why then have you used these strange combinations for the relational operators? If it was for compatibility with the < and > operators in cmd.exe, it is not worth it since < does not work in Powershell anyway and > is problematic since many time one has to change the encoding anyway and so one has to type "| -encoding ascii filename". In any case, > piping simantecs is unnecessary, ambiguous and less flexible than the "|" to an "out-something" commandlet. Also, < and > piping does not fit into the simplistic model of Powershell which does not use extra operators when not needed. So, there is really no excuse?

  • User profile image

    I would also be interested in knowing why they chose -eq etc. instead of the standard operator set.

  • User profile image

    A "crapload of operators" that sounds like a lot. Big Smile

  • User profile image

    I was in the v1 beta group back in MSH days.  We fought over this for months.  As both an (ex) ksh guy and a c-style programmer, I was on the side of using the normal operators like yourself.  The real hangup was the ">" redirect operator (and to a lesser extent the  ">>") as already taken.  DOS and unix legacy scripters won, because the common use of that operator is well understood and they felt it would be too much of a change.  It was really a SHELL -vs- language argument and a choice needed to be made.  Not being able to use ">", also ment they could not really use the others ("<=", "==", etc) because the symmetry was now gone.   Personally, I still think they made the wrong choice, but understand the other side.  It would have been better to have the normal programmer operators and use something else for io and let the io folks deal with the change.  Now with LINQ logic needing those operators and the fact that people want PSH integrated with things like VS and others , I am guessing some folks may be kicking themselfs.

  • User profile image

    Windows Power Shell its very good



    Free sms kostenlos

Add Your 2 Cents