Boost your shell with reusable code stripped to its essentials


Minimalism is not just an art direction or lifestyle but is also a programming style. I don’t have much practisch in the former styles but I guess they have one thing in common; the satisfaction in adding value by simplifying. I can spend hours in trying clean up code from unnecessarily commands and functions. Take for example the input parameters of a function, you can spend a lot of code in returning errors on unexpected input values but you can also accommodate on it and give your program an extra functionality.
Meaning a global cmdlet, like Get-Item -Name <String>, could produce an error when no name is provided but it could also simply return $Null , telling the calling program rather than the programmer there is nothing to found and probably easier to program. You might take this one step further and add an extra functionality by returning all items if no -Name is provided. And, what if the -Name is not a <String> but an <int>? In that case you might e.g. conciser to return the Nth item in the list.

This approach is especially useful for internal functions which you might want to reuse in multiple programs or even multiple times in the same program. Needless to say, PowerShell does has a huge collection of very useful cmdlet functions and statements available but still I could add a few which I would actually expect to be standard available. Take for e.g. a the very small IIf (Inline If or ternary If) cmdlet, although it is possible to put the standard If statement inline, the IIf cmdlet results in a much cleaner code as it needs less parenthesis and brackets in the syntax. A more complex example of a reusable cmdlet is the Join-Object cmdlet which has a similar functionally as the SQL Join command for SQL. Taken the fact that PowerShell is optimized for dealing with piped objects, I would expect such command to be native to PowerShell. Saying that, it could well be that one of the cmdlets I published here will exist in a future release of PowerShell but that would not make it obsolete as it could still be used for programs that require downwards compatibility with older PowerShell versions.

The objective of this website is to describe and make these cmdlets available for reuse so that you can write cleaner code. Suggestions for code improvement are welcome. I also welcome ideas for new PowerShell cmdlets that can be reused by others. At the moment, I am still adding cmdlets and the plan is to eventually bundle them in a PowerSnippets.psm1 module.

Last updated on 6 Jun 2020
Published on 6 Jun 2020