I am currently writing a REST API using UD. I have a separate module with a number of PS Class definitions. I would like to be able to be able to call static methods from these custom PS Classes from api endpoints, but nothing I’ve tried so far seems to work. The best I’ve managed so far is to Install the module in the PS modules path, place a “using module moduleName” as the first line of my endpoint scriptblock, and see that the module is loaded in the sessions (via using get-module). However, when I try to instantiate an object from one of the classes in the module, or call a static method, I get a “Unable to find type [className]”.
Adding modules to the modules array in the New-UDEndpointInitialization will make modules available, but import-module won’t load the class definitions.
I do the following, pass the name of my installed modules into the below function:
$dashmodules = @(“module1”,“module2”)
$endpointinitialization = New-UDEndpointInitialization -Variable $dashvariables -Function $dashfunctions -Module $dashmodules
When you do either new-uddashboard or start-udrestapi use the ‘-EndpointInitialization $endpointinitialization’ flag to pass it in.
so, for every page I create I write my own module. the reason is pretty simple, whenever i change something in the module it will only effect the page which is using the corresponding module. There is a modules folder where I put all my modules. You can import them like this: