Command-line interface or PowerShell?


If you were to make a tool that:

  1. sys-admins would use (e.g. system monitoring or backup/recovery tools)
  2. has to be script-able on Windows

Would you make the tool:

  1. A command-line interface tool?
  2. PowerShell cmdlet?
  3. GUI tool with public API?

I heard PowerShell is big among sys-admins, but I don’t know how big compared to CLI tools.



With PowerShell you have your choice of creating reusable commands in either PowerShell script or as a binary PowerShell cmdlet. PowerShell is specifically designed for commmand line interfaces supporting output redirection as well as easily launching EXE’s and capturing their output. One of the best parts about PowerShell IMO is that it standardizes and handles parameter parsing for you. All you have to do is declare the parameters for your command and PowerShell provides the parameter parsing code for you including support for typed, optional, named, positional, mandatory, pipeline bound, etc. For example, the following function declarations shows this in action:

PowerShell 2.0 advanced functions provide even more capabilities such as parameter aliases -CN alias for -ComputerName, parameter validation [ValidateNotNull()] and doc comments for usage and help e.g.:

See how the attributes give you finer grained control over PowerShell’s parameter parsing engine. Also note the doc comments that can be used for both usage and help like so:

This is really quite powerful and one of the main reasons I stopped writing my own little C# utility exes. The parameter parsing wound up being 80% of the code.


Command-line interface or PowerShell? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply