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.
advertisement
- Getting to grips with Microsoft's IT Health Environment Scanner
- Virtualise your servers
- The changing face of travel gadgets
- Build your own distributed file system
- The bulletproof Dell that costs an arm and a leg
- Microsoft Office 2010 Technical Preview: Q&A
- Lawnmowers, the TyTN II and one odd insurance request
- There'll never be a bulletproof OS
- How far can we trust apps?
- Five nice touches in Outlook 2010
- ATI Radeon HD 5970: 42% more expensive in the UK
- Office 2010 Beta – 32-bit or 64-bit – The Choice is Clear
- Why Britain's watchdogs have fewer teeth than goldfish
- Tabbed documents: how to make Office 2010 great
- Outlook 2010 People Pane – does it spell death to Xobni
- Microsoft Outlook 2010 screenshots
- Co-Authoring in Word 2010 and SharePoint Foundation 2010
- Microsoft Outlook 2010 screenshots: Backstage view
- Flash 10.1: Developing for Desktop and Device
- Microsoft Office 2010 screenshots: Recover unsaved items
- Sky Player shows up in Windows 7
- Tweetlevel reveals most influential Twitterers
- Apple "refuses to repair smokers' Macs"
- Spotify arrives on Symbian
- Chrome OS and Android to "converge over time"
- Microsoft to pay News Corp to stay off Google
- Christmas sales surge knocks out eBay search
- Windows 8 set for 2012 release
- Q&A: Why Conficker was a victim of its own success
- App developers losing faith in Android
advertisement
Printed from www.pcpro.co.uk


