PowerShell: Can you write a class like the system ones?

35 Views Asked by At

Hopefully a very simple question. I'm diving into classes within PowerShell; What I'm wondering is normally you estantiate a class as Class <myClass> {} is there a way to write it like the system ones System.Collections.Generic..... So it would be something akin to: class <myCompany>.<myClass> {}?

1

There are 1 best solutions below

0
Mathias R. Jessen On BEST ANSWER

NO

PowerShell classes cannot be namespaced with native syntax, you'll need to compile your types from C# using Add-Type:

Add-Type -TypeDefinition @'
namespace MyCompany {
  public class MyClass { }
}
'@