How to update powershell az.accounts to latest version?

Osama Mahmudi 0 Reputation points
2024-09-11T12:26:58.93+00:00

When I start powershell in azure cloud, I encounter the following error, how to resolve it?

"Requesting a Cloud Shell.Succeeded.

Connecting terminal...

Import-Module: /opt/microsoft/powershell/7/profile.ps1:13

Line |

13 | Microsoft.PowerShell.Core\Import-Module -Name PSCloudShellUtility

 |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 | This module requires Az.Accounts version 3.0.4. 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:310

Line |

310 | & ($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:66

Line |

66 | & ($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:97

Line |

97 | 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:66

Line |

66 | & ($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:66

Line |

66 | & ($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:384

Line |

384 | Microsoft.PowerShell.Core\Import-Module -Name AzurePSDrive

 |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 | This module requires Az.Accounts version 3.0.4. 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:66

Line |

66 | & ($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:395

Line |

395 | $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:66

Line |

66 | & ($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:408

Line |

408 | & ($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:66

Line |

66 | & ($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."
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-09-12T01:21:21.6533333+00:00

    Hi Osama Mahmudi, Thanks for your post.

    You can try installing the specified version of az.accounts in the Azure cloud shell.

    Install-Module -Name Az.Accounts -RequiredVersion 3.0.4
    

    Then create a new cloud shell session to use it.

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.