Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
Info

This will perform the following actions for each PowerShell module:

  • Remove the modules from the current session if loaded

  • Update the module if installed and install the module if not

Unload

Graph

Azure PowerShell modules respecting the dependency on

Microsoft

Az.

Graph.Authentication

Accounts

Code Block
# get loaded modules with base module split out
$Modules, $BaseModule = (Get-Module -Name 'Az.*').Where({$_.Name -ne 'Az.Accounts'},[System.Management.Automation.WhereOperatorSelectionMode]::Split)
# unload modules with base module last
$Modules | ForEach-Object { Remove-Module -Name $_.Name -Force }; $BaseModule | ForEach-Object { Remove-Module -Name $_.Name -Force }

Update

Graph

Azure PowerShell modules

Code Block
Get-Module -ListAvailable -Name Az.* | ForEach-Object { Update-Module -Name $_.Name } 

...

Expand
Info

This will perform the following actions for each PowerShell module:

  • Remove the modules from the current session if loaded

  • Remove the module files from the AllUsers scope

  • Install the modules from the PowerShell gallery

Unload Azure PowerShell modules respecting the dependency on Az.Accounts

Code Block
# get loaded modules with base module split out
$Modules, $BaseModule = (Get-Module -Name 'Az.*').Where({$_.Name -ne 'Az.Accounts'},[System.Management.Automation.WhereOperatorSelectionMode]::Split)
# unload modules with base module last
$Modules | ForEach-Object { Remove-Module -Name $_.Name -Force }; $BaseModule | ForEach-Object { Remove-Module -Name $_.Name -Force }

Remove Azure PowerShell modules

Code Block
Get-ChildItem -Path "$env:ProgramFiles\WindowsPowerShell\Modules" -Filter 'Az.*' | Remove-Item -Recurse -Force

Install Azure PowerShell modules

Code Block
Save-Module -Path "$env:ProgramFiles\WindowsPowerShell\Modules" -Name Az -Force

...