Skip to content

[BUG] $psdefaultparametervalues are overwritten on powershell startup #132

Open

Description

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

Activity

  1. added
    bug
    on Jan 13, 2022
  2. added
    Area-image
    Iteration-Current
    Status-In_review
    on Jun 9, 2022
  3. added
    Iteration-Backlog
    and removed
    Iteration-Current
    on Jun 30, 2022
  4. dsajanice commented on Jun 30, 2022

    @dsajanice
    Member

    We're moving this back to the backlog due to higher priorities. Please upvote this issue if you need it fixed sooner.

  5. theJasonHelmick commented on Oct 17, 2022

    @theJasonHelmick
    Member

    Ben Wilkinson (@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.

  6. mbifeld commented on Feb 10, 2026

    @mbifeld
    Member

    Hey Ben Wilkinson (@brwilkinson), is this still an active issue for you?

  7. brwilkinson commented on Feb 15, 2026

    @brwilkinson
    Author

    Mitchell Bifeld (@mbifeld) I am not actively using Cloudshell on current projects. I believe it's still likely broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area-imageIteration-BacklogStatus-In_reviewbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions