Get-xAzDoProjectPermissionList.ps1
<#PSScriptInfo .VERSION 1.1 .GUID 894d99d5-ef22-4ad3-b21d-b4af5b267fe9 .AUTHOR Chendrayan Venkatesan .COMPANYNAME Free Lancer .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES .PRIVATEDATA #> <# .DESCRIPTION A PowerShell script to retrieve Azure DevOps Project Permissions #> param ( $PAT, $Organization ) $IdentityCollection = @() $DescriptorCollection = @() $ResultCollection = @() $PATGetBytes = [System.Text.Encoding]::ASCII.GetBytes(":$PAT") $Authentication = [System.Convert]::ToBase64String($PATGetBytes) $Headers = @{Authorization = ("Basic {0}" -f $Authentication) } $UserCollection = @() do { $Uri = "https://$($Organization).vsaex.visualstudio.com/_apis/UserEntitlements?continuationToken=$ContinuationToken" $UserCollection += (Invoke-RestMethod -Uri $Uri -Headers $Headers).members $ContinuationToken = $UserCollection.continuationToken } while ($null -eq $ContinuationToken) foreach ($User in $UserCollection) { $IdentityCollection += (Invoke-RestMethod -Uri "https://$($Organization).vssps.visualstudio.com/_apis/Identities?api-version=6.0&searchFilter=General&filterValue=$($User.user.mailAddress)" -Headers $Headers -ContentType 'application/json').value } foreach ($Descriptors in $IdentityCollection) { $DescriptorCollection += (Invoke-RestMethod -Uri "https://$($Organization).vssps.visualstudio.com/_apis/Graph/Descriptors/$($Descriptors.id)" -Headers $Headers).value } foreach ($Identity in $UserCollection.user) { $MemberDescriptor = (Invoke-RestMethod -Uri "https://$($Organization).vssps.visualstudio.com/_apis/Graph/Memberships/$($Identity.descriptor)" -Headers $Headers).value foreach ($Member in $MemberDescriptor) { $Body = [pscustomobject]@{ lookupkeys = @([pscustomobject]@{ descriptor = $Member.containerDescriptor }) } | ConvertTo-Json $Subjectlookup = (Invoke-RestMethod -Uri "https://vssps.dev.azure.com/$($Organization)/_apis/graph/subjectlookup?api-version=6.0-preview.1" -Method Post -Body $($Body) -Headers $Headers -ContentType 'application/json') $Groups = (($subjectlookup.value | Get-Member -MemberType NoteProperty).Name) foreach ($Group in $Groups) { $ResultCollection += [PSCustomObject]@{ PrincipalName = $Identity.principalName DisplayName = $Identity.displayName ProjectName = $($Subjectlookup.value.$($Group).principalName -split '\\')[0] -replace '\[' , '' -replace '\]' , '' GroupName = $($Subjectlookup.value.$($Group).principalName -split '\\')[1] } } } } $ResultCollection |