MethodsAndPractices / vsteam

PowerShell module for accessing Azure DevOps Services and Azure DevOps Server (formerly VSTS or TFS)
https://methodsandpractices.github.io/vsteam-docs/
MIT License
445 stars 155 forks source link

Remove-VSTeamUserEntitlement 405 - DELETE Method not allowed #329

Closed Freakling closed 4 years ago

Freakling commented 4 years ago

Steps to reproduce

[array]$activeUsers = Get-VSTeamUser | Where-Object{$_.Origin -ne 'vsts'}
[Array]$usersToRemove = $activeUsers | Where-Object{$Users -notcontains $_.PrincipalName}
$usersToRemove | Remove-VSTeamUserEntitlement

Expected behavior

User is removed

Actual behavior

WARNING: An error occurred: The remote server returned an error: (405) Method Not Allowed.
WARNING: The requested resource does not support http method 'DELETE'.
Invoke-RestMethod : {"count":1,"value":{"Message":"The requested resource does not support http method 'DELETE'."}}
At C:\Program Files\WindowsPowerShell\Modules\VSTeam\6.4.8\vsteam.functions.ps1:268 char:18
+          $resp = Invoke-RestMethod @params
+                  ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Environment data

OS

Server

> Get-VSTeamAPIVersion

Name                           Value                                                                                                                                                                                                                             
----                           -----                                                                                                                                                                                                                             
Release                        5.1-preview                                                                                                                                                                                                                       
Version                        VSTS                                                                                                                                                                                                                              
MemberEntitlementManagement    5.1-preview                                                                                                                                                                                                                       
TaskGroups                     5.1-preview.1                                                                                                                                                                                                                     
DistributedTask                5.0-preview                                                                                                                                                                                                                       
Core                           5.0                                                                                                                                                                                                                               
Packaging                      5.1-preview                                                                                                                                                                                                                       
ServiceFabricEndpoint          5.0-preview                                                                                                                                                                                                                       
VariableGroups                 5.0-preview.1                                                                                                                                                                                                                     
Build                          5.1-preview                                                                                                                                                                                                                       
Git                            5.1-preview                                                                                                                                                                                                                       
ExtensionsManagement           5.1-preview                                                                                                                                                                                                                       
Graph                          5.1-preview                                                                                                                                                                                                                       
Policy                         5.1                                                                                                                                                                                                                               
Tfvc                           5.0   
> $PSVersionTable
----                           -----                                                                                                                                                                                                                             
PSVersion                      5.1.18362.752                                                                                                                                                                                                                     
PSEdition                      Desktop                                                                                                                                                                                                                           
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                                           
BuildVersion                   10.0.18362.752                                                                                                                                                                                                                    
CLRVersion                     4.0.30319.42000                                                                                                                                                                                                                   
WSManStackVersion              3.0                                                                                                                                                                                                                               
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                                               
SerializationVersion           1.1.0.1       
Freakling commented 4 years ago

This worked

$entitlements = Get-VSTeamUserEntitlement

Remove users that are not in list

[Array]$usersToRemove = $entitlements | Where-Object{$Users -notcontains $_.email}

$usersToRemove | Remove-VSTeamUserEntitlement