Shortens and simplifies a PowerShell script block by replacing command names with aliases and using shortest parameter aliases.
The Invoke-CommandShortener function takes a PowerShell script block as input and performs the following tasks
- Splits the input script block into individual lines, removing empty lines and delimiters.
- Identifies command delimiters in the input script block.
- Parses the input script block into an Abstract Syntax Tree (AST).
- Extracts a list of command elements and their associated parameters from the AST.
- Creates a list of command information, including aliases and parameters.
- Replaces command names with their aliases and parameter names with their shortest aliases or their shortest unique parameter match if no alias is available, including an implied 'Get-' test.
- Returns the modified script block.
None, but open for good ideas :)
The PSCommandShortener script was created with the intention of simplifying and optimizing PowerShell script blocks, particularly for Code-Golf enthusiasts. This tool aims to assist users in finding the shortest and most efficient way to construct PowerShell commands, making the coding experience more enjoyable and productive.
Feel free to contribute to this project, suggest improvements, or report any issues you encounter. I welcome community involvement in making PowerShell scripting more efficient and fun!