Top 10 Windows 7 Features #9: Native PowerShell 2.0
By Scott M. Fulton, III | Published May 4, 2009, 6:19 PM
![]()
Ever since the command-line tool code-named Monad escaped by the skin of its fingernails from Microsoft's laboratories in 2006, there has been debate and dispute over whether the company has finally, once and for all, replaced DOS. Since that time, we've seen the arrival of an entirely new generation of Windows users who believe "DOS" is an acronym for "denial of service," and who are baffled as to the reasons why anyone would want to command or control an operating system using text.
It isn't so much that text or command-line syntax is the "old" way of working and that Microsoft Management Console is the "new" way. As Microsoft discovered, to the delight of some in its employ and the dismay of others, using the command line as the fundamental basis for Exchange Server improved its usability and efficiency immensely. The graphical environment simply does not translate well -- or to be fairer, not effectively -- to the task of administration.
As of last October and up through today, at least, Microsoft's often variable plan on PowerShell has been to include it with every SKU of Windows 7 and Windows Server 2008 R2. We will not be surprised if we suddenly discover it isn't included with the Home Basic edition, but its inclusion even there would be an indication that Microsoft is confident about being able to hand over the real-world equivalent of Doctor Who's "sonic screwdriver" to every Windows 7 user in existence.
PowerShell can be used exactly like DOS, as it maintains a vocabulary of "aliases" that recognize DOS commands as alternates, but it is not DOS. Rather, it is a very sophisticated administrative language designed not for programmers or for veteran developers, but instead for admins and system managers who need the ability to communicate a lot of information in as little space as possible.
Looking at just the front end, PowerShell takes the user right back to the TRSDOS era, with a blinking cursor beside a carat. But from there on, the resemblance to the 1970s becomes fleeting and momentary. You do not have to learn the MS-DOS batch file language to create a simple script that enables you to make a common fix. That doesn't mean learning PowerShell isn't a skill in itself -- it is, believe me. But its principles of consistency and economy of verbiage (something I myself may yet aspire to) enable anyone to theoretically craft and deploy a safe and powerful set of free tools that easily substitute for a myriad of commercial anti-malware and system tune-up programs.
Here's an example I created for a tutorial on PowerShell for InformIT last November: Imagine in your mind an MS-DOS batch file whose purpose is to scan the running processes in Windows, find Windows Media Player, and make a log of the amount of available system memory whenever it does find that app. Assuming there were some kind of API for running Windows processes in DOS (and there never was), the amount of conditional statements and print formatting instructions would make such a script enormous.
With PowerShell, I managed the entire concoction in just two instructions:
get-process | where {$_.ProcessName -match "wmplayer"} | format-table $table | out-file "mediaplayer.log" -append
Now, there's a lot going on with these two instructions, thanks to PowerShell's ability to compress a lot of instruction in a little space. The first line, for example, actually creates a little database table in memory, and formats it for the columns needed for this little log file. Each of those columns is given a name, just as though we were building this table for MySQL or SQL Server. The format becomes a kind of template string in memory, which is given the name $table (TRS-80 veterans will remember the old BASIC language where the $ character fell at the end of the string variable name rather than the beginning).
The second instruction is actually in four segments, and each segment passes on its results to the next by means of the pipe | character. Commands that are native to PowerShell are called cmdlets (pronounced "command-lets"), and they all have a verb-noun syntax. There are dozens of cmdlets that start with get, and because the syntax is consistent, it's easier to remember which command does what function. The get-process cmdlet is fairly self-explanatory, in that it generates a list of running processes. If the instruction stopped there, it would generate that list on-screen, but instead the pipeline takes the output to a where function that filters it. During this process, the output of get-process behaves like an object, as in "object-oriented language," so you can refer to the members of the object like properties. This script aligns those properties with the template created for the $table variable.
Next: How far does PowerShell 2.0 go?
this could help us immensely. this would let us easily set configs, change settings, etc through group policy automatically or waiting until we update our images.
the only downside is we're entirely XP Professional. unless they push PS to XP Pro this wont affect many businesses or schools for years =/
Score: 0
|It's a mistake to use gray on gray syntax highlighting, needs more contrast.
Score: 0
|PowerShell is fine for the geeks..for Joe Average, MS need something built atop PowerShell like Automator.
Score: 0
|Windows 7 RC public download page: http://www.microsoft.com...windows-7/download.aspx
Enjoy :)
Score: 0
|consumers that fatten microsofts wallet want an o.s. that is simple, easy and fast. they want internet, graphics and multi media.
business's pay workers to know how to use the o.s., business applications and the telephone. they don't pay their workers to use or know powershell.
perhaps, it should stay as a downloadable tool from microsoft or consumers will be frightened away thinking that utilities included in windows like powershell makes the o.s. complex.
Score: -5
|"they don't pay their workers to use or know powershell"
Really?
Good Windows systems administrators/engineers will know how to perform their tasks from the command line, whether that be with DOS batch, VBScript or PowerShell. If you think admins/engineers touch each PC or server individually, you're crazy. Businesses want their admins/engineers to perform their jobs effectively and efficiently, and that often cannot be done without the use of various scripting technologies.
Score: 3
|what? that all business's employ only software engineers?
besides a real software engineers and database programmers will use real programming applications to develop customized solutions.
unless the company is in the business of software development, 99% of the workforce of a typical company are not paid to be scripting.
Score: -3
|I said nothing of software (or database) engineers, not sure where you came up with that.
I assume from your username that you're an IT person, so why do you want to ignore the admins and engineers? A business is made up of all sorts of people, including IT people. That is especially so in large enterprises, where there could be hundreds of IT people supporting many tens of thousands of PCs and servers. Mine has probably somewhere in the vicinity of 80,000 PCs and servers. Since we frequently need to perform various scripting tasks, would it be more efficient for us to have to install PowerShell on every Windows box than for it to already be there, well hidden from the typical user? Wouldn't it be better for us to know it is already there and we can rely on it when necessary?
Score: 0
|nothing worst than having a bored co worker fiddle with specialty tools to screw everything up.
i'd rather limit developmental softwares and code writing on specialized computers instead of having them on "all" computers for the sake of convenience. besides, a "real" network makes sharing files and programs between hundreds or thousands of pc's a convenience.
the foundation for my original comment, is that powershell is not needed to be supplied with the o.s. because it can be downloaded on an as needed basis from microsoft, like their power toys or the toys for ultimate vista.
Score: -1
|"consumers that fatten microsofts wallet want blah blah blah...."
Oh man...
Wow.
There are no words... You've reached critical mass in clueless.
Score: 0
|obviously you are burdened with a great responsibility to ensure your insufferable whine is heard.
perhaps, you simply need your diaper changed, again.
Score: 0
|Or I just can't resist ridiculing ignorant BS whenever I see it?
Seriously, the level of ignorance in that OP of yours alone is off the charts. Just because *you* can't see a use for it is a failing of your own ability to think, not the ability of any given product or feature to be useful to others.
I love your level of arrogance. "If I can't see a need for it, *obviously* it's useless to *everyone*!" "If it's too kompeekated for me, *obviously* it will confuse *everyone*!"...
Yeah...
Thankfully, not everyone is as narrow-minded, lacking in creativity, or just plain ignorant as you are. :)
Score: 0
|Heh...
So Microsoft finally gets a decent scripting shell. (Calling a command line or command shell is a little outmoded...it would be like calling 'bash' a DOS alternative)
I haven't even begun to think of all the ways this will not only make supporting windows so much easier, but administering it, managing it, and scripting all kinds of "mods" for my personal systems.
Looks like I'll have something to do in my free time now in addition to playing WoW private servers and playing with the online drooling masses. ;-)
Score: -13
|It's not a decent scripting shell...it's a very good scripting shell! You can do some great things with it without much effort. This was an area MS was REALLY lacking in (any form of a useable scripting shell) for a very long time, and I'm glad they've finally addressed it, and did a very good job imho. I've been using PS1 whenever I need anything scripted...except our login script which I still use KiX for. I haven't used PS2 yet, but one of the features I'm most looking forward to is powershell remoting which was sorely lacking in PS1. It's been in CTP for a while now but I just haven't gotten around to using it yet.
MS has also begun to incorporate powershell into pretty much everything they develop now. Exchange 2007 is fully PS integrated, you can do everything in PS that you'd be able to do through the system manager, but much quicker ofcourse since it is a scripting language...:)
Score: 0
|Exactly.
It's been too long coming, and it's powerful. Linking it to their Apps, and OSes is an obvious step (well, for most of us...), and other vendors will very likely follow suit from what I've seen in various demonstrations so far.
Can't wait to start messing around with it. (Never really got into PS1, but we're going into a full update cycle in about 8 months and I am hoping Win7 is out by then...the possibilities seem almost endless) Win7 & WS2k8 & PS2.... Heh... Exciting time to be a (mostly) Windows shop. :D
Score: 0
|