Last active
November 10, 2021 16:29
-
-
Save jamesbroome/c84b599e42f37cf53b02105af21981b1 to your computer and use it in GitHub Desktop.
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
# Set local variables from ADO Release environment variables | |
$DeploymentPrincipalAppId = "$(DeploymentPrincipalAppId)" | |
$DeploymentPrincipalAppSecret = "$(DeploymentPrincipalAppSecret)" | |
$TenantId = "$(TenantId)" | |
$WorkspaceName = "$(WorkspaceName)" | |
$ObjectId = "$(ObjectId)" | |
$AccessRights = "$(AccessRights)" | |
$PrincipalType = "$(PrincipalType)" | |
$moduleName = "MicrosoftPowerBIMgmt.Profile" | |
$module = Get-Module $moduleName -ListAvailable -ErrorAction SilentlyContinue | |
if (!$module) | |
{ | |
Install-Module -Name $moduleName -Force -Scope CurrentUser -SkipPublisherCheck | |
} | |
$credentials = New-Object System.Management.Automation.PSCredential ($DeploymentPrincipalAppId, (convertto-securestring $DeploymentPrincipalAppSecret -asplaintext -force)) | |
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credentials -Tenant $TenantId | |
$results = Invoke-PowerBIRestMethod -Url ('groups?$filter=name eq ''' + $WorkspaceName + '''') -Method GET | ConvertFrom-Json | |
if ($results.value) | |
{ | |
Write-Host "Power BI App Workspace $WorkspaceName already exists..." | |
} | |
else | |
{ | |
$body = '{"name": "' + $WorkspaceName + '"}' | |
$workspace = Invoke-PowerBIRestMethod -Url 'groups' -Method POST -Body $body | ConvertFrom-Json | |
Write-Host "Created Power BI App Workspace..." | |
$body = '{"identifier": "' + $ObjectId + '","groupUserAccessRight": "' + $AccessRights + '","principalType": "' + $PrincipalType + '"}' | |
Invoke-PowerBIRestMethod -Url ('groups/' + $workspace.Id + ' /users') -Method POST -Body $body | |
Write-Host "Added $AccessRights permission to $PrincipalType $ObjectId..." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment