Azure PowerShell error when startup

Trương Chí Diễn 0 Reputation points
2023-03-13T02:01:53.93+00:00

My Azure PowerShell always throws this error whenever I start a session. I tried to delete the resource group for PowerShell and then create a new one but it's still not working.

Import-Module: /opt/microsoft/powershell/7/profile.ps1:13
Line |
  13 |  Microsoft.PowerShell.Core\Import-Module -Name PSCloudShellUtility
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | This module requires Az.Accounts version 2.12.0. An earlier version of Az.Accounts is imported in the current PowerShell session. Please open a new session before importing this module. This error could indicate that multiple
     | incompatible versions of the Azure PowerShell cmdlets are installed on your system. Please see https://aka.ms/azps-version-error for troubleshooting information.
InvalidOperation: /opt/microsoft/powershell/7/profile.ps1:308
Line |
 308 |  & ($script:PSCloudShellUtilityModuleInfo){Get-CloudShellTip -ErrorAct …
     |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
VERBOSE: Authenticating to Azure ...
InvalidOperation: /opt/microsoft/powershell/7/profile.ps1:64
Line |
  64 |      & ($script:PSCloudShellUtilityModuleInfo){param([string]$Label, [ …
     |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
Invoke-CloudShellTelemetry: /opt/microsoft/powershell/7/profile.ps1:95
Line |
  95 |          Invoke-CloudShellTelemetry -LogLabel "GETSUBSCRIPTIONID" -Sta …
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
InvalidOperation: /opt/microsoft/powershell/7/profile.ps1:64
Line |
  64 |      & ($script:PSCloudShellUtilityModuleInfo){param([string]$Label, [ …
     |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
InvalidOperation: /opt/microsoft/powershell/7/profile.ps1:64
Line |
  64 |      & ($script:PSCloudShellUtilityModuleInfo){param([string]$Label, [ …
     |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
InvalidOperation: /opt/microsoft/powershell/7/profile.ps1:64
Line |
  64 |      & ($script:PSCloudShellUtilityModuleInfo){param([string]$Label, [ …
     |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
Import-Module: /opt/microsoft/powershell/7/profile.ps1:395
Line |
 395 |      Microsoft.PowerShell.Core\Import-Module -Name AzurePSDrive
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | This module requires Az.Accounts version 2.12.0. An earlier version of Az.Accounts is imported in the current PowerShell session. Please open a new session before importing this module. This error could indicate that multiple
     | incompatible versions of the Azure PowerShell cmdlets are installed on your system. Please see https://aka.ms/azps-version-error for troubleshooting information.
VERBOSE: Building your Azure drive ...
InvalidOperation: /opt/microsoft/powershell/7/profile.ps1:64
Line |
  64 |      & ($script:PSCloudShellUtilityModuleInfo){param([string]$Label, [ …
     |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
New-PSDrive: /opt/microsoft/powershell/7/profile.ps1:406
Line |
 406 |      $null = Microsoft.PowerShell.Management\New-PSDrive -Name Azure - …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find a provider with the name 'SHiPS'.
WARNING: Something went wrong while creating Azure drive. You can still use this shell to run Azure PowerShell commands.
InvalidOperation: /opt/microsoft/powershell/7/profile.ps1:64
Line |
  64 |      & ($script:PSCloudShellUtilityModuleInfo){param([string]$Label, [ …
     |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
InvalidOperation: /opt/microsoft/powershell/7/profile.ps1:419
Line |
 419 |  & ($script:PSCloudShellUtilityModuleInfo){Set-CloudShellPSReadLineKey …
     |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
InvalidOperation: /opt/microsoft/powershell/7/profile.ps1:64
Line |
  64 |      & ($script:PSCloudShellUtilityModuleInfo){param([string]$Label, [ …
     |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,085 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. chinjila 35 Reputation points
    2023-06-28T04:15:06.8666667+00:00

    Had the same problem, turns out under:

    /home/[username]/.local/share/powershell/Modules

    there are some conflicting modules, namely Az.Accounts of outdated version. It seems to take priority over the default modules provided by Azure Cloud Shell.

    I ran the following command in Cloud shell

    rm -rf ~/.local/share/powershell/Modules

    followed by restarting the cloudshell.

    7 people found this answer helpful.

  2. Manu Philip 16,986 Reputation points MVP
    2023-03-13T05:03:43.0266667+00:00

    The similar issue has reported by another user before and solved by my solution as below:

    https://learn.microsoft.com/en-us/answers/questions/903709/cloudshell


    --please don't forget to upvote and Accept as answer if the reply is helpful--

    2 people found this answer helpful.
    0 comments No comments