Anton Kruglov Anton Kruglov - 1 year ago 89
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.

Class Foo { static [string]$data }

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download