Skip to content

When I upgrade to Powershell 7.0.0 I'm unable to load powershellget and get errors pointing to importing Microsoft.Powershell.utility #12040

Closed

Description

  • Make sure you are able to repro it on the [latest released version]: 7.0.0
  • Search the existing issues.
  • Refer to the FAQ.
  • Refer to the known issues.

Steps to reproduce

Upgraded powershell from powershell.exe prompt to avoid conflicts to 7.0.0. Rebooted to avoid this issue being environment scoped.

choco upgrade powershell-core
Get-InstalledModule powershellget
# OR
Import-Module PowershellGet

Expected behavior

Return the module without error.

Actual behavior

InvalidOperation: C:\Users\USERNAME\Documents\WindowsPowerShell\Modules\PowerShellGet\2.2.1\PSModule.psm1:327 
Line |  327 |      $NoMatchFound = $LocalizedData.NoMatchFound     
~~~~~~~~~~~~~~
| The variable '$LocalizedData' cannot be retrieved because it has not been set.

When trying to import powershellget i've also found the error a little more specific:

Import-LocalizedData: C:\Users\USERNAME\Documents\WindowsPowerShell\Modules\Powershellget\2.2.1\PSModule.psm1:1
Line |
   1 |  Import-LocalizedData LocalizedData -filename PSGet.Resource.psd1
     |  ~~~~~~~~~~~~~~~~~~~~
     | The 'Import-LocalizedData' command was found in the module
     | 'Microsoft.PowerShell.Utility', but the module could not be loaded. For more
     | information, run ....

Trying to run the suggested command Import-Module Microsoft.Powershell.utility and I get the following:

Import-Module: Failed to generate proxies for remote module 'Microsoft.PowerShell.Utility'. The 'Export-PSSession' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.

Environment data


Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Mar 5, 2020
  2. changed the title [-]My bug report[/-] [+]When I upgrade to Powershell 7.0.0 I'm unable to load many modules and get errors pointing to importing Microsoft.Powershell.utility[/+] on Mar 5, 2020
  3. changed the title [-]When I upgrade to Powershell 7.0.0 I'm unable to load many modules and get errors pointing to importing Microsoft.Powershell.utility[/-] [+]When I upgrade to Powershell 7.0.0 I'm unable to load powershellget and get errors pointing to importing Microsoft.Powershell.utility[/+] on Mar 5, 2020
  4. anmenaga commented on Mar 6, 2020

    @anmenaga

    Looks like version 2.2.1 of PowerShellGet is not the latest one and installed in WindowsPowerShell module path; So I would first try to install the latest one from pwsh by
    Install-Module -Name PowerShellGet -MinimumVersion 2.2.3 -Repository PSGallery
    then start a fresh pwsh 7.0.0 from desktop (as opposed to 'from other pwsh' or 'from powershell.exe') and do the Import-Module PowershellGet.

  5. sheldonhull commented on Mar 6, 2020

    @sheldonhull
    Author

    This helped point me in the right direction. I figured it might be a conflict with versions. Here's what failed

    $PSModulePath = @(
    "$ENV:USERPROFILE\Documents\WindowsPowerShell\Modules"
    ,'C:\ProgramData\Boxstarter'
    ,'C:\Program Files\WindowsPowerShell\Modules'
    ,'C:\Windows\System32\WindowsPowerShell\v1.0\Modules'
    ,'C:\Program Files (x86)\Red Gate\SQL Change Automation PowerShell\Modules'
    ,"$ENV:USERPROFILE\Documents\WindowsPowerShell\modules"
    ,'C:\Program Files\PowerShell\Modules'
    ,'c:\Program Files\powershell\7\Modules'
    ,"$ENV:USERPROFILE\Documents\PowerShell\Modules"
    )
    $ENV:PSModulePath = $PSModulePath -join ';'
    
    
    Import-Module PowerShellGet
    

    Then I moved to powershell/7/Modules above the other path and it correctly ran like below:

    $PSModulePath = @(
    "$ENV:USERPROFILE\Documents\WindowsPowerShell\Modules"
    ,'C:\ProgramData\Boxstarter'
    ,'C:\Program Files\WindowsPowerShell\Modules'
    ,'C:\Windows\System32\WindowsPowerShell\v1.0\Modules'
    ,'C:\Program Files (x86)\Red Gate\SQL Change Automation PowerShell\Modules'
    ,"$ENV:USERPROFILE\Documents\WindowsPowerShell\modules"
    ,'c:\Program Files\powershell\7\Modules'
    ,'C:\Program Files\PowerShell\Modules'
    ,"$ENV:USERPROFILE\Documents\PowerShell\Modules"
    )
    $ENV:PSModulePath = $PSModulePath -join ';'
    
    Import-Module PowerShellGet

    This leads me to two main questions for those of us who have been using windows + core and not upgraded to 7.

    1. Are both of these folders used in 7? Is it something to do with compatibility?
      'c:\Program Files\powershell\7\Modules'
      'C:\Program Files\PowerShell\Modules'

    2. Do I need to distribute now some ranked psmodule path hierarchy to force certain ordering of psmodule path to avoid this type of error in the future?

  6. anmenaga commented on Mar 6, 2020

    @anmenaga

    sheldonhull (@sheldonhull) What looks suspicious to me is that WindowsPS paths precede CorePS paths.
    Is the order of paths in those arrays exactly like $ENV:PSModulePath value when a fresh pwsh is started?

    c:\Program Files\powershell\7\Modules - is probably the install location of PS Core,

  7. SteveL-MSFT commented on Mar 6, 2020

    @SteveL-MSFT
    Member

    PS7 puts the PS7 User path for modules ahead of the Windows PowerShell User path. sheldonhull (@sheldonhull) are you explicitly setting PSModulePath in your Profile or somewhere else?

  8. sheldonhull commented on Mar 7, 2020

    @sheldonhull
    Author

    Steve Lee (@SteveL-MSFT) I don't remember doing that, but I just edited to help solve that issue. Should I remove any entries or any type of prevention/fix I can apply in the future?

  9. SteveL-MSFT commented on Mar 18, 2020

    @SteveL-MSFT
    Member

    sheldonhull (@sheldonhull) hard to say without understanding what your specific use case is, but for most users, I would expect they don't mess with PSModulePath directly and so this shouldn't be a problem.

  10. ghost closed this as completedon Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions