How to transform PSClass into module?

I consider PSClass - Object Oriented Scripting in Powershell as a very promising way to use simple OOP notations in my PowerShell productions.

The beauty of the original PSClass.ps1 construction is that it gives possibility to use very communicative/self-descriptive scriptblock in New-PSClass invocation.

It is constructed as a script that you have to run before any OOP syntax can be used in you own code.

My ambition is to convert it into standard PoweShell module (ie. PSClass.psm1) that could be imported by Import-Module cmdlet. Unfortunately, when content of the PSClass.ps1 is directly embedded into PSClass.psm1 subroutines note, constructor, property, method are not visible for Export-ModuleMember. Even if I use simple PSClass.psm1 definition like:

. .\PSClass.ps1

Export-ModuleMember -Function @('New-PSClass')

still subroutines note, constructor, property, method cannot be exported by Export-ModuleMember.

Has anybody any hint, how to make PSClass.ps1 script fully functional module with preserved self-descriptive scriptblock in New-PSClass invocation?


Personally I would rename PSClass.ps1 to PSClass.psm1 and the put the Export-ModuleMember command inside the PSClass.psm1 file. I don't see any value in dot sourcing PSClass.ps1 inside PSClass.psm1. Now you have two classes to pass redist rather than just one.

After looking at this script, I would add this to the end of the PSClass.psm1 file:

Export-ModuleMember -Function New-PSClass, constructor, note, property, method

Need Your Help

How to return rows from a related table in single query Zend Framework

php mysql zend-framework knockout.js zend-db

I have two tables, Restaurants and RestaurantHours, which I need to return in a single result set. For each restaurant in the Restaurants table, there are 7 records in the RestaurantHours table.

changes not upadated in eclipse

java html eclipse tomcat

I am writing a simple registration form in html using Eclipse Indigo.But after running one time on server Apache Tomcat 6.0 ,it is giving perfect output.But later if i am trying to modify any valu...