Windows PowerShell: The Utility You Probably Missed

Power Shell has been around for a while and I've managed to miss it. That's too bad because I used to like performing magic tricks with BAT files in the days when DOS ran our desktop computers. Computers no longer run on DOS, but a DOS-like command line is available and PowerShell brings some truly powerful programming capabilities to the command line.

Windows PowerShell is Microsoft's task automation framework, consisting of a command-line shell and associated scripting language built on top of, and integrated with the Net Framework (which Microsoft styles as ".NET Framework"). PowerShell provides access to Component Object Model (COM) and Windows Management Instrumentation (WMI) so users can perform administrative tasks on both local and remote Windows systems.

PowerShell is buried deep in the menu structure: Start > All Programs > Accessories > Windows PowerShell > Windows PowerShell [right-click and select Run as Administrator]).

Click for a larger view.Although documentation is limited, PowerShell includes console-based help similar to "man" pages in Unix/Linux shells. Unlike Unix and Linux command names, which are so short as to be unintelligible (man cp) the PowerShell command names are so long that they're unwieldy (get-help copy-item). I should point out that PowerShell has aliases, so you can type "help copy-item" or "help cp" or even "man cp" to view the help page.

Windows PowerShell looks somewhat like the old DOS command line or the Windows command prompt, but it is far more capable. PowerShell can run 4 classes of commands:

Executable programs are launched in a separate process while cmdlets run within the existing PowerShell process, which is based on the Win32 console.

Much like Unix and Linux, the PowerShell allows the use of pipes (|) to create a series of commands that create output and pass that output to the next command as that command's input.

A Wikipedia article points out that unlike Unix and Linux pipe operators, the PowerShell pipe operator expects objects; "that is, the data passed between cmdlets are fully typed objects, rather than character streams. When data is piped as objects, the elements they encapsulate retain their structure and types across cmdlets, without the need for any serialization or explicit parsing of the stream, as would be the need if only character streams were shared."

Working My Way Up to Something That's Almost Useful

Windows doesn't have a built-in way to print a directory listing. It's easy enough to do by opening a command prompt, navigating to the directory you want to print, then typing "dir > list.txt", and then printing "list.txt" after opening it in a text editor or word processor. ("dir > lpt1" or "dir > prn" no longer work.)

In the PowerShell, "dir" produces a Linux-like display:

  Mode                LastWriteTime     Length Name
 	----                -------------     ------ ----
 	-a---         6/14/2010   5:02 PM         35 123.txt
 	-a---         8/10/2010   4:03 PM       3997 dirs.txt
 	-----         4/18/2010  12:00 PM       2128 How to scan documents.txt
 	-a---          7/4/2010   8:32 PM        742 k-calendars.txt
 	-a---          1/6/2008  11:50 AM         78 MachineGuid.txt
 	-a---         5/18/2010   5:05 PM         26 StartPenServices.cmd
 	-a---         12/8/2008   6:31 PM   66125824 SystemRestore.iso
 	-a---         9/30/2007   7:32 AM       6632 tasks.txt
 	-a---         2/12/2009   6:03 PM       1440 Win-Files.txt

This may not be what you want, though. So "dir | select name, lastwritetime, length" produces a more usable list:

  Name                                    LastWriteTime                           length
 	----                                    -------------                           ------
 	123.txt                                 6/14/2010 5:02:24 PM                    35
 	dirs.txt                                8/10/2010 4:03:21 PM                    3997
 	How to scan documents.txt               4/18/2010 12:00:24 PM                   2128
 	k-calendars.txt                         7/4/2010 8:32:02 PM                     742
 	MachineGuid.txt                         1/6/2008 11:50:22 AM                    78
 	StartPenServices.cmd                    5/18/2010 5:05:30 PM                    26
 	SystemRestore.iso                       12/8/2008 6:31:11 PM                    66125824
 	tasks.txt                               9/30/2007 7:32:32 AM                    6632
 	Win-Files.txt                           2/12/2009 6:03:59 PM                    1440

