Azure / Azure/CloudShell

[BUG] $psdefaultparametervalues are overwritten on powershell startup

Aperta
#132 4 commenti 0 reazioni 1 assegnatario Rivendicata da @theJasonHelmick Vedi su GitHub
Area-image bug Iteration-Backlog Status-In_review
Lingua principale
PowerShell
Stelle
273
Fork
117
Merge medio
1h
PR unite (30g)
2

Descrizione

## 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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.