Adding Custom Properties to Functions
A question was asked on StackOverflow regarding how to add properties to a function, and then be able to retain that custom property when recalling that function from the function Provider. I’m not going to copy my answer here, but I do want to throw out a possible work around for this issue.
(It has been bugging me and I can’t really concentrate on my other tasks, so I need to get this out of the way.)
One suggestion I had was to create a type extension that had the property he was adding, but he was more interested in tagging specific functions, not all of them.
So, I’ve written a couple of little ScriptProperties to save and restore NoteProperties which have been added to FunctionInfo objects. I’ve added these to a PS1XML.
After saving this file as a PS1XML file, you can call Update-TypeData –Prepend path\to\thefile.ps1xml, and every FunctionInfo object will have two script properties – SaveMetadata and LoadMetadata. As I’ve configured it, the data will be saved to the user’s profile directory and under a filename that matches the function name. So, you can add NoteProperties to your heart’s desire and save and recall them as needed.
I don’t have a direct application for this, and it can probably be cleaned up or done more efficiently, but I had to work through the problem. I’d love to hear your feedback!