Workloads/Get-CopilotData.ps1
|
# Get-CopilotData.ps1 # Collects Microsoft 365 Copilot and Copilot Studio licensing signals. # Part of the M365-QuickAssess module -- not exported. function Get-CopilotData { param ( $Assessment ) Write-Log "Collecting Copilot / AI data" try { $skus = Get-MgSubscribedSku -ErrorAction Stop if ( -not $skus ) { Write-Log "No SKUs returned from Graph" "WARN" $Assessment.AI.HasAILicenses = $null $Assessment.AI.AILicenseCount = $null $Assessment.AI.HasCopilot = $null return } # ------------------------------------------------------------------- # Microsoft 365 Copilot # ------------------------------------------------------------------- $m365Copilot = $skus | Where-Object { $_.SkuPartNumber -match "^MICROSOFT_365_COPILOT$|^M365_COPILOT$" } $m365Count = ( $m365Copilot | Measure-Object -Property ConsumedUnits -Sum ).Sum if ( -not $m365Count ) { $m365Count = 0 } # ------------------------------------------------------------------- # Copilot Studio # ------------------------------------------------------------------- $copilotStudio = $skus | Where-Object { $_.SkuPartNumber -like "CCIBOTS*" } $studioCount = ( $copilotStudio | Measure-Object -Property ConsumedUnits -Sum ).Sum if ( -not $studioCount ) { $studioCount = 0 } # ------------------------------------------------------------------- # Totals # ------------------------------------------------------------------- $totalLicenseCount = $m365Count + $studioCount $hasLicenses = ( $totalLicenseCount -gt 0 ) # ------------------------------------------------------------------- # Populate Schema # ------------------------------------------------------------------- $Assessment.AI.HasAILicenses = $hasLicenses $Assessment.AI.AILicenseCount = $totalLicenseCount $Assessment.AI.HasCopilot = ( $m365Count -gt 0 ) $Assessment.AI.HasAIAgents = ( $studioCount -gt 0 ) $Assessment.AI.AIAgentCount = $studioCount $Assessment.AI.IsAIDataReady = $null $Assessment.AI.HasAIGovernance = $null Write-Log "Copilot: M365Copilot=$m365Count CopilotStudio=$studioCount Total=$totalLicenseCount" # ------------------------------------------------------------------- # Findings # ------------------------------------------------------------------- if ( $m365Count -gt 0 ) { $Assessment.Findings += New-Finding ` -Type "CopilotLicensesDetected" ` -Summary "$m365Count Microsoft 365 Copilot licenses detected" ` -Category "AI" ` -Severity "Info" ` -Impact "Copilot licenses are tenant-specific and will need to be reassigned in the target tenant post-migration." ` -Recommendation "Confirm Copilot license availability in the target tenant and plan reassignment as part of migration." } if ( $studioCount -gt 0 ) { $Assessment.Findings += New-Finding ` -Type "CopilotStudioDetected" ` -Summary "$studioCount Copilot Studio licenses detected" ` -Category "AI" ` -Severity "Info" ` -Impact "Copilot Studio agents and configurations are tenant-specific and will need to be recreated in the target tenant." ` -Recommendation "Inventory Copilot Studio agents and plan recreation in the target tenant." } } catch { Write-Log "Copilot data collection failed: $( $_.Exception.Message )" "ERROR" $Assessment.AI.HasAILicenses = $null $Assessment.AI.AILicenseCount = $null $Assessment.AI.HasCopilot = $null $Assessment.AI.HasAIAgents = $null $Assessment.AI.AIAgentCount = $null $Assessment.AI.IsAIDataReady = $null $Assessment.AI.HasAIGovernance = $null } } |