This is a complete refactor and re-implementation of the ScriptClass object extensions -- it contains breaking changes. In addition to including a new packaging of code based on PowerShell's implementation of .NET objects through the class keyword, it removes leaked module state it previously depended upon and is thus more reliable. Several commands have been renamed for consistency and clarity, and some public types have changed structure.
Here is an excerpt from the release notes:
The most significant changes are at the implementation layer, where refactoring and simplification should
make the code more reliable at runtime, enable better isolation of PowerShell modules built on it from
dependencies on implementation of ScriptClass or other modules depending on it, and even improve runtime performance.
In general, the codebase is more modular and now aligns to an explicit logical arrangement, making it easier
to maintain and modify.
New features
The ::> operator now supports invocation on class instances, i.e. given an instance, it will call the
static member of that instance's class. It can still be used with class names as the target just as before.
Script scope variables are inaccessible to code within a ScriptClass method -- this protects the method
code from unintended / confusing behavvior. This is also a breaking change
Parameters may be passed to the script block used to define a class via New-ScriptClass. This is a workaround
for the breaking change above for cases where one explicitly wants outside state available to the method
Module initialization occurs only within module scope -- no pre-initialization code is executed through the
ScriptsToProcess key of the manifest, resulting in better isolation and reliability
Import-Script now supports the AnyExtension option to allow any file, not just files ending with
the ps1 extension, to be imported
Breaking changes
Add-ScriptClass is renamed to New-ScriptClass
Get-Class is renamed to Get-ScriptClass
The with alias is renamed to withobject
Script scope variables are no longer accessible from ScriptClass methods -- use the ArgumentList parameter
of New-ScriptClass / ScriptClass to pass such variables to the ScriptClass definition
The PSCmdlet automatic variable is no longer passed to ScriptClass methods
Verbose output is not visible from ScriptClass methods unless a caller earlier in the stack has invoked the
new Enable-ScriptClassVerbosePreference command
The gls alias directs to the new Get-GraphItemWithMetadata command instead of Get-GraphChildItem
The PSTypeName property is no longer part of ScriptClass objects
The Get-ScriptClass command returns a different data structure than the old Get-Class command
Fixed defects
The module's internal variables are now isolated within the module -- previously variables and
functions at script scope were available to any callers outside the module, allowing them
to modify ScriptClass internal state. And it was quite possible that ScriptClass internal state
collided with variables or functions in other modules. This is no longer the case as ScriptClass
now behaves like an ordinary Powershell module. This means its features can be accessed by
other modules by including ScriptClass in the NestedModules element of those module manifests.
This is a complete refactor and re-implementation of the
ScriptClass
object extensions -- it contains breaking changes. In addition to including a new packaging of code based on PowerShell's implementation of .NET objects through theclass
keyword, it removes leaked module state it previously depended upon and is thus more reliable. Several commands have been renamed for consistency and clarity, and some public types have changed structure.Here is an excerpt from the release notes:
The most significant changes are at the implementation layer, where refactoring and simplification should make the code more reliable at runtime, enable better isolation of PowerShell modules built on it from dependencies on implementation of ScriptClass or other modules depending on it, and even improve runtime performance. In general, the codebase is more modular and now aligns to an explicit logical arrangement, making it easier to maintain and modify.
New features
::>
operator now supports invocation on class instances, i.e. given an instance, it will call the static member of that instance's class. It can still be used with class names as the target just as before.New-ScriptClass
. This is a workaround for the breaking change above for cases where one explicitly wants outside state available to the methodScriptsToProcess
key of the manifest, resulting in better isolation and reliabilityImport-Script
now supports theAnyExtension
option to allow any file, not just files ending with theps1
extension, to be importedBreaking changes
Add-ScriptClass
is renamed toNew-ScriptClass
Get-Class
is renamed toGet-ScriptClass
with
alias is renamed towithobject
ArgumentList
parameter ofNew-ScriptClass
/ScriptClass
to pass such variables to the ScriptClass definitionPSCmdlet
automatic variable is no longer passed to ScriptClass methodsEnable-ScriptClassVerbosePreference
commandgls
alias directs to the newGet-GraphItemWithMetadata
command instead ofGet-GraphChildItem
PSTypeName
property is no longer part of ScriptClass objectsGet-ScriptClass
command returns a different data structure than the oldGet-Class
commandFixed defects
NestedModules
element of those module manifests.