X
Business

Five enhancements that PowerShell really needs

PowerShell is one of the best Windows tools available, but it could be even better. Here are my five suggestions for a better PowerShell experience.
Written by Ken Hess, Contributor

PowerShell is Microsoft's scripting language, now in its third iteration. It's an extremely powerful tool to use for automation work, system administration, working remotely on systems, or working on multiple systems at a time. You can use it interactively or in a script. You can also touch multiple systems in a script by using its handy looping mechanism. So what more could one possibly want out of PowerShell that it doesn't already do? Plenty.

OK, first, PowerShell is a modular language, so that's one major point in its favor. Why? Because modularity allows it to be extended "voluntarily". By voluntarily, I mean that it can be extended by adding modules instead of having everything already packed in with no possibility of extension.

PowerShell 3.0 was a huge extension over PowerShell 2.0. PowerShell 3.0 comes equipped with thousands of cmdlets for almost every purpose — almost. And that's where this post begins — where PowerShell 3.0 leaves off.

Here is a list of what I think PowerShell 3.0 still needs: 

  1. *nix Connectivity Utilities — Boldly missing are tools for *nix style connectivity, such as SSH, SCP, SFTP, and others. There are some third-party modules for this, but they aren't very good, although I've had some success with SSHSession

  2. Backup/Restore Support — It would be nice to have some deep dive Backup and Restore tools in PowerShell, and enhanced versions of command line utilities such as AT and NTBACKUP

  3. Better Output Support — PowerShell has -OutFile and -ExportCSV output redirection, but you can't always get what you need from one of these because some output can't be redirected. For some output, you can do the following:
    PS> script.ps1 > file.txt and then use the text file. However, there are times when that sort of "out of script" redirection doesn't work for output either. You should see some of the crazy ways I've had to grab output from scripts. I'd really like to see better output redirection. In other words, anything that I can output to the screen (STDOUT), I'd really like to see supported in -OutFile or -ExportCSV, or some other redirection option

  4. Import on First Use — Rather than import Microsoft-branded modules, such as Active Directory modules, you should be able to download and install them on first use like you do with some of Microsoft's other features. This would be a very handy feature so that, for example, I could run a Get-ADUser on a system, and PowerShell would import the module and run the cmdlet without interaction from me

  5. Easier to Extract and Format Info — You can extract a lot of good information using PowerShell, but then to actually get the data you want into a desirable (readable) format, is very difficult. For example, PS> Get-Process provides you with a list of processes from your system in table format as shown in Figure 1.

processes_ps
Figure 1: Partial Process List — PowerShell. (Image: Screenshot by Ken Hess/ZDNet)

Now, try to just list the Process ID and ProcessName with PS> Get-Process | FT ID,ProcessName

See the result in Figure 2.

processes_2
Figure 2: Processes Filtered by ID and ProcessName. (Image: Screenshot by Ken Hess/ZDNet)

Do you see the problem? Now you might think that this isn't a problem because you can either live with the odd original location format or you can direct it to a text file. Wrong. When you direct the output to a text file, you get a text file with the columns pushed out to the right, just like they are on screen.

Forget about Format-Wide; it doesn't work. Format-List is even uglier than Format-Table. And if you said, "Try Format-Custom"; it's worse than the others, although I think that you can create a custom view (an XML file) and use that for a better format. But seriously, that's a lot of trouble for a simple list of IDs and process names.

If this were a *nix environment, I'd do something like this to get the format I want:

$ ps -ef | gawk -F" " '{print $2,$8}'

To yield,

PID CMD
1 /sbin/init
2 [kthreadd]
3 [migration/0]
4 [ksoftirqd/0]
5 [watchdog/0]
6 [migration/1]
7 [ksoftirqd/1]

And in fact, what I would do on my Windows systems, since I have CygWin tools installed and in my path on my automation systems, is:

PS> Get-Process |gawk -F" " '{print $7,$8}'

To yield,

Id ProcessName
-- -----------
3780 AmIcoSinglun64
1788 AppleMobileDeviceService
4900 ApplePhotoStreams
5396 APSDaemon
1764 armsvc
3844 atieclxx
948 atiesrxx
1444 AvastSvc
5188 AvastUI

I shouldn't have to resort to such measures to get what I need in terms of formatting. If you know of a better way, I would love to see it. So far, I haven't found one, though I've looked for a solution.

OK, that was a really, really long number five, but sometimes, it helps to fully illustrate a point to drive it home. 

[Update: one of my readers has supplied a fix for this problem with the -Autosize switch. If this works for all such formatting, then I guess we can mark number five off the list. Thanks.]

These are my five enhancements to PowerShell that I'd like to see. Do you have any improvements that you want included in a PowerShell update? Talk back and let me know.

Editorial standards