PowerShell Class Inheritance from separate file using Import-Module PowerShell Class Inheritance from separate file using Import-Module powershell powershell

PowerShell Class Inheritance from separate file using Import-Module


Firstly, a module file should have the extension .psm1 so you're going to want to change that. If you do not name them this way, the Using statement I referenced below will show an error.

bar.psm1 should contain a reference to the module, because modules do not import classes.

bar.psm1:

Using module ".\foo.psm1"class bar : foo{ }

However once you do this, the bar class is not exported so you would have to write a separate ps1 file that stated at the top Using module ".\bar.psm1" and then inside that script file you could call the [bar] class.