IntuneAdminRoles.psm1

# IntuneAdminRoles.psm1

# --- Dependency Check ---
# Define required modules and their minimum versions.
$requiredModules = @(
    @{ Name = 'Microsoft.Graph.Beta.DeviceManagement'},
    @{ Name = 'Microsoft.Graph.Beta.DeviceManagement.Administration'},
    @{ Name = 'Microsoft.Graph.Beta.DeviceManagement.Actions'},
    @{ Name = 'Microsoft.Graph.Beta.Groups'}
)

foreach ($mod in $requiredModules) {
    if (-not (Get-Module -ListAvailable -Name $mod.Name)) {
        Write-Host "Module '$($mod.Name)' is not installed. Attempting to install..." -ForegroundColor Yellow
        try {
            Install-Module -Name $mod.Name -Force -Scope CurrentUser -ErrorAction Stop
            Write-Host "Module '$($mod.Name)' installed successfully." -ForegroundColor Green
        }
        catch {
            Write-Warning "Failed to install module '$($mod.Name)'. Please install it manually."
        }
    }
}

# --- Module Functions ---
# Determine the module root and functions folder paths.
$moduleRoot = Split-Path -Parent $MyInvocation.MyCommand.Definition
$functionsPath = Join-Path $moduleRoot "Functions"

# Dot-source each function file.
. (Join-Path $functionsPath "Connect-IntuneGraph.ps1")
. (Join-Path $functionsPath "New-IntuneAdminRole.ps1")
. (Join-Path $functionsPath "New-IntuneRoleAssignment.ps1")
. (Join-Path $functionsPath "New-IntuneScopeTag.ps1")
. (Join-Path $functionsPath "New-IntuneDynamicDeviceGroup.ps1")
. (Join-Path $functionsPath "New-IntuneRoleAssignmentGroup.ps1")
. (Join-Path $functionsPath "Add-IntuneScopeTagToRoleAssignment.ps1")
. (Join-Path $functionsPath "Get-IntuneAdminRoleReport.ps1")

# Export the module functions.
Export-ModuleMember -Function `
    Connect-IntuneGraph, `
    New-IntuneAdminRole, `
    New-IntuneRoleAssignment, `
    New-IntuneDynamicDeviceGroup, `
    New-IntuneRoleAssignmentGroup, `
    New-IntuneScopeTag, `
    Add-IntuneScopeTagToRoleAssignment, `
    Get-IntuneAdminRoleReport