Skip to content

Replace Get-InstalledModule with Get-Module -ListAvailable #20632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/Az.Tools.Installer/Az.Tools.Installer.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class ModuleInfo
function Remove-AzureRM {
process {
try {
$azureModuleNames = (Get-InstalledModule -Name Azure* -ErrorAction Stop).Name | Where-Object {$_ -match "Azure(\.[a-zA-Z0-9]+)?" -or $_ -match "AzureRM(\.[a-zA-Z0-9]+)?"}
$azureModuleNames = (Microsoft.PowerShell.Core\Get-Module -ListAvailable -Name Azure* -ErrorAction Stop).Name | Where-Object {$_ -match "Azure(\.[a-zA-Z0-9]+)?" -or $_ -match "AzureRM(\.[a-zA-Z0-9]+)?"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jin Lei, are we systematically changing from *-InstalledModule to *-Module? Or is this just a special case? Can you explain more?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jin Lei, are we systematically changing from *-InstalledModule to *-Module? Or is this just a special case? Can you explain more?

This is the only usage of Get-InstalledModule in product codes for now and I just want to correct it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recapping our conversation, Get-InstalledModule can't get modules that are not installed by Install-Module. But Get-Module -ListAvailable can.

foreach ($moduleName in $azureModuleNames) {
PowerShellGet\Uninstall-Module -Name $moduleName -AllVersion -AllowPrerelease -ErrorAction Continue
}
Expand Down
1 change: 1 addition & 0 deletions tools/Az.Tools.Installer/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Upcoming Release
* Remove the usage of `Get-InstalledModule` from product codes.
## 0.2.1
* Fixed the issue of installation and updating when Repository is not provided (#20209)
* Updated telemetry assembly to 2.13.1
Expand Down