Parameter position ON/OFF switch with $PSDefaultParameterValues - by S.K. _

Status : 


Sign in
to vote
ID 775553 Comments
Status Active Workarounds
Type Suggestion Repros 0
Opened 1/1/2013 11:29:58 PM
Access Restriction Public


*** [PRECONDITION] $PSDefaultParameterValues is exist for short typing ***

When I use $PSDefaultParameterValues against parameters that have position,
I want they to turn off their position.

In New-PSDrive, -PSProvider parameter has position 2, and -Root parameter has position 3. 
Even if I substitute a default value for -PSProvider parameter,
 I cannot set -Root parameter's value without -PSProvider parameter's value using positions.

>> $PSDefaultParameterValues['New-PSDrive:PSProvider'] = "FileSystem"

>> New-PSDrive K //server/share ### want to set folder path to -Root parameter ###

cmdlet New-PSDrive at command pipeline position 1
Supply values for the followingparameters:

For avoiding this, I need to use named parameter

>> New-PSDrive K -Root //server/share # using named parameter

>> New-PSDrive K FileSystem //server/share # without defalut parameter

Now, there is no meaning using $PSDefaultParameterValues for short typing, yey!! :-<

If there is position ON/OFF switch...

>>> $PSDefaultParameterValues['New-PSDrive:PSProvider'].position = $false

>> New-PSDrive K //server/share

Name      Used (GB)     Free (GB) Provider      Root                 CurrentLocation
----      ---------     --------- --------      ----                 ---------------
K                            5.30 FileSystem    //server/share

Yey, I get short typing. 
Sign in to post a comment.