microsoftgraph / msgraph-sdk-powershell

Powershell SDK for Microsoft Graph
https://www.powershellgallery.com/packages/Microsoft.Graph
Other
678 stars 161 forks source link

Remove-MgTeam: Method Not Allowed and incorrect example #2841

Open Lyx09 opened 2 weeks ago

Lyx09 commented 2 weeks ago

Describe the bug

I'm working on a project where I need to delete unused Teams. I'm trying to use the "Remove-MgTeam" command with the "-TeamId" parameter, but I get the following error: 1

The team exists, and I have do have permissions to delete the Team: 6

Trying to reach the endpoint directly, using Invoke-MgGraphRequest instead gives the same result (as expected): 2

The enpoint is defined when using "Find-MgGraphCommand": 7

The endpoint does not seem to allow the "DELETE" method, but the "GET" method works: 3

Moreover, the documentation and Get-Help shows incorrect examples: 4

image

Expected behavior

The team should be deleted, no errors should be thrown. Documentation should include example of Remove-MgTeam instead of Update-MgTeam

How to reproduce

  1. Connect to MgGraph Connect-MgGraph
  2. Execute Remove-MgTeam with the "-TeamId" parameter: Remove-MgTeam -TeamId "{teamid}"

SDK Version

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.19.0                Microsoft.Graph.Authentication      {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, Get-MgContext…}
Script     2.19.0                Microsoft.Graph.Teams               {Add-MgChatMember, Add-MgTeamChannelMember, Add-MgTeamMember, Add-MgTeamPrimaryChannelMember…}

Latest version known to work for scenario above?

No response

Known Workarounds

Use MicrosoftTeams module instead with the "Remove-Team" and "-GroupId" parameter 5

Debug output

Click to expand log Note: identifying information has been removed ``` DEBUG: [CmdletBeginProcessing]: - Remove-MgTeam begin processing with parameterSet 'Delete'. DEBUG: [Authentication]: - AuthType: 'Delegated', TokenCredentialType: 'InteractiveBrowser', ContextScope: 'CurrentUser', AppName: 'Microsoft Graph Command Line Tools'. DEBUG: [Authentication]: - Scopes: [DeviceManagementApps.ReadWrite.All, DeviceManagementConfiguration.ReadWrite.All, DeviceManagementManagedDevices.PrivilegedOperations.All, DeviceManagementManagedDevices.ReadWrite.All, Directory.AccessAsUser.All, Group.ReadWrite.All, openid, Organization.Read.All, profile, User.Read, User.Read.All, User.ReadWrite.All, email]. Confirm Are you sure you want to perform this action? Performing the operation "Remove-MgTeam_Delete" on target "Call remote 'DELETE /teams/{team-id}' operation". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A DEBUG: ============================ HTTP REQUEST ============================ HTTP Method: DELETE Absolute Uri: https://graph.microsoft.com/v1.0/teams/{teamid} Headers: FeatureFlag : 00000043 Cache-Control : no-store, no-cache User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.22631; fr-FR),PowerShell/2024.2.2 Accept-Encoding : gzip SdkVersion : graph-powershell/2.19.0 client-request-id : {client-request-id} Body: DEBUG: ============================ HTTP RESPONSE ============================ Status Code: MethodNotAllowed Headers: Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : {request-id} client-request-id : {client-request-id} x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"{DataCenter}","Slice":"E","Ring":"5","ScaleUnit":"003","RoleInstance":"{RoleInstance}"}} Date : Tue, 09 Jul 2024 14:00:19 GMT Body: { "error": { "code": "UnknownError", "message": "", "innerError": { "date": "2024-07-09T14:00:19", "request-id": "{request-id}", "client-request-id": "{client-request-id}" } } } Remove-MgTeam_Delete: Status: 405 (MethodNotAllowed) ErrorCode: UnknownError Date: 2024-07-09T14:00:19 Headers: Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : {request-id} client-request-id : {client-request-id} x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"{DataCenter}","Slice":"E","Ring":"5","ScaleUnit":"003","RoleInstance":"{RoleInstance}"}} Date : Tue, 09 Jul 2024 14:00:19 GMT DEBUG: [CmdletEndProcessing]: - Remove-MgTeam end processing. ```

Configuration

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Other information

No response

Eavzz commented 2 weeks ago

Yes, I stumbled upon the same problem, it really bothers me as well... @Lyx09 If you find a solution please contact me. I will use the workaround for now, however that means I need to import 2 modules instead of 1

timayabi2020 commented 2 weeks ago

@Lyx09 thank you for logging this issue and apologies for the experience you are having with that cmdlet. Having used both Remove-MgTeam and Invoke-MgGraphCommand cmdlet, clearly points to an API issue where DELETE operation is not supported. I've also tried the request on graph explorer and got the same result.

image

Further investigations also revealed that the documentation for that particular API is not available here https://learn.microsoft.com/en-us/graph/api/resources/team?view=graph-rest-1.0.

Unfortunately, for API related issues/questions we are not best placed to give an answer. Kindly raise an issue here https://developer.microsoft.com/en-us/graph/support so that the API owner can respond to it.

You can also consider archiving the team as described here

Lyx09 commented 1 week ago

Thank you for your reply. I'll do as you said. However, even though the endpoint is broken, the examples are still incorrect (Get-Help).

Lyx09 commented 1 week ago

I contacted the Microsoft support, and they suggested I use an alternative endpoint to delete a team, which I did not think about: Remove-MgGroup -GroupId $groupId It works in a similar way as Remove-MgTeam.