Created
November 5, 2019 12:25
-
-
Save sajeetharan/4df899ba15a206fcb199d0e58eca8a2c to your computer and use it in GitHub Desktop.
Add-UserEntitlement.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Short description | |
.DESCRIPTION | |
Long description | |
.EXAMPLE | |
Example of how to use this cmdlet | |
.EXAMPLE | |
Another example of how to use this cmdlet | |
#> | |
function Add-UserEntitlement { | |
[OutputType([int])] | |
Param | |
( | |
[String]$userEmail, | |
[String]$projAccessLevel, | |
[String]$projId | |
) | |
Begin { | |
$creds = Import-Clixml -Path creds.xml | |
[string]$AccName = $creds.AccountName | |
[string]$userName = $creds.UserName | |
[string]$vstsToken = $creds.Token | |
$VstsAuth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $userName, $vstsToken))) | |
} | |
Process { | |
$vstsUri = "https://$AccName.vsaex.visualstudio.com/_apis/userentitlements?api-version=4.1-preview" | |
$vstsUEBody = @{ | |
accessLevel = @{ accountLicenseType = "express" } | |
user = @{ principalName = $userEmail; subjectKind = "user" } | |
projectEntitlements = @{ | |
group = @{ groupType = $projAccessLevel } | |
projectRef = @{ id = $projId } | |
} | |
} | |
$RestParams = @{ | |
ContentType = "application/json" | |
Method = 'Post' | |
URI = $vstsUserUri | |
Body = $vstsUEBody | ConvertTo-Json | |
Headers = @{Authorization=("Basic {0}" -f $VstsAuth)} | |
} | |
$vstsUpdateResult = Invoke-RestMethod @RestParams | |
} | |
End { | |
} | |
} | |
# Export-ModuleMember -Function Add-UserEntitlement | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment