CloudShell
CloudShell copied to clipboard
[BUG] $psdefaultparametervalues are overwritten on powershell startup
To Reproduce
Execute the variable name $PSDefaultParameterValues
The following are setup in startup of the container or loading powershell.
$PSDefaultParameterValues
Name Value
---- -----
Install-Module:Scope CurrentUser
Install-Script:Scope CurrentUser
*-Az*:ResourceGroupName if($pwd -like $script:pathPattern){($pwd -split $script:pathSeparator)[3]}
Now if I want to use a powershell profile, I cannot define or use $PSDefaultParameterValues
because it's being over written.
Example code that runs in my own profile
$PROFILE | select *
CurrentUserAllHosts CurrentUserCurrentHost Length
------------------- ---------------------- ------
/home/ben/.config/PowerShell/profile.ps1 /home/ben/.config/PowerShell/Microsoft.PowerShell_profile.ps1 61
# in my $profile.CurrentUserAllHosts, let say I have the following
Set-Alias -Name ls -Value Get-ChildItem -Force -Scope Global
$PSDefaultParameterValues['Get-ChildItem:Force'] = $true # I set this, however you overwrite it....
Expected behavior
Modify the way that you are setting your psdefaultparameter values as follows:
Instead of this:
$Global:PSDefaultParameterValues = @{
'Install-Module:Scope' = 'CurrentUser'
'Install-Script:Scope' = 'CurrentUser'
'*-Az*:ResourceGroupName' = { if ($pwd -like $script:pathPattern) { ($pwd -split $script:pathSeparator)[3] } }
}
Do this:
$PSDefaultParameterValues['Install-Module:Scope'] = 'CurrentUser'
$PSDefaultParameterValues['Install-Script:Scope'] = 'CurrentUser'
$PSDefaultParameterValues['*-Az*:ResourceGroupName'] = { if ($pwd -like $script:pathPattern) { ($pwd -split $script:pathSeparator)[3] } }
That way you are adding the values that you want to set to the Global variable, which is hashtable, however you are not wiping out any other values that are already set in there.
AB#14681398
We're moving this back to the backlog due to higher priorities. Please upvote this issue if you need it fixed sooner.
@brwilkinson - Thank you for reporting this issue. Creating a CurrentUser profile will normally allow you to add/change values from AllUsers profile - however in this case that is not occurring. I can reproduce and am investigating a solution.
In the meantime, one workaround is to use the Add
method of $PSDefaultParameterValues
. You can execute this directly at the prompt in Cloud Shell, or add to a script to execute.
$PSDefaultParameterValues.add('Get-ChildItem:Force', $true)
Then $PSDefaultParameterValues will have the new entry.
Investigating why a CurrentUser profile does not Add
to this variable.