FIX-ASSEMBLY-CONFLICT.ps1

<#
.SYNOPSIS
    Fix script for assembly conflicts with Microsoft.Graph modules
     
.DESCRIPTION
    This script removes all loaded Microsoft.Graph modules to resolve assembly conflicts.
    Run this before starting the Intune AI module if you encounter assembly conflicts.
     
.EXAMPLE
    .\FIX-ASSEMBLY-CONFLICT.ps1
#>


Write-Host "Fixing Microsoft.Graph assembly conflicts..." -ForegroundColor Cyan
Write-Host ""

# Get all loaded Microsoft.Graph modules
$loadedModules = Get-Module -Name "Microsoft.Graph.*" | Select-Object -ExpandProperty Name

if ($loadedModules.Count -eq 0) {
    Write-Host "No Microsoft.Graph modules currently loaded." -ForegroundColor Green
} else {
    Write-Host "Removing loaded modules:" -ForegroundColor Yellow
    foreach ($module in $loadedModules) {
        Write-Host " - $module" -ForegroundColor Gray
        Remove-Module -Name $module -Force -ErrorAction SilentlyContinue
    }
    Write-Host ""
    Write-Host "Modules removed successfully." -ForegroundColor Green
}

# Also remove the Intune AI module if loaded
$intuneModule = Get-Module -Name "ai-enterprise-intune-compliance" -ErrorAction SilentlyContinue
if ($intuneModule) {
    Write-Host "Removing ai-enterprise-intune-compliance module..." -ForegroundColor Yellow
    Remove-Module -Name "ai-enterprise-intune-compliance" -Force -ErrorAction SilentlyContinue
    Write-Host "Module removed." -ForegroundColor Green
}

Write-Host ""
Write-Host "You can now start the module with:" -ForegroundColor Cyan
Write-Host " .\Start-IntuneAI.ps1" -ForegroundColor White
Write-Host ""