{"id":1048,"date":"2021-09-05T15:33:33","date_gmt":"2021-09-05T13:33:33","guid":{"rendered":"https:\/\/www.flip-design.de\/?p=1048"},"modified":"2021-09-05T15:36:07","modified_gmt":"2021-09-05T13:36:07","slug":"how-to-add-users-into-roles-with-azure-devops-by-using-powershell-to-a-analysis-service-cube","status":"publish","type":"post","link":"https:\/\/www.flip-design.de\/?p=1048","title":{"rendered":"How to add users into roles with Azure DevOps by using PowerShell to a Analysis Service Cube"},"content":{"rendered":"\n<p>To add users users after a deployment to a Azure Analysis Services cube you can do this manually with the Management tools or with the Visual Studio. But with a Continiuos Deployment (CI\/CD) and different stages, you need mostly add different users\/groups to add to the roles. So, you need todo this dynamiccaly with some scipts. I found in the marketplace a addin to do this with DevOps by using a pipline. But, unfornatially this adding does not work and you can only onee user\/group by using one step. So, I decided to do this with PowerShell to add more than one user in one step.<br>I added my deployment user as a SSAS admin with the portal (you can also do this with the Management Studio)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image.png\"><img decoding=\"async\" loading=\"lazy\" width=\"605\" height=\"330\" src=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image.png\" alt=\"\" class=\"wp-image-1049\" srcset=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image.png 605w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-300x164.png 300w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-500x273.png 500w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/a><\/figure>\n\n\n\n<p>After that, I created this PowerShell script and added this to my Repo and published it to DevOps to use it inside a Pipeline: This script connects to my Analysis Service and adds a user to a role. use it inside a Pipeline: This script connects to my Analysis Service and adds a user to a role.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n&#91;CmdletBinding()]\nparam (\n    $ParamUser,\n    $ParamPassword\n)\n\n$myPassword = $ParamPassword\n$myUsername = $ParamUser\n\n$password = ConvertTo-SecureString $myPassword -AsPlainText -Force\n$credential = New-Object System.Management.Automation.PSCredential ($myUsername, $password)\nLogin-AzAccount -Credential $credential\nImport-Module SqlServer -DisableNameChecking\n\nAdd-RoleMember `\n    -Server asazure:\/\/westus.asazure.windows.net\/ssas001 `\n    -membername \"asadmin@plenz.onmicrosoft.com\" `\n    -database \"adventureworks\" `\n    -rolename \"Internet Sales Manager\" `\n    -Credential $credential\n<\/code><\/pre>\n\n\n\n<p>Here you see the script inside my Repo at DevOps<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-1.png\"><img decoding=\"async\" loading=\"lazy\" width=\"605\" height=\"330\" src=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-1.png\" alt=\"\" class=\"wp-image-1050\" srcset=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-1.png 605w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-1-300x164.png 300w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-1-500x273.png 500w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/a><\/figure>\n\n\n\n<p>Next, I created a pipeline, and I added the needed credentials to connect to the SSAS server as variables.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-2.png\"><img decoding=\"async\" loading=\"lazy\" width=\"605\" height=\"330\" src=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-2.png\" alt=\"\" class=\"wp-image-1051\" srcset=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-2.png 605w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-2-300x164.png 300w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-2-500x273.png 500w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/a><\/figure>\n\n\n\n<p>After doing this, I created an Azure PowerShell task inside my pipeline this one uses the PowerShell script from the repo and pushes the variables as parameters to the script.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-3.png\"><img decoding=\"async\" loading=\"lazy\" width=\"605\" height=\"330\" src=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-3.png\" alt=\"\" class=\"wp-image-1052\" srcset=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-3.png 605w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-3-300x164.png 300w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-3-500x273.png 500w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/a><\/figure>\n\n\n\n<p>After tunning the pipeline, the user from the script is added to the role.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-4.png\"><img decoding=\"async\" loading=\"lazy\" width=\"605\" height=\"585\" src=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-4.png\" alt=\"\" class=\"wp-image-1053\" srcset=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-4.png 605w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-4-300x290.png 300w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2021\/09\/image-4-310x300.png 310w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>To add users users after a deployment to a Azure Analysis Services cube you can do this manually with the Management tools or with the Visual Studio. But with a Continiuos Deployment (CI\/CD) and different stages, you need mostly add &hellip; <a href=\"https:\/\/www.flip-design.de\/?p=1048\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.flip-design.de\/index.php?rest_route=\/wp\/v2\/posts\/1048"}],"collection":[{"href":"https:\/\/www.flip-design.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.flip-design.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.flip-design.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.flip-design.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1048"}],"version-history":[{"count":2,"href":"https:\/\/www.flip-design.de\/index.php?rest_route=\/wp\/v2\/posts\/1048\/revisions"}],"predecessor-version":[{"id":1055,"href":"https:\/\/www.flip-design.de\/index.php?rest_route=\/wp\/v2\/posts\/1048\/revisions\/1055"}],"wp:attachment":[{"href":"https:\/\/www.flip-design.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flip-design.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flip-design.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}