Windows PowerShell - Unix comes to Windows

Windows PowerShell (formerly known as “Monad”) is a Microsoft's answer to the power and flexibility of the Unix command shells. It should finally complete the Windows management picture by providing a solid command line shell to administer Windows systems. PowerShell is part of Vista, but fortunately for all of us, it is being released separately and is available for Windows XP as well.

PowerShell is a command line shell that is:

  • as interactive and composable as bash/ksh (or any other Unix shell)
  • as programmatic as Perl or Ruby
  • as production oriented as the AS400 CL or VMS DCL languages
  • allows access to data stores as easy as if they were a file system
  • provides “man-style“ help with a rich schema and searching capabilities

PowerShell seems to have incorporated many of the best features of the Unix shells, such as:

  • series of profile files that can be run at startup (or logon)

  • command aliasing

  • prompt customization

  • tab completion

  • many preferences controllable via variables

Scripting

  • Supports existing scripting models

  • UNIX model of text processing including regular expressions

  • Visual Basic Script model of COM automation

  • Supports scripting .NET objects

  • Support loose, strong, and extensible typing models

  • Uniform syntax to access to a wide range of types

  • WMI, XML, COM, ADSI, ADO

  • Rich variable semantics (typed, read-only, constraints, descriptions)

  • Rich operators and control structures (Visual C#-like with access to cmds and utilities)

  • Functions (positional, named, typed, constrained params)

Text Processing Model

  • NET String class is the foundation

  • Clone, CompareTo, Contains, CopyTo, EndsWith, Equals, IndexOf, IndexOfAny, Insert,  LastIndexOf, LastIndexOfAny, Length, PadLeft, PadRight, Remove, Replace, Split, StartsWith, Substring, ToCharArray, ToLower, ToLowerInvariant, ToString, ToUpper, ToUpperInvariant, Trim, TrimEnd, TrimStart

  • Native support for useful datatypes

  • REGEX, XML, Arrays, Associative arrays,

  • Rich string operators

  • +, *, -f, -replace, -match, -like, -eq, -ne, gt, -ge, -lt, -le

  • Implicit/explicit casting and coercion

  • Here-strings

  • Rich control structures

  • Rich utilities

  • Select-String, foreach, group, select, sort, where

function top ($property=“Handles”, [int]$count=10)

{
   Get-Process | sort $property | select –first $count}

For those of you who have written Unix shell scripts before (and maybe a lot of people who haven't) the syntax should look familiar. This declares a function named “top” which takes two paramters (both with defaults) and returns a sorted list of the top $count processes sorted by $property.

This article is part of the GWB Archives. Original Author: Scott Dorman

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.