Counting Lines of Source Code in PowerShell

Oren Eini recently ran into some performance problems while using PowerShell to count the number of lines in a source tree: _I wanted to know how many lines of code NHibernate has, so I run the following PowerShell command… (gci -Recurse | select-string . ).Count The result: (Graphic of PowerShell still working after about 5 minutes, using 50% of his CPU.) Bummer. _ The performance problem from this command comes from us preparing for a rich pipeline experience in PowerShell that you never use.

Updated: PowerShell Profile Locations Rationale

You may have noticed that we changed the location of the default profiles yet again! The one in “My Documents” is now under “WindowsPowerShell,” rather than “PsConfiguration.” The one in “All User’s Documents” is now under the installation root. Since you are probably wondering why, I’ve updated my last explanation: The Story Behind the Naming and Location of PowerShell Profiles.

Great PowerShell Screencasts

Several people have been churning out screencasts lately, and they are really great resources. On the Channel9 front, David Aiken recently posted two DFO Show screencasts: Introducing Windows PowerShell Amazon S3 meets Windows PowerShell (fantastic!) In addition, Doug Finke and the Lab49 team just posted an overview of some PowerShell features – Variables, Arrays, Hashtables, Functions, and PsObject. For interactive learners, the screencast medium is a great resource. Not only do you get to watch over somebody’s shoulder, but the vocal accompaniment also provides the “Proximity Effect” benefit of working under the guidance of an expert.

DasBlog Upgrade to 1.9 Complete!

Now that DasBlog 1.9 has been released, I’ve finally upgraded. Everything appears to have gone well, and I’m really happy with some of the new themes available. You won’t necessarily notice this if you only read the site through your RSS reader, so why don’t you come on down and check out the new look? :) Please let me know if you see anything broken!

O'Reilly PowerShell Quick Reference Now Available

My O’Reilly PowerShell Quick Reference is now available – a 120-page guide (in PDF format) that provides the essential reference material for your day-to-day use of PowerShell. With a concise explanation at your fingertips, there is no need to memorize esoteric topics like regular expressions and string formatting specifiers. Aside from its straight factual reference material, the Quick Reference also provides an enormous amount of value by distilling large bodies of knowledge into their most usable forms, including:

Exploring the Glide Path of PowerShell

As people begin to explore PowerShell, the question often comes up – “Will PowerShell support the cmdlet or language feature <foo>?” For example (from the newsgroup,) “Is there a way to get the unmodified contents of a file – since Get-Content splits it into lines?” Or from Occasionally Rabid Programmer, “… Is there a zipping PowerShell class yet?” For many of these questions, the answer is, “Yes. Since PowerShell gives you access to all of the .

SecureStrings and Plain Text in PowerShell

A question came up today on the newsgroup asking why the following didn’t work: PS >$secureString = ConvertTo-SecureString "Hello" ConvertTo-SecureString : Cannot process argument because the value of argume nt "input" is invalid. Change the value of the "input" argument and run the operation again. At line:1 char:39 + $secureString = ConvertTo-SecureString <<<< "Hello" PS > For some background – a SecureString is a type of string that PowerShell (and .

PowerShell range operator for other types

The PowerShell range operator allows you to generate lists of numbers out of more compact expressions: PS >1..5 1 2 3 4 5 PS >6..4 6 5 4 Something that came up on the newsgroup was the desire for range operators on data types other than the numeric ones. It’s a feature we wanted to add, but weren’t able to. In the meantime, this script / function accomplishes the goal quite well:

Exchange team demonstrates their PowerShell integration

Over the past few days, the Exchange team has been demo-blogging features of their new administrative interface. The power is obvious, and the benefit it brings to administrators is palpable. They’ve built their entire administration surface on PowerShell cmdlets, so today’s post really ties the series together nicely. They go through 14 of their most common scenarios with screen shots to illustrate all of the GUI actions. Then, for each, they show some incredibly intuitive PowerShell one-liners that accomplish the same task (and more!

Value types vs Reference types

A question came up recently in the newsgroup, asking why adding seemingly different items to an ArrayList resulted in the ArrayList being full of the same item: PS >$table = new-object Collections.ArrayList PS >$row = 1 | select Col1,Col2,Col3 PS >$row.Col1 = "Column 1" PS >$row.Col2 = "Column 2" PS >[void] $table.Add($row) PS >$row.Col1 = "Column 1, again" PS >$row.Col2 = "Column 2, again" PS >[void] $table.Add($row) PS >$table Col1 Col2 Col3 ---- ---- ---- Column 1, again Column 2, again Column 1, again Column 2, again The source of the difference comes from the type of data that you assign to a variable.