I implemented a small PowerShell module that brings a special type with it. I defined the type in the .psm1 file as a C # class and added it using Add-Type . Now, when I add a module and delete it again, the type still exists, which is probably not entirely correct (for example, it prevents the module from being added again). The documentation for Remove-Module states that types defined in assemblies loaded by the module are also unloaded. But my module does not bring assemblies, but just one tiny view in the form of source code.
I could just put the type in my own DLL and mark it as an assembly to load in the module manifest, but I like how the whole source code is now easily visible. Distributing a DLL with a module may raise a suspicion of why it needs an executable.
Is there something that I can connect to to somehow remove this type when unloading the module? Or should I just ignore potential errors with Add-Type in order to at least be able to re-add the module after being removed from the session? I would prefer not to put the DLL there (maybe all the same for this tiny module).
source share