Open lgabor85 opened 7 months ago
Thanks for your feedback! @msJinLei please look into this issue. Thanks.
Hi @lgabor85 it is because you cannot uninstall modules in the path
Directory: C:\Program Files\WindowsPowerShell\Modules
from Powershell Core. These modules can only be uninstalled by windows Powershell. Try to start a windows Powershell terminal from vscode
Thanks for looking into it @msJinLei !
I tried another repro. Here is what I`ve done and the results:
1) Open an elevated WindowsPowershell terminal
PS C:\> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 22621 2506
PS C:\> $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')
PS C:\> $isAdmin
True
1.1) Update the Az modules using cmdlet Update-AzModules
PS C:\> Update-AzModule -Name Az -WhatIf
WARNING: Az.Tools.Installer cannot be used to install Az. Will discard Az in the Name parameter.
What if: Remove Az if installed
WhatIf: Will update Az.Accounts from 2.15.0 to 2.15.1.
WhatIf: Will update Az.Aks from 6.0.0 to 6.0.1.
WhatIf: Will update Az.DataFactory from 1.18.0 to 1.18.1.
WhatIf: Will update Az.KeyVault from 5.1.0 to 5.2.0.
WhatIf: Will update Az.Migrate from 2.2.0 to 2.3.0.
WhatIf: Will update Az.Monitor from 5.0.0 to 5.0.1.
WhatIf: Will update Az.Network from 7.3.0 to 7.4.0.
WhatIf: Will update Az.RecoveryServices from 6.7.0 to 6.7.1.
WhatIf: Will update Az.Resources from 6.13.0 to 6.15.1.
WhatIf: Will update Az.Sql from 4.13.0 to 4.14.0.
WhatIf: Will update Az.SqlVirtualMachine from 2.1.0 to 2.2.0.
WhatIf: Will update Az.StackHCI from 2.2.3 to 2.3.0.
WhatIf: Will update Az.Storage from 6.1.0 to 6.1.1.
WhatIf: Will update Az.Websites from 3.1.2 to 3.2.0.
PS C:\> Update-AzModule -Name Az
WARNING: Az.Tools.Installer cannot be used to install Az. Will discard Az in the Name parameter.
Name VersionBeforeUpdate VersionUpdate
---- ------------------- -------------
Az.Accounts 2.15.0 2.15.1
Az.Aks 6.0.0 6.0.1
Az.DataFactory 1.18.0 1.18.1
Az.KeyVault 5.1.0 5.2.0
Az.Migrate 2.2.0 2.3.0
Az.Monitor 5.0.0 5.0.1
Az.Network 7.3.0 7.4.0
Az.RecoveryServices 6.7.0 6.7.1
Az.Resources 6.13.0 6.15.1
Az.Sql 4.13.0 4.14.0
Az.SqlVirtualMachine 2.1.0 2.2.0
Az.StackHCI 2.2.3 2.3.0
Az.Storage 6.1.0 6.1.1
Az.Websites 3.1.2 3.2.0
1.2) Pick a module and list its available versions
PS C:\> Get-Module -Name Az.Accounts -ListAvailable
Directory: C:\Users\<USER>\OneDrive - <COMPANY>\Documenten\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.15.1 Az.Accounts {Disable-AzDataCollection, Disable-AzContextAutosave, Enab...
2) Repeat the same in PWSH7/Core
PS C:\> $PSVersionTable.PSVersion
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
7 3 11
PS C:\> $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')
PS C:\> echo $isAdmin
True
PS C:\> Update-AzModule -Name Az -WhatIf
WARNING: Az.Tools.Installer cannot be used to install Az. Will discard Az in the Name parameter.
What if: Remove Az if installed
WhatIf: Will update Az.Accounts from 2.15.0 to 2.15.1.
WhatIf: Will update Az.Aks from 6.0.0 to 6.0.1.
WhatIf: Will update Az.DataFactory from 1.18.0 to 1.18.1.
WhatIf: Will update Az.KeyVault from 5.1.0 to 5.2.0.
WhatIf: Will update Az.Monitor from 5.0.0 to 5.0.1.
WhatIf: Will update Az.Network from 7.3.0 to 7.4.0.
WhatIf: Will update Az.RecoveryServices from 6.7.0 to 6.7.1.
WhatIf: Will update Az.Resources from 6.13.0 to 6.15.1.
WhatIf: Will update Az.Sql from 4.13.0 to 4.14.0.
WhatIf: Will update Az.StackHCI from 2.2.3 to 2.3.0.
WhatIf: Will update Az.Storage from 6.1.0 to 6.1.1.
WhatIf: Will update Az.Websites from 3.1.2 to 3.2.0.
PS C:\> Update-AzModule -Name Az
WARNING: Az.Tools.Installer cannot be used to install Az. Will discard Az in the Name parameter.
WARNING: The version '2.15.0' of module 'Az.Accounts' is currently in use. Retry the operation after closing the applications.
WARNING: The version '7.3.0' of module 'Az.Network' is currently in use. Retry the operation after closing the applications.
WARNING: The version '6.13.0' of module 'Az.Resources' is currently in use. Retry the operation after closing the applications.
Name VersionBeforeUpdate VersionUpdate
---- ------------------- -------------
Az.Accounts 2.15.0 2.15.1
Az.Aks 6.0.0 6.0.1
Az.DataFactory 1.18.0 1.18.1
Az.KeyVault 5.1.0 5.2.0
Az.Monitor 5.0.0 5.0.1
Az.Network 7.3.0 7.4.0
Az.RecoveryServices 6.7.0 6.7.1
Az.Resources 6.13.0 6.15.1
Az.Sql 4.13.0 4.14.0
Az.StackHCI 2.2.3 2.3.0
Az.Storage 6.1.0 6.1.1
Az.Websites 3.1.2 3.2.0
PS C:\> Get-Module -Name Az.Accounts -ListAvailable
Directory: C:\Users\<USER>\OneDrive - <COMPANY>\Documenten\PowerShell\Modules
ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Script 2.15.1 Az.Accounts Core,Desk {Disable-AzDataCollection, Disable-AzCo…
Script 2.15.0 Az.Accounts Core,Desk {Disable-AzDataCollection, Disable-AzCo…
To me it looks like that the cmdlet doesn`t work properly in PWSH7/Core edition. Maybe it was related to me being logged in to my Azure account in VSCode PWSH at the time.
Description
As discussed here, the cmdlet Update-AzModule will install the latest Az modules but not remove older versions when it is run in a VSCode integrated terminal, even if run with admin privileges.
If run in a separate, elevated windows terminal, the cmdlet executes as expected and replaces the old versions with the latest.
Issue script & Debug output
Environment data
Module versions
Error output