This can be sent as is to the default printer:
dir | select name, lastwritetime, length | out-printer

The result isn't satisfactory, though. Because the dates don't contain either leading zeros or spaces and because the printer's default typeface is a proportional one, columns do not align.

To obtain an alphabetical listing of all files in the current directory and all subdirectories, try: "ls $_.FullName|Foreach {$_;if ($_.PSIsContainer){dirlist}};Get-Item * |Foreach {$_;if ($_.PSIsContainer){dirlist}}" and then add "|out-printer" to send the listing to the default printer.

Click for a larger view.This uses right justification, so the alignment is better, but it's still probably not quite what you might be looking for. There's still a lot learn, such as how to specify a typeface. Many books already exist to describe the intricacies of PowerShell scripting. Now I suppose I'll have to read some of them.

All This for a Directory!?

Incidentally, if all you need is a directory listing, you can use Firefox, Chrome, or Opera. Users of Safari and Internet Explorer will not experience success.

Click for a larger view.Firefox
Type "file:///" followed by the directory you want to list. Firefox produces, in my opinion, the best looking list.

Click for a larger view.Chrome
This is the second-best option. As with Firefox, use "file:///" in front of the directory name.

Click for a larger view.Safari
This browser says that it needs enhanced permissions to continue. This is probably something that can easily be resolved, but why bother?

Click for a larger view.Opera
I don't much care for Opera's directory view. I suppose it's very good with the Opera logo, but what's up with spreading the file size over 2 lines? Likewise the timestamp.

Click for a larger view.Internet Explorer
FAIL! Instead of displaying a directory, Internet Explorer opens the Windows Explorer. If you're a Microsoft programmer, that probably even makes sense. But you can't print the directory listing.

In December, We Think of Video

The thought pattern works this way: End of the year. Winter solstice. Religious holidays. Gifts. Video. Some of those gifts are bound to be video cameras or digital SLR cameras that include the ability to capture video. But capturing video is just the first step. If you want the video to serve any purpose, editing is essential. The good news this year is that editing video has become a whole lot easier than you thought.

Most people seem to fear video editing and I think I know why.

Even so, people are intimidated because video editing requires that you find a way to acquire (import) the video from a camera, that you understand the various video formats and timecodes, and that you figure out how video compression works so that you can create programs for others to view. At least that's what most people seem to think.

Well, I have good news for you ...

It's not that hard!

The folks at Adobe's PR agency sent me a copy of Premiere Elements to take a look at. If you're a video professional, Premiere Elements probably isn't sufficient for you. But just as Photoshop Elements, which isn't Photoshop, packs the features home users will need into an easy-to-use package, Premiere Elements gives you everything you need to create home videos that will make you the envy of your peers.

True story: I have dozens of VHS, 8mm, and Hi8 videos that I've wanted to convert to DVD for my two daughters. After tinkering with Premiere Elements and watching Jeff Sengstack's introduction to Premiere Elements, I knew that I could do it. Don't tell Elizabeth and Kaydee, but this year at Christmas they'll each receive a "coupon" like this:
Video

In his Lynda.com video, Jeff Sengstack said that video editing can be enjoyable, easy, and rewarding. He's right. But he also went on to describe the process, which can be, if not intimidating, at least confusing: "First, you shoot your raw footage, then you transfer that raw, unedited video to your computer where it's stored as a collection of files. In Premiere Elements, you create links to those files as well as to audio, photo, and graphics files. This linking process is called 'importing' or 'getting media'. It's important to know that Premiere Elements does not change, copy, move, or delete those original files. Now you start editing your video. There are several approaches to video editing—most frequently, you'll probably want to arrange your clips into a 'rough cut'. Then you can re-arrange and trim away video that you don't want to use from some of those clips. You can place transitions between scenes, put video and audio effects on some clips, plus add graphics and text that can appear on top of those clips. You might also want to include music or narration. Finally, when you're all done, you share your finished product. You can create a DVD with menus or simply create your project into a single video file that you can upload to the Internet or play on your computer or mobile phone."

