I created an agent in Copilot Studio named AgentX. I shared agentX to "userA@ptXYZ.com", "userB_ptABC.com#EXT#@ptXYZ.com", "userC_ptDEF.onmicrosoft.com#EXT#@ptXYZ.com". I published agentX to Teams Channel. User A B C was able to find Agent X from Teams from Apps -> Categories -> Built with Power Platform. User C successfully accessed agentX. Then I did not want user C to access agentX, so I removed user C permission from copilot studio and I also uninstalled AgentX from user C using this code
$users = @(
"userA@ptXYZ.com",
"userB_ptABC.com#EXT#@ptXYZ.com",
"userC_ptDEF.onmicrosoft.com#EXT#@ptXYZ.com"
)
$ApplicationClientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$ApplicationClientSecret = "<Application_Client_Secret>"
$TenantId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$SecureClientSecret = ConvertTo-SecureString -String $ApplicationClientSecret -AsPlainText -Force
$ClientSecretCredential = New-Object System.Management.Automation.PSCredential(
$ApplicationClientId,
$SecureClientSecret
)
Install-Module Microsoft.Graph.Teams -Scope CurrentUser
Import-Module Microsoft.Graph.Teams
Connect-MgGraph -TenantId $TenantId -ClientSecretCredential $ClientSecretCredential
$result = foreach ($user in $users) {
$apps = Get-MgUserTeamworkInstalledApp `
-UserId $user `
-ExpandProperty "teamsApp,teamsAppDefinition"
$targetApps = $apps | Where-Object {
$_.TeamsAppDefinition.DisplayName -eq "Copilot Studio Agent Name"
}
if ($targetApps) {
foreach ($app in $targetApps) {
[PSCustomObject]@{
User = $user
AppName = $app.TeamsAppDefinition.DisplayName
InstallationId = $app.Id
ExternalId = $app.TeamsApp.ExternalId
}
}
}
else {
[PSCustomObject]@{
User = $user
AppName = "NOT FOUND"
InstallationId = "-"
ExternalId = "-"
}
}
}
$result | Format-Table -AutoSize
Remove-MgUserTeamworkInstalledApp `
-UserId "userC_ptDEF.onmicrosoft.com#EXT#@ptXYZ.com" `
-UserScopeTeamsAppInstallationId "<installation-id>"
Then, I wanted user C to be able to access agentX again, so I gave user C permission again and republish AgentX in Teams Channel. User C could find AgentX from Teams from Apps -> Categories -> Built with Power Platform, but when user C wanted to ADD agentX, there was an error as seen in picture 1. This is not about license that user C has because previously user C was able to access agentX (agentX was able to return good response). How to resolve this issue?