Chapter 17. Turning command-line tools into PowerShell tools

 

Jeffery Hicks

As terrific as PowerShell is as an automation engine and management tool, and despite the new cmdlets that shipped with Windows 8 and Windows Server 2012, there are still times when a command-line (CLI) tool gets the job done. Perhaps there isn’t a cmdlet replacement yet, or the CLI tool is easy to run. Or perhaps you have some legacy batch files that you need to use. The downside is that although you can run these tools in PowerShell, you’re limited with regard to what you can do with them because CLI tools write text and PowerShell is all about objects.

In this chapter I’ll show you how to turn output from CLI tools into something you can work with in a PowerShell pipeline. Ultimately, I think you’ll want to create your own PowerShell functions that wrap around a legacy command yet still write objects to the pipeline.

Requirements

Unfortunately, not every command-line tool lends itself to a PowerShell conversion. The tips and techniques I’ll show you rely on a few key requirements. If the tool you want to use doesn’t fit into the following categories you’ll have a hard time transforming the results to a PowerShell-friendly format:

Conversion techniques

A practical example

Summary

About the author

sitemap