Do videos really come from here?
Blackwood Forest
Image source: http://travel.webshots.com/photo/1026477300030171813ymKuqzEJhX

What is Premier Elements?

Adobe's professional video editing suite includes OnLocation, Premiere, and AfterEffects. These are applications that professionals use. By comparison, Elements is (well) elementary. Even so, the capabilities are surprising.

As an editing application, Premiere is non-linear and non-destructive; so is Premiere Elements. I remember working on video projects in the 1980s and, although the process was non-linear, it wasn't easy. The process could be made non-destructive in those days, too, but that wasn't easy, either. And studio time could easily run several hundred dollars per hour, even if you worked with low-rate university editing shops that took a little outside business to defray expenses.

Professional applications such as Premiere have a timeline view. Premiere Elements has a timeline view, but it also has a (newbie-friendly) "sceneline" view that makes much more sense to new users. Start with the sceneline view, but transition to the timeline view as soon as you can because the results will be better.

TIMELINE VIEW
The width of each scene in the timeline view gives you a visual indication of the scene's length. You also have access to more advanced video and audio editing controls as well as the ability to add additional layers of video for titling and other creative effects. Even if you start with the sceneline view, you should graduate to this view as soon as you can.
Timeline

SCENELINE VIEW
The sceneline view looks more like a storyboard. You gain simplicity, but at the cost of forfeiting some of the powerful features. The small rectangles between the scenes are where you would drop transition elements. In this view, a scene that's 5 seconds in length takes just as much space as a scene that's 5 minutes long.
Sceneline

Easier and Far More Powerful than Expected

Particularly with the help of Jeff Sengstack's instructional video at Lynda.com, I was able to create an acceptable video on my first attempt. The second and third attempts were considerably more polished as I returned to Sengstack's program for refreshers. And Premiere Elements has some built-in features that help those of us who aren't video professionals.

For example, when I set up a program and then attempted to import video, the application told me that the format I had selected didn't match the video I was trying to import. Would I like to change the settings to match the inbound video, it asked. Of course I wanted to do that.

When it's time to share the video, Premiere Elements offers several options: DVD, file on a computer, file on the Internet, file for a mobile phone, and even outputting to digital video tape. Premiere Elements even takes care of video compression so that your production will fit on the type of disc you will be using.

5 CatsBottom Line: Home Video Producers, Your Wish Has Been Granted.

This is another Adobe product that, like Photoshop Elements, requires a bit of explanation: If you're a professional video editor in an agency shop, this isn't the application for you. You'll need to lay out some big bucks and purchase the full Creative Suite CS5. But if you're someone who wants to spend a relatively short period learning how to edit videos and then to make videos that will astound your friends, Premiere Elements is just what you need. Premiere Elements is available alone (less than $100) or with Photoshop Elements (less than $150).
For more information, visit the Adobe Premiere Elements website.

Short Circuits

An Open Letter to Google

Hey, Google, Maybe you've noticed that the world has moved on from 8-bit operating systems that predated your company to 16-bit systems, 32-bit systems, and (since Windows XP) 64-bit systems. It's true that only a few XP users opted for the 64-bit version, but that was back in 2003, a couple of years after XP was introduced. 64-bit adoption picked up during the Vista years because that's the only version that more or less worked. Now, according to Microsoft, almost half of all PCs running Windows 7 are running 64-bit editions of the OS. Oh, and you may also have noticed that Windows 7 is selling very well. So why does Google Calendar Sync still not work with 64-bit systems?

It would seem that you've forgotten about it. I performed a Google search and found on a Google blog that "Google Calendar Sync isn't working with Windows XP 64-bit Edition." There's not even any mention of Vista or Windows 7. Might that be because the most recent update was posted on September 30, 2008? (This is 796 days ago as of today's program date.)

