Skip to navigation

PCPro-Computing in the Real World Printed from www.pcpro.co.uk

Register to receive our regular email newsletter at http://www.pcpro.co.uk/registration.

The newsletter contains links to our latest PC news, product reviews, features and how-to guides, plus special offers and competitions.

Real World Computing

Shell power for Windows

Posted on 29 Jun 2006 at 11:22

Thomas Lee looks at microsoft's cool new administration shell and scripting tool, powershell, and finds out how it fits into the .NET framework

PSH [C:\]: [string] $s = "foobar"

PSH [C:\]: [int] $i=21

PSH [C:\]: $I+$S

Cannot convert value "foobar" to type "System.Int32". Error: "Input string was not in a correct format."

At line:1 char:4

+ $I+$ <<<< S

Here, PowerShell creates a string variable $s and an integer variable $i, and then quite correctly raises an error when you attempt to add them together. PowerShell enhances type safety through a synthetic type system: by using a series of XML files that provide the type definitions, it extends and normalises the underlying .NET objects. For example, in the PROCESS class, the name of the process is held by the PROCESSNAME property, while for services the service name is held in the SERVICENAME property. However, Enhanced PowerShell adds a generic NAME parameter to both classes, thus simplifying the writing of polymorphic scripts - another example of knowledge leverage.

By default, PowerShell will automatically pipe any output to the OUT-DEFAULT cmdlet for formatting, but you're able to improve and extend the default formatting, as all the formatting information, which you can modify or extend, is stored in XML form in the PowerShell install folder. You don't have to just use PowerShell's defaults, although they're often good enough for most simple applications. You can use the FORMAT-LIST or FORMAT-TABLE cmdlets to be clearer about which properties you want to look at, and if you want fixed-width output you can apply .NET formatting strings to get the precise layout you want.

For more information about PowerShell, read the PowerShell Team blog or visit my PowerShell subsite (www.reskit.net), which has information and a bunch of sample scripts to look at.

1 2 3 4 5
Be the first to comment this article

You need to Login or Register to comment.

(optional)

advertisement

Latest Real World Computing
Latest Blog Posts Subscribe to our RSS Feeds
Latest News Stories Subscribe to our RSS Feeds
Latest Reviews Subscribe to our RSS Feeds

advertisement

Sponsored Links
 
SEARCH
SIGN UP

Your email:

Your password:

remember me

advertisement


Hitwise Top 10 Website 2008