I have a solution in Powershell (7) where I have a module that includes a class, like
test.psm1
class TestClass {
[string]$Test
TestClass(
[string]$_test
) {
$this.Test = $_test
}
[void] TestMethod() {
xxx
}
}
In the main script I can successfully import the module including its classes and work with it.
In the main script I also want to process certain steps in parallel using jobs, like
using module .\test.psm1
[TestClass]$test = [TestClass]::new()
$job = $objects | ForEach-Object -Parallel {
[TestClass]$testJob = $using:test
} -ThrottleLimit $ParallelJobsThrottleLimit -AsJob
In these jobs I want to use an object of type TestClass that has been declared outside of the parallel statement.
All my approaches so far failed with Unable to find type.
How can I make this work?