How to Completely Uninstall the Microsoft Graph PowerShell SDK
The Microsoft Graph PowerShell module is a critical tool for administrators managing Microsoft Entra ID and Microsoft 365. However, you may encounter scenarios such as module bloat, version conflicts, or corruption where standard updates fail. In these instances, the most effective solution is to perform a complete removal of the SDK and start with a fresh installation.
Prerequisites:
This guide covers removal across:
– Environments: Windows PowerShell (v5.1) and PowerShell (v7.x+).
– Scopes: Current User and All Users.
– Managers: Modules installed via PowerShellGet or the newer PSResourceGet.
Step 1: Inventory Installed Modules
Before attempting removal, identify which Graph modules are currently present. This helps verify that the uninstallation commands target the correct versions.
Run the following commands in your terminal:
# Check for modules using PowerShellGet (Standard)
Get-InstalledModule Microsoft.Graph* -ErrorAction SilentlyContinue
# Check for modules using PSResourceGet (Newer)
Get-InstalledPSResource Microsoft.Graph* -Scope CurrentUser -ErrorAction SilentlyContinue
Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers -ErrorAction SilentlyContinue
Step 2: Uninstall Modules via Package Manager
Attempt to uninstall the modules using standard package management cmdlets first. Because the Microsoft Graph SDK consists of many sub-modules, we use the wildcard (*) to target all related components.
Run the following commands to remove modules for both the current user and all users:
# Option A: Uninstall via PowerShellGet
Get-InstalledModule Microsoft.Graph* | Uninstall-Module -AllVersions -Force -ErrorAction SilentlyContinue
# Option B: Uninstall via PSResourceGet (for newer installations)
Get-InstalledPSResource Microsoft.Graph* -Scope CurrentUser | Uninstall-PSResource -Scope CurrentUser -SkipDependencyCheck -ErrorAction SilentlyContinue
Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers | Uninstall-PSResource -Scope AllUsers -SkipDependencyCheck -ErrorAction SilentlyContinue
Step 3: Manually Delete Residual Folders
Standard uninstallation commands often fail to remove every dependency, particularly if files are locked or versioning is inconsistent. To ensure a completely clean state, use the script below to physically delete the module folders from the disk.
Instructions:
- Open your PowerShell console as an Administrator.
- Copy and run the script below
- Note for non-English OS users: Ensure the “Documents” path matches your system’s folder structure
# Define standard module paths for Windows PowerShell and PowerShell Core
$paths = @(
"$env:ProgramFiles\WindowsPowerShell\Modules", # Windows PowerShell (All Users)
"$env:USERPROFILE\Documents\WindowsPowerShell\Modules", # Windows PowerShell (Current User)
"$env:ProgramFiles\PowerShell\Modules", # PowerShell 7+ (All Users)
"$env:USERPROFILE\Documents\PowerShell\Modules" # PowerShell 7+ (Current User)
)
Write-Host "Starting manual cleanup of Microsoft Graph modules..." -ForegroundColor Cyan
# Iterate through paths and remove Graph directories
foreach ($path in $paths) {
if (Test-Path $path) {
Get-ChildItem -Path $path -Filter "Microsoft.Graph*" -Directory -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host "Removing: $($_.FullName)" -ForegroundColor Yellow
Remove-Item -Path $_.FullName -Recurse -Force -ErrorAction SilentlyContinue
}
}
}
Write-Host "Cleanup complete." -ForegroundColor Green
Conclusion
By following this three-step process—inventory, standard uninstallation, and manual file cleanup—you ensure that the Microsoft Graph PowerShell SDK is completely removed from your system. This prepares your environment for a clean, conflict-free reinstallation of the latest version.
