I've got a module setup to be like a library for a few other scripts. I can't figure out how to get a class declaration into the script scope calling Import-Module
. I tried to arrange Export-Module
with a -class
argument, like the -function
, but there isn't a -class
available. Do I just have to declare the class in every script?
The setup:
- holidays.psm1 in ~\documents\windows\powershell\modules\holidays\
- active script calls
import-module holidays
- there is another function in holidays.psm1 that returns a class object correctly, but I don't know how to create new members of the class from the active script after importing
Here is what the class looks like:
Class data_block
{
$array
$rows
$cols
data_block($a, $r, $c)
{
$this.array = $a
$this.rows = $r
$this.cols = $c
}
}
According to here and here, you can use classes defined in your module by doing the following in PowerShell 5: