[BUG] $psdefaultparametervalues are overwritten on powershell startup
- Dominant language
- PowerShell
- Stars
- 273
- Forks
- 117
- Avg merge
- 1h
- Merged PRs (30d)
- 2
Description
## To Reproduce
Execute the variable name `$PSDefaultParameterValues`
The following are setup in startup of the container or loading powershell.
```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
```powershell
$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:
```powershell
$Global:PSDefaultParameterValues = @{
'Install-Module:Scope' = 'CurrentUser'
'Install-Script:Scope' = 'CurrentUser'
'*-Az*:ResourceGroupName' = { if ($pwd -like $script:pathPattern) { ($pwd -split $script:pathSeparator)[3] } }
}
```
Do this:
```powershell
$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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.