You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Get-VSTeamUserEntitlement only returns 96 results #388
As side note: calling from Postman directly also returns the same 77 objects https://vsaex.dev.azure.com/organization/_apis/userentitlements?api-version=6.0
In 6.0 and later, it changed to Search User Entitlements and returns a continuationToken property that it's neccesary to provide in the next call as query parameter
When VSTeam module is installed, is pointing to the last MemberEntitlementManagement service version. So, it would be nice if Get-VSTeamUserEntitlement is changed to the last version behavior or preset the MemberEntitlementManagement service to the 5.1 version
I think it's complicated to change the internal implementation keeping the current parameters
For the -top parameter: Use the continuation token to call the API up to get the -top n rows, return that n rows and keep the excding rows foreseing a next call
For the -skip parameter, Keep the status (the continuation token) between calls
I can't figure any update without saving some internal status between calls. And that seems me an awfull solution.
Other option
Use different parameter set to separate both versions:
and warn some how in the documentation that to use the top & skip version it's needed to keep the MemberEntitlementManagement service lower or equal to 5.1 version calling to Set-VSTeamAPIVersion -Service MemberEntitlementManagement -Version 5.1-preview.2
The -id version Parameterset("ByID") is supported by the 6.0 API
Regarding to the -top -skip version Parameterset("List") is not supported in the last API version, so my proposal is to play with the _supportsMemberEntitlementManagement function checking the current api version: if is set up to 5.1, ok. If it is 6.0 or upper, throw an exception explaining how to change to a lower version using Set-VSTeamAPIVersion -Service MemberEntitlementManagement -Version 5.1-preview.2
Now, the new parameter sets:
The -Filter version is a free form so the user can setup complex queries like licenseId eq 'Account-Stakeholder' or (licenseId eq 'Account-Express' and licenseStatus eq 'Disabled')
The 4th version is a helper to build internally the filter using the eq operator
@mnieto sorry for the silence. You can go with it and even change the parameters of the cmdlet if necessary. We will drop support of older on-premise versions anyways with version 8.0.
Ant regards to the change of the parameters. I would suggest that you make an extended explanation for the breaking change in the changelog.
As you suggested please check for the cmdlet itself what version we use. And throw an exception to change the API. Good point!
Btw. regarding the continuation token. There will be multiple API calls, where there are continuation tokens. If you see you can create an internal function that can be reused regarding those tokens then I would appreciate it.
@SebastianSchuetze , working on it.
I have some doubts:
How do you think is the best way to return the ContinuationToken?
I'm thinking to set a global variable (i..e $VSTeamContinuationToken) with the value returned by the API.
Other way could be: Expose a new function i.e. Get-VSTeamContinuationToken -Token UserEntlitement, where the posible values for the Token parameter is a set of function names that manage continuation tokens
3rd option: manage internaly the continuationToken, paging inside the Get-VSTeamUserEntitlement function, and return the complete list
Hi @mnieto I would go for the third option for now. I think the continuation token complexity should be hidden as much as possible. We can expose this function later if really needed. However, I would suggest an optional parameter with something like "-MaxPages" (int) or similar which limits how much requests we do. So the user can decide if they want only 5 pages or all.
Default should be a setting that returns all pages. Maybe 0 could mean "all" and is the default.
I created tests and documentation. Now trying how to figure out a generic method to manage the continuationToken.
Still working most of the changes on my local fork, not PR created yet. I can create it, so you can review it, but it's a work in progress. Not sure how to proceed (I think it is my first PR):
Create a draft PR with the first changes and continue for completion
Work in private and create the PR when finished, just to review
You can already make a draft PR. Then you can see already if the build is accepted. I have also open PRs already. And I could help with tips or even commit to the PR branch if needed.
API endpoints that use the continuationToken do that as part of the response json in a property. But other endpoints are using a X-MS-ContinuationToken header.
Ok, this can be solved with a switch parameter.
Also add a parameter with the property name, or header name, that will contain the token. With a default value.
Add another parameter for the property that we need to iterate. In this case "members"
I will have a look as soon as I have some time. Hope it takes not too long. Could you add comments to code lines where somebody might not expect what is happening with the code?
If you think it is obvious then just wait for my questions. 😉
RuntimeException: EntitlementManagemen version must be equal or lower than 5.1 for this call, current value 6.0-preview
by calling the following function
Get-VSTeamUserEntitlement -Id $id
This means that your cmdlet changes actually change the required parameters for existing scripts. Either I didn't get it and the parameter set 'ByID' must also be allowed for apiVersion 5.1 and above or I have to change the mayor version. I would rather have the first. I am researching currently. But maybe you can help me explaining how to solve it.
@SebastianSchuetze, Understood. The main problem is that the new API in v6.0 doesn't support filtering by ID.
See $filter parameter.
The workaround I see is: check if ParameterSetName -eq 'ById' set internally $apiVersion to 5.1 independently of the version configured in the Set-VSTeamAPIVersion
Let me try along this week
Activity
mnieto commentedon Dec 7, 2021
I my case, it returns always the same first 77 users.
PS> (Get-VSTeamUserEntitlement).Count
77
PS> (Get-VSTeamUserEntitlement -Top 1).Count
77
PS> (Get-VSTeamUserEntitlement -Top 1000).Count
77
I have 1539 users
VSTeam version 7.4.0
Checked in both Desktop and Core powershell versions
As side note: calling from Postman directly also returns the same 77 objects
https://vsaex.dev.azure.com/organization/_apis/userentitlements?api-version=6.0SebastianSchuetze commentedon Dec 7, 2021
I think the wrong API version being used is the problem. Either the documentation or the API is wrong.
mnieto commentedon Dec 9, 2021
Thanks, changing
Set-VSTeamAPIVersion -Service MemberEntitlementManagement -Version 5.1-preview.2it did the work
I think this is because the REST API changed some time from v5.1 to v6.0
When VSTeam module is installed, is pointing to the last MemberEntitlementManagement service version. So, it would be nice if Get-VSTeamUserEntitlement is changed to the last version behavior or preset the MemberEntitlementManagement service to the 5.1 version
SebastianSchuetze commentedon Dec 9, 2021
Thanks for verification. How would you suggest to update it without breaking earlier scripts? Any idea?
mnieto commentedon Dec 9, 2021
I think it's complicated to change the internal implementation keeping the current parameters
For the -top parameter: Use the continuation token to call the API up to get the -top n rows, return that n rows and keep the excding rows foreseing a next call
For the -skip parameter, Keep the status (the continuation token) between calls
I can't figure any update without saving some internal status between calls. And that seems me an awfull solution.
Other option
Use different parameter set to separate both versions:
and warn some how in the documentation that to use the top & skip version it's needed to keep the MemberEntitlementManagement service lower or equal to 5.1 version calling to
Set-VSTeamAPIVersion -Service MemberEntitlementManagement -Version 5.1-preview.2SebastianSchuetze commentedon Dec 9, 2021
Good idea thanks!
I will think about it. Otherwise we have to up the mayor version.
mnieto commentedon Dec 22, 2021
I would like to propose this new syntax for the command. If you agree I can try to go to a PR
The first 2 entries are the current ones.
Parameterset("ByID")is supported by the 6.0 APIParameterset("List")is not supported in the last API version, so my proposal is to play with the_supportsMemberEntitlementManagementfunction checking the current api version: if is set up to 5.1, ok. If it is 6.0 or upper, throw an exception explaining how to change to a lower version usingSet-VSTeamAPIVersion -Service MemberEntitlementManagement -Version 5.1-preview.2Now, the new parameter sets:
licenseId eq 'Account-Stakeholder' or (licenseId eq 'Account-Express' and licenseStatus eq 'Disabled')eqoperatorThe param list could be somthing like this:
Official documentation for reference: https://docs.microsoft.com/en-us/rest/api/azure/devops/memberentitlementmanagement/user-entitlements/search-user-entitlements?view=azure-devops-rest-6.0
@SebastianSchuetze, what do you think?
SebastianSchuetze commentedon Jan 24, 2022
@mnieto sorry for the silence. You can go with it and even change the parameters of the cmdlet if necessary. We will drop support of older on-premise versions anyways with version 8.0.
Ant regards to the change of the parameters. I would suggest that you make an extended explanation for the breaking change in the changelog.
As you suggested please check for the cmdlet itself what version we use. And throw an exception to change the API. Good point!
Hope you are still open for a PR.
SebastianSchuetze commentedon Jan 24, 2022
Btw. regarding the continuation token. There will be multiple API calls, where there are continuation tokens. If you see you can create an internal function that can be reused regarding those tokens then I would appreciate it.
Maybe future implementations could be easier.
mnieto commentedon Jan 27, 2022
@SebastianSchuetze , working on it.
I have some doubts:
How do you think is the best way to return the ContinuationToken?
SebastianSchuetze commentedon Jan 29, 2022
Hi @mnieto I would go for the third option for now. I think the continuation token complexity should be hidden as much as possible. We can expose this function later if really needed. However, I would suggest an optional parameter with something like "-MaxPages" (int) or similar which limits how much requests we do. So the user can decide if they want only 5 pages or all.
Default should be a setting that returns all pages. Maybe
0could mean "all" and is the default.SebastianSchuetze commentedon Feb 28, 2022
@mnieto could I ask how far you have come? If not then no problem. But then I would take an approach myself. Would like to have this added soon.
mnieto commentedon Feb 28, 2022
I created tests and documentation. Now trying how to figure out a generic method to manage the continuationToken.
Still working most of the changes on my local fork, not PR created yet. I can create it, so you can review it, but it's a work in progress. Not sure how to proceed (I think it is my first PR):
Any case, I will try to advance this week
SebastianSchuetze commentedon Mar 1, 2022
You can already make a draft PR. Then you can see already if the build is accepted. I have also open PRs already. And I could help with tips or even commit to the PR branch if needed.
SebastianSchuetze commentedon Mar 7, 2022
You seem to have progress with your PR @mnieto do you need something from me to help?
mnieto commentedon Mar 9, 2022
Hi @SebastianSchuetze
I'm investigating how to extract the continuationToken management block to a generic function.
https://github.com/MethodsAndPractices/vsteam/blob/79d9801102d47e837f4992b664f52f0ba0f149a3/Source/Public/Get-VSTeamUserEntitlement.ps1#L110-129
I see some problems here:
API endpoints that use the continuationToken do that as part of the response json in a property. But other endpoints are using a X-MS-ContinuationToken header.
Add another parameter for the property that we need to iterate. In this case "members"
The main doubt for me is this block
In a generic function, how do you cast
$item, that is a PSCustomObjet, to the specific type? In c# is easy:An equivalent way is to use a scriptBlock, but the preparation to the call seems tricky. Example:
And the implementation inside _callAPIWithContinuationToken
mnieto commentedon Mar 13, 2022
Finaly I resolved as below. If it is ok for you, I'm ready to finish the PR
Method: In a future, it may be necessary add the same parameters that _callAPI currently has, but at this moment I prefer to keep it simple
Call:
SebastianSchuetze commentedon Mar 13, 2022
I will have a look as soon as I have some time. Hope it takes not too long. Could you add comments to code lines where somebody might not expect what is happening with the code?
If you think it is obvious then just wait for my questions. 😉
Thanks already for the great help!!
mnieto commentedon Sep 1, 2022
@SebastianSchuetze, any chance to review my last comments on PR #459 ?
SebastianSchuetze commentedon Sep 2, 2022
I need to find time to get I to it again regarding the one comment I made with the parameters. I try to check it this weekend.
SebastianSchuetze commentedon Sep 4, 2022
@mnieto unfortunately I discovered a problem.
The integration test have an error:
https://github.com/MethodsAndPractices/vsteam/runs/8176556019?check_suite_focus=true#step:7:121
RuntimeException: EntitlementManagemen version must be equal or lower than 5.1 for this call, current value 6.0-previewby calling the following function
Get-VSTeamUserEntitlement -Id $idThis means that your cmdlet changes actually change the required parameters for existing scripts. Either I didn't get it and the parameter set 'ByID' must also be allowed for apiVersion 5.1 and above or I have to change the mayor version. I would rather have the first. I am researching currently. But maybe you can help me explaining how to solve it.
mnieto commentedon Sep 5, 2022
@SebastianSchuetze, Understood. The main problem is that the new API in v6.0 doesn't support filtering by ID.
See $filter parameter.
The workaround I see is: check if ParameterSetName -eq 'ById' set internally $apiVersion to 5.1 independently of the version configured in the Set-VSTeamAPIVersion
Let me try along this week
mnieto commentedon Sep 7, 2022
@SebastianSchuetze
I created PR #482 to fix the back-compability issue
not sure how to update the changelog in this case
SebastianSchuetze commentedon Sep 8, 2022
I close this now since it is working again.