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.
From around the web
advertisement
- Why virtualisation hasn't slowed the growth of data
- How to make Google AdWords work for your business
- The curse of sloppily written software
- Paying for your crimes with Bitcoin
- Behind the scenes: tech support for Formula 1
- The security risk of fat fingers
- Why Windows Phone 7 isn't quite ready for business
- When will Microsoft stop fiddling with Windows 8?
- Flash down the pan?
- Metro Style apps vs desktop applications
- Chrome's shine getting lost in translation
- BytePac: the cardboard hard disk enclosure
- How tech loosens our grip on reality
- Hokum watch: Safer Internet Day
- Why I'm deleting Adobe from my PC
- Prepare to be patronised: it's Safer Internet Day
- Dear Sony, Samsung and every other tech company in the world: stop trying to be Apple
- Will Apple's Final Cut Pro X update placate the pros?
- Smartr Contacts for iPhone review
- Switching to Office 365's Outlook Web App
- VeriSign slammed for security breach cover-up
- SAP willing to share HANA with Oracle
- Why using a tablet could harm your health
- New RIM boss: no need for drastic change
- RIM founders fall on their swords
- Slow economy helps boost Red Hat revenue by 23%
- Google+ pages get multiple admins
- One in five companies lack card industry compliance
- Oil industry warns hacking attacks could kill
- British workers fear email monitoring
advertisement