"Please be informed," the post says, "that Windows XP 64-bit Edition isn't compatible with Google Calendar Sync at this time." The post goes on to say that the team is "definitely aware of the strong desire to use this feature and we're keeping track of all reports and requests as we work to improve Google Calendar Sync."

Sure you are. That's why you haven't updated the information in more than 2 years. You're so busy keeping track of all those requests that you haven't had time to do any work.

Google Calendar Sync is a pretty cool application. Well, it was. Several years ago. Back when just about everyone used a 32-bit operating system.

C'mon, Google. Get with the program. Update your apps so that they'll work with the operating system more than half of Window 7 users have installed. [Note: In July, 64-bit adoption was 46%. My guess is that it's expanded since then. But even if 64-bit penetration is "only" 46%, why are you penalizing nearly half of Windows 7 users by ignoring them?

This message was sent to Google's media relations staff on 30 Nov 2010 with an explanation that indicated a response would be welcome and that the deadline was Friday, 3 December 2010.

RESPONSE FROM GOOGLE from Victoria Katsarou: Both Windows and Outlook can be found in 32-bit and 64-bit versions. You mention below that Google Calendar Sync doesn't work with 64-bit Windows, but it does. That is, if you are using 32-bit Outlook.
Me: HA! HA HA HA HA! Oh, wait, you're serious aren't you? You expect me to use a 64-bit operating system on 64-bit hardware and to limit the applications to their 32-bit versions?
Victoria: What we do not support yet is 64-bit Outlook. We actually launched a new version of GCS a few months ago to add support for the new release of Outlook (2010), but only the 32-bit edition. In the blog post announcing it, we said we were working on the 64-bit (Outlook) version, so that will be coming too. It is possible to use Google Calendar Sync with 32-bit Outlook on a 64-bit version of Windows.
Me: HA! HA HA HA HA! Oh, wait, you're serious aren't you? You expect me to use a 64-bit operating system on 64-bit hardware and to limit the applications to their 32-bit versions? (Oh, I already said that, didn't I?) It's been 7 years since Microsoft introduced a 64-bit operating system. Where has Google been all that time?
Victoria: As I explained ... [it] in fact does work with 64-bit Windows OS, just limited to 32-bit Outlook 2010.

Which is rather like having an 8-cylinder automobile that runs on just 4 cylinders. Sure, it might work; but you won't enjoy it.

High Tech Exports, Down But Still Important

TechAmerica Foundation released its annual report this week that details national and state trends in the international trade of high-tech goods. The report, Trade in the Cyberstates 2010: A State-by-State Overview of High-Tech International Trade, covers all 50 states, the District of Columbia, and Puerto Rico. The figures are for the year 2009.

Only 4 states showed improvements in high-tech exports: Alaska, Wyoming, Louisiana, and Arkansas. These 4 states aren't well known for their technological abilities and this is confirmed by their rankings:

"Bottom of the barrel" might not be much of an overstatement. (Or would that be an "understatement"?) Wyoming, for example, ranks below even Puerto Rico (23rd) and the District of Columbia (45th), neither of which is generally regarded as being a primary high-tech exporter.

Click for a larger view.By comparison, Ohio is 16th.

Overall, US high-tech goods exports fell by 16 percent in 2009 to $188 billion, which represents 18% of all US exports. High-tech exports form the largest merchandise export sector in the United States. High-tech imports were down by 11%, totaling $299 billion in 2009, resulting in a slight improvement in the high-tech trade deficit, which stands at $111 billion. High-tech exports supported 944,300 jobs in the United States according to the survey.

But there's still a deficit: $111.2 billion in 2009, down slightly from 2008 ($113.5 billion).

The largest overseas markets for US high-tech exports in 2009 were the European Union ($37.3 billion), Mexico ($28.1 billion), Canada ($24.3 billion), China ($14.0 billion), and Japan ($9.0 billion). The top high-tech exporter is California, followed by Texas, Florida, New York, and Massachusetts. All of those states saw high-tech exports decline in 2009.

The full Trade in the Cyberstates 2010 report and its sister publications can be purchased from the Tech America Foundation.