We’re happy to announce the discharge of PowerShell Crescendo 1.1.0-preview01. Crescendo
is a framework to quickly develop PowerShell cmdlets for widespread command line instruments, no matter
platform. This preview features a new schema, assist for argument worth transformation, the flexibility
to bypass the output handler, and improved error dealing with.
It is a neighborhood pushed launch constructed from the various recommendations and requests obtained immediately or
from our Github. Thanks PowerShell Group to your adoption and recommendations!
The preview launch is now accessible for obtain on the PowerShell Gallery.
Putting in Crescendo
Necessities:
- Microsoft.PowerShell.Crescendo requires PowerShell 7.0 or increased
To put in Microsoft.PowerShell.Crescendo:
Set up-Module -Identify Microsoft.PowerShell.Crescendo -AllowPreRelease
To put in Microsoft.PowerShell.Crescendo utilizing the brand new PowerShellGet v3:
Set up-PSResource -Identify Microsoft.PowerShell.Crescendo -AllowPreRelease
Highlighted options
This preview launch contains many fixes and recommendations. Listed here are only a few of the highlights
added for this preview.
New schema model
The Crescendo schema has been up to date to incorporate assist for 2 new members to the Parameter
class, ArgumentTransform
and ArgumentTransformType
. The schema works with supported instruments like
Visible Studio Code to offer intellisense and tooltips throughout the authoring expertise.
URL location of the always-available Crescendo schema:
{
"$schema": "https://aka.ms/PowerShell/Crescendo/Schemas/2022-06",
"Instructions": []
}
Stop overwriting of the module manifest
Crescendo creates each the module .psm1
and the module manifest .psd1
when
Export-CrescendoModule
is executed. This will create issues when you’ve gotten custom-made the module
manifest past the scope of Crescendo. The Export-CrescendoModule
cmdlet now supplies a
NoClobberManifest swap parameter to stop the manifest from being overwritten.
Export-CrescendoModule -ConfigurationFile .myconfig.json -ModuleName .Mymodule -NoClobberManifest
Observe
The NoClobberManifest swap parameter prevents Crescendo from
updating the module manifest. You’re answerable for manually updating the manifest with any new
cmdlets and settings.
Bypass output dealing with solely
Some native instructions reply with completely different output relying on whether or not the output is shipped to the
display or the pipeline. Pastel is an instance of a command that modifications its output
from a graphical display illustration to a single string worth when utilized in a pipeline. Crescendo
output dealing with is pipeline based mostly and may trigger these functions to return undesirable outcomes.
Crescendo now helps the flexibility to bypass the output handler solely.
To bypass all output dealing with by Crescendo:
"OutputHandlers": [
{
"ParameterSetName": "Default",
"HandlerType": "ByPass"
}
]
Dealing with error output
Beforehand, native command errors weren’t captured by Crescendo and allowed to stream on to
the consumer. This prevented you from creating enhanced error dealing with. Crescendo now captures the
generated command error output (stderr) and is now accessible to the output handler. Error messages
are positioned in a queue. You may entry the queue in your output handler utilizing a brand new perform,
Pop-CrescendoNativeError
.
In the event you don’t outline an output handler, Crescendo makes use of the default handler. The default output
handler ensures that errors respect the -ErrorVariable
and -ErrorAction
parameters and provides
errors to $Error
.
Including an output handler that features Pop-CrescendoNativeError
permits you to examine errors in
the output handler so you’ll be able to deal with them or cross them by to the caller.
"OutputHandlers": [
{
"ParameterSetName": "Default",
"StreamOutput": true,
"HandlerType": "Inline",
"Handler": "PROCESS { $_ } END { Pop-CrescendoNativeError -EmitAsError }"
}
]
Argument worth transformation
You could discover conditions the place the enter values handed to a Crescendo wrapped command must be
translated to a distinct worth for the underlying native command. Crescendo now helps argument
transformation to assist these eventualities. We up to date the schema so as to add two new members to the
Parameter class, ArgumentTransform
and ArgumentTransformType
. Use these members to remodel
parameter arguments inline or invoke a script block that takes the parameter worth as an argument.
The default worth for ArgumentTransformType
is inline.
Instance: Multiplication of a worth.
"Parameters": [
{
"Name": "mult2",
"OriginalName": "--p3",
"ParameterType": "int",
"OriginalPosition": 2,
"ArgumentTransform": "param([int]$v) $v * 2"
}
]
Instance: Accepting an ordered hashtable.
"Parameters": [
{
"Name": "hasht2",
"OriginalName": "--p1ordered",
"ParameterType": "System.Collections.Specialized.OrderedDictionary",
"OriginalPosition": 0,
"ArgumentTransform": "param([System.Collections.Specialized.OrderedDictionary]$v) $v.Keys.ForEach({''{0}={1}'' -f $_,$v[$_]}) -join '',''"
}
]
Instance: Argument transformation with be a part of.
"Parameters": [
{
"Name": "join",
"OriginalName": "--p2",
"ParameterType": "string[]",
"OriginalPosition": 1,
"ArgumentTransform": "param([string[]]$v) $v -join '',''"
}
]
Instance: Calling a script based mostly transformation.
"Parameters": [
{
"Name" : "Param1",
"ArgumentTransform": "myfunction",
"ArgumentTransformType" : "function"
}
]
Extra data
To get began utilizing Crescendo, take a look at the documentation.
Future plans
We worth your concepts and suggestions and hope you give Crescendo a attempt. Cease by our
GitHub repository and tell us of any points you discover or options you want to added.