I'm using powershell to (mass) delete and create roles in SSAS. Deleting is done like this :

$rolecount = $db.Roles.count
    for ($i = 0; $i -lt $rolecount; $i++) {
        Write-host ($db.Roles.item(0).name) 

and adding like this :

        if (!$db.Roles.Contains($sRole))
                $db.roles.add($sRole) > $null
                $role = $db.Roles.GetByName($sRole)
            Write-host "[$((get-date).ToString('HH:mm:ss'))] -> Role '$sRole' already exists !"

with $db being an instance of the "Microsoft.AnalysisServices.Database" class. When the role is added permissions etc. are added too in a similiar fashion. 98% of the time that works fine, but ever so often i get the following error message back from SSAS : the object (database role) with the name [insert role name here, its always a different one] already exists in [insert database name here] (i translated the error message, actual wording in english could be different). The script output shows that the same role has been deleted moments ago with no errors. I even put a debug output into the script that counted the number of roles after deletion, it was 0. Has anyone experienced this behavior before ? i've tried for ages to find a way to reliably reproduce the error in order to fix it.

  • can you post the exact script? In your delete script for example you iterate i=0, i<rolecount but you keep deleting item(0) instead of item(i) – Tom V - try topanswers.xyz Aug 25 '17 at 11:58
  • yes, it always deletes the first item, the second then becomes the first, repeat – MSBerlin Aug 25 '17 at 12:05
  • I see makes sense – Tom V - try topanswers.xyz Aug 25 '17 at 13:36
  • If you trap this error in a try/catch block and retry the add operation do you get the same error again or does it clear on the retry? – John Eisbrener Aug 25 '17 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.