Windows PowerShell overcomes this limitation by having cmdlets return objects rather
than simple plain text. If you run a command by itself, PowerShell automatically invokes
the default formatting to render the output as text. But say, for example, that you want
to pipe the output into another command. Rather than having that command output
text that you would then have to parse yourself, the command simply returns an object
containing that data, so that the next command can work on the data set itself and manipulate
directly without having to try to deal with parsing strings.
Consider our good friend Get-ChildItem (the old DIR). By default, Windows
PowerShell renders its output just as the DIR command did. Suppose you want to convert
this output to HTML. In the past, you would have had to write a Windows Shell Script
or even write the whole thing in VBScript to get this type of functionality. In PowerShell,
since Get-ChildItem returns an object representing the list of files in that folder, you
can simply pass it to another cmdlet that can take a list of objects and convert it directly
to HTML tables. In practice, all you need to do is run the following command and it will
generate an HTML file, as shown in Figure 13-5:
Get-ChildItem | ConvertTo-HTML > MyFile.html
If that alone didn??™t wow you, you probably have never had to write your own HTML
conversion routine.
Pages:
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467