Code Writing Code
In the last article, I showed you how I created a module based on the APICodePack library. The module makes loading the assemblies and the supporting type and format extensions easier. The assembly exposes extended properties grouped by object type, so I started writing functions based on a property set, which I stored in psd1 configuration files. After writing the first two functions in the module, I realized I could automate or at least accelerate the development of additional commands.
This isn’t something you can always do, but if you realize you are repeating steps or commands to create code, you should look for ways to leverage those steps. You might want to create a snippet that you can use to jump-start a new command. In the module I’m working on, I have developed code snippets that I can reuse to assist with code generation. I want to capitalize on that.
I have already copied the configuration data files I generated in earlier articles to the configurations folder. These were files like CodePack-ImageProperties.psd1. To simplify working with these files, I’m going to rename them and drop the CodePack prefix. I have set my location to the module root.
Get-ChildItem .\configuration\codepack*.psd1 |
Foreach-Object {
Rename-Item -path $_.FullName -NewName "$(($_.name).split("-")[1])"
}