Open
Description
Classes are currently a pain to export from a module in PowerShell.
This can be worked around, given this sort of code ($classScript
would be a script that defines classes) :
$classDefs = $classScript.Ast.FindAll({param($ast) $ast -is [Management.Automation.Language.TypeDefinitionAst]},$true)
$accelerators = ([psobject].assembly.gettype("System.Management.Automation.TypeAccelerators"))
if ($classDefs) {
. $classScript
foreach ($classDef in $classDefs) {
$null = $accelerators::Remove($classDefs.Name)
$null = $accelerators::Add($classDef.Name, ($classDef.Name -as [type]))
}
}
Using this workaround will surface the class via a type accelerator.