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
444 stars 155 forks source link

Get-VSTeamUser return only 500 users event if there is more, Filtering by Get-VSTeamUser | ? DisplayName also not finding existing user #412

Open JanuszNowak opened 2 years ago

JanuszNowak commented 2 years ago

Steps to reproduce


$users = Get-VSTeamUser 

Expected behavior

$users = Get-VSTeamUser 
$users | Measure
2537

Actual behavior

$users = Get-VSTeamUser 
$users | Measure
500

Environment data

OS

Server

> Get-VSTeamAPIVersion
Name                           Value                                                                                                                                                  
----                           -----                                                                                                                                                  
Packaging                      6.0-preview                                                                                                                                            
Version                        VSTS                                                                                                                                                   
ServiceEndpoints               5.0-preview                                                                                                                                            
HierarchyQuery                 5.1-preview                                                                                                                                            
Graph                          6.0-preview                                                                                                                                            
Pipelines                      5.1-preview                                                                                                                                            
TaskGroups                     6.0-preview                                                                                                                                            
ExtensionsManagement           6.0-preview                                                                                                                                            
Git                            5.1                                                                                                                                                    
VariableGroups                 5.1-preview.1                                                                                                                                          
Core                           5.1                                                                                                                                                    
Release                        5.1                                                                                                                                                    
DistributedTaskReleased        5.1                                                                                                                                                    
MemberEntitlementManagement    6.0-preview                                                                                                                                            
Tfvc                           5.1                                                                                                                                                    
Processes                      6.0-preview                                                                                                                                            
Policy                         5.1                                                                                                                                                    
Build                          5.1                                                                                                                                                    
DistributedTask                6.0-preview
> $PSVersionTable
Name                           Value                                                                                                                                                  
----                           -----                                                                                                                                                  
PSVersion                      5.1.19041.1151                                                                                                                                         
PSEdition                      Desktop                                                                                                                                                
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                
BuildVersion                   10.0.19041.1151                                                                                                                                        
CLRVersion                     4.0.30319.42000                                                                                                                                        
WSManStackVersion              3.0                                                                                                                                                    
PSRemotingProtocolVersion      2.3                                                                                                                                                    
SerializationVersion           1.1.0.1 
SebastianSchuetze commented 2 years ago

@JanuszNowak hard to test for me. Any idea how I can invite more than 500 users on my own private Org to test this case?

mnieto commented 2 years ago

Please refer to https://docs.microsoft.com/en-us/rest/api/azure/devops/graph/users/list?view=azure-devops-rest-6.1 Since the list of users may be large, results are returned in pages of users. If there are more results than can be returned in a single page, the result set will contain a continuation token for retrieval of the next set of results. By default a page will contain 500 users. The API returns a X-MS-ContinuationToken header if there is more available users

As suggestion, the Get-VSTeamUser should have a -continuationToken parameter to allow sucesive calls or manage internally the continuation token and return the complete list of users

Also as additional note: the API in the v6.0 supports an aditional parameter scope that allows to filter users by project, collection... given the descriptor

mnieto commented 1 year ago

@SebastianSchuetze, @DarqueWarrior I would like to open a discussion here: There are some API endpoints that use X-MS-ContinuationToken header to control paged return This problem is also faced in #169

This is a problem because Invoke-RestMethod in powershell Desktop (5.1) does not support manage headers in the response. This support was introduced later in powershell 6.0

So, I see some options:

SebastianSchuetze commented 1 year ago

@mnieto I cannot speak for @DarqueWarrior but I have his trust. We already decided to ditch the support for all TFS versions and tend to only support Azure DevOps versions that Microsoft supports.

There is already a branch that will introduce the removal of these API endpoint (you can still control ist by enforcing it if needed). But we could introduce this also in Version 8.0.0 and also only support pwsh 6+.

People who can't use it are free to use version less than 8.0.0.

Having said that: We will not create a new _callAPI but rather change the existing. Do you want to give it a shot? Only thing is: change the minimum needed. We are very cautious in changing core code as we had problems with PRs in the past that we eventually didn't merge since too much unnecessary stuff was changed.

mnieto commented 1 year ago

Ok, I can try to work on that. which branch should I take as a starting point? feature/v8.0.0? or trunk, as usual?

My idea to implement this is just to add an optional parameter -ResponseHeadersVariable to _callAPI

To manage X-MS-ContinuationToken I wanted to integrate management of this header in the existing _callAPIContinuationToken I created previously to manage ContinuationToken when it comes as part of the response object.

SebastianSchuetze commented 1 year ago

Make a branch based on V8.0.0.

And go from there. I will update that branch with the newest changes.

The PR would also be into V8.0.0

And feel free to also integrate that into the continuation token. Could you also create an extra MD file to explain how and when to use the internal function for development?

In that way new devs and also we can use it in all cmdlets where it is needed.

JanuszNowak commented 1 year ago

@SebastianSchuetze I would probably go with rest api https://learn.microsoft.com/en-us/rest/api/azure/devops/memberentitlementmanagement/user-entitlements/add?view=azure-devops-rest-6.0&tabs=HTTP and maybe use Gmail future to add suffix after mymyemail+0001@gmail.com. Or create AAD users like described here in my post

SebastianSchuetze commented 1 year ago

You wanna give it a try @JanuszNowak ?