Skip to content

Update all Microsoft Cloud PowerShell modules

directorcia edited this page Jan 8, 2025 · 2 revisions
# PowerShell Script Overview

This PowerShell script ensures the system's necessary modules are up-to-date. Here's a breakdown of its functionality:

## Initialize Counter

- `$counter = 0`: Initializes a counter to keep track of the number of operations performed.

## Check for Administrator Privileges

```powershell
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
  • The script checks if it is running with administrator privileges using the current Windows user principal.

Conditional Logic

If ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
  • Executes the script only if it's running as an administrator.

NuGet Provider Update

if ($ps.Major -lt 7)
  • Checks if the PowerShell version is less than 7.
  • If true:
    • Increments the counter.
    • Updates the NuGet provider by calling test-package -packagename NuGet.

Azure AD Module Update

  • Increments the counter.
  • Updates the Azure AD module by calling test-install -modulename AzureAD.

Azure Information Protection Module Update

  • Increments the counter.
  • Checks if the older Azure AD Rights Management module (aadrm) is installed.
    • If the module exists:
      • Displays a warning message.
      • Uninstalls the outdated aadrm module.
  • Installs the Azure Information Protection service module by calling test-install -modulename AIPService.

Teams Module Update

  • Increments the counter.
  • Updates the Teams module by calling test-install -modulename MicrosoftTeams.

SharePoint Online Module Update

  • Increments the counter.
  • Updates the SharePoint Online module by calling test-install -modulename Microsoft.Online.SharePoint.PowerShell.

Summary

This script updates essential PowerShell modules (NuGet, AzureAD, AIPService, MicrosoftTeams, and Microsoft.Online.SharePoint.PowerShell) if executed with administrator privileges. It also ensures that outdated modules (e.g., aadrm) are removed.

Clone this wiki locally