Home Dashboard Directory Help
Search

Add module-level default parameter assignment support to PSDefaultParameterValues by Kirk Munro


Status: 

Active


2
0
Sign in
to vote
Type: Suggestion
ID: 844699
Opened: 4/1/2014 7:57:59 AM
Access Restriction: Public
0
Workaround(s)
view

Description

As PowerShell evolves, more patterns develop. With those patterns, you may have multiple modules that use the same pattern against different targets. For example, the SMA module has a WebServicesEndpoint common parameter that can be used to remotely manage SMA. Rather than using a variable or entering this all the time, it is easier to use PSDefaultParameterValues. Unfortunately, that either means setting the default value for WebServicesEndpoint for all cmdlets (global assignments should be discouraged) or setting it atomically on each cmdlet (which means updated versions of the module with new commands mean you need to revisit the assignments and add some for the new commands). I'm working on a module that will use WebServicesEndpoint as a parameter as well. With these patterns in mind, it becomes very important to allow PSDefaultParameterValues to be used to assign a default value to a single parameter across all commands that are part of a specific module. This way you can avoid the complexity and error that comes with atomic assignments while also avoiding the issues that come with global assignments.

I propose a syntax that leverages the fully-qualified command name format, as follows:

$PSDefaultParameterValues['Microsoft.SystemCenter.ServiceManagementAutomation\*:WebServicesEndpoint'] = 'https://sma.corp.poshoholicstudios.com'

This would also fix the issue with fully-qualified command names not being supported by this feature.

Details
Sign in to post a comment.
Sign in to post a workaround.