Anton Kruglov Anton Kruglov - 3 months ago 15
PowerShell Question

How to access a Class Defined In A Module From Outside A Module?

I cannot access one class from another. Classes are defined in different files.

#foo.ps1
Class Foo { static [string]$data }


#bar.ps1
using module ".\foo.ps1"
class Bar {
Bar() {
[Foo]::data="test" #not working
}
}
[Foo]::data="test" #works

Answer

Posting as an answer so this doesn't go unanswered (credit to PetSerAl).

Rename foo.ps1 to foo.psm1 so that PowerShell knows it's a module.