Private/Connect-EgmGraph.ps1
|
function Connect-EgmGraph { <# .SYNOPSIS Ensures the Microsoft Graph SDK is available and a session with the required scopes exists. #> [CmdletBinding()] param() $required = 'Microsoft.Graph.Authentication', 'Microsoft.Graph.Users', 'Microsoft.Graph.Groups' $missing = $required | Where-Object { -not (Get-Module -ListAvailable -Name $_) } if ($missing) { throw "Missing modules: $($missing -join ', '). Install with: Install-Module Microsoft.Graph -Scope CurrentUser" } $scopes = 'User.Read.All', 'Group.ReadWrite.All' $ctx = Get-MgContext if (-not $ctx -or ($scopes | Where-Object { $ctx.Scopes -notcontains $_ })) { Connect-MgGraph -Scopes $scopes -NoWelcome } } |