Entra / Microsoft 365 · Licensing
Disable Copilot Studio
Disables Copilot Studio by removing the Copilot Studio service plan from users licensed for Microsoft 365 Copilot.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
Connect-MgGraph -Scopes "User.ReadWrite.All" -ErrorAction Stop
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
Connect-MgGraph -Scopes "User.ReadWrite.All" -ErrorAction Stop[guid]$CopilotSKUId = "639dec6b-bb19-468b-871c-c5c441c4b0cb"[guid]$CopilotStudioPlanId = "fe6c28b3-d468-44ea-bbd0-a10a5167435c"[array]$ExcludedUsers = "eff4cd58-1bb8-4899-94de-795f656b4a18"# Find if any groups assign Copilot licenses and extract the identifiers for their members[array]$Groups = Get-MgGroup -Filter "assignedLicenses/any(s:s/skuId eq $CopilotSkuId)" -All -Property Id, DisplayName, AssignedLicensesForEach ($Group in $Groups) {Write-Host "Copilot license found in group" $Group.DisplayName[array]$Members = Get-MgGroupMember -GroupId $Group.Id -All -PageSize 500 | Select-Object -ExpandProperty Id$ExcludedUsers += $Members}# Remove any duplicates$ExcludedUsers = $ExcludedUsers | Sort-Object -UniqueWrite-Host "Scanning for user accounts with Microsoft 365 Copilot licenses..."[array]$Users = Get-MgUser -Filter "assignedLicenses/any(s:s/skuId eq $CopilotSkuId)" -All -Sort 'displayName' -Property Id, displayName, signInActivity, userPrincipalName -PageSize 500If ($Users) {Write-Host "Processing user accounts to remove access to Copilot Studio..."ForEach ($User in $Users) {If ($User.Id -notin $ExcludedUsers) {Write-Host "Checking Copilot Studio license status for" $User.DisplayName[array]$UserPlans = Get-MgUserLicenseDetail -UserId $User.Id | Select-Object -ExpandProperty ServicePlans$Status = ($UserPlans | Where-Object {$_.ServicePlanId -eq $CopilotStudioPlanId} | Select-Object -ExpandProperty ProvisioningStatus )If ($Status -eq "Success") {Try {Write-Host "Removing Copilot Studio from" $User.DisplayName -ForegroundColor GreenSet-MgUserLicense -UserId $User.Id -AddLicenses @{SkuId = $CopilotSkuID; DisabledPlans = $CopilotStudioPlanId } `-RemoveLicenses @() -ErrorAction Stop | Out-Null} Catch {Write-Host "Couldn't remove Copilot Studio from" $User.DisplayName -ForegroundColor Red}}} Else {Write-Host "Skipping excluded user" $User.DisplayName -ForegroundColor Yellow}}}
Attribution
Author
Office365itpros