smsagent.blog
  • docs.smsagent.blog
  • Custom Reporting in Microsoft Intune
    • Delivery Optimization Report
    • Windows Update for Business Custom Reporting
      • Power BI Report Walkthrough
      • Known issues / limitations
      • Change log
      • Deploy the solution
        • Create Azure Resources
        • Configure Azure Resources
        • Deploy the client-side script
        • Deploy the Azure automation runbooks
        • Configure the Power BI report
      • Adding additional language support
      • Table schema reference
    • Automating Data Exports from Microsoft Graph
      • Azure Automation account
        • Create / configure an Azure automation account
        • Grant API permissions
        • Create an Azure automation runbook
      • Azure Storage account
      • Automate Data Export to Azure Storage Account
      • Automate Data Export to Azure Monitor Logs
      • Creating / Troubleshooting Runbooks
      • Power BI
        • Connect Power BI to an Azure storage account data source
        • Connect Power BI to an Azure log analytics workspace as a data source
    • Managed Devices Report
      • Create / configure an Azure automation account
      • Grant API permissions
      • Create / configure an Azure storage account
      • Create an Azure automation runbook
      • Create a PowerBI report
      • MEM Managed Device Report template
      • Bonus! Unhealthy MEMCM Clients email report
    • Intune Assignments Report
      • Create / configure an Azure automation account
      • Grant API permissions
      • Create / configure an Azure storage account
      • Create an Azure automation runbook
      • Create a Power BI report
      • Change log
    • Patch My PC Report
      • A look at the Power BI reports
      • Change log
      • Video guides
      • Things to know
      • Create / configure an Azure automation account
      • Grant API permissions
      • Create / configure an Azure storage account
      • Create an Azure automation runbook
      • Create the Power BI report
      • Feedback
    • Windows 11 Hardware Readiness Report
    • Gathering Custom Inventory with Intune
      • Set up the Azure Resources
      • Create a Proactive remediations script package
      • Create a runbook
  • PowerShell Scripts Online Help
    • Get-AzSubscriptionActivityLog
  • Azure Solutions
    • Automated Azure Table Storage Backups
      • Change log
      • Deploy the solution
        • Create the Azure resources
        • Set the backup schedule
        • Add storage tables to the backup
        • Add role assignments to the storage account/s
        • Create a lifecycle management rule
      • Run a manual backup
      • Restore a backup
Powered by GitBook
On this page

Was this helpful?

  1. Azure Solutions
  2. Automated Azure Table Storage Backups
  3. Deploy the solution

Add role assignments to the storage account/s

PreviousAdd storage tables to the backupNextCreate a lifecycle management rule

Last updated 1 year ago

Was this helpful?

Before the solution can backup your storage tables, it needs to be granted access to the storage account containing the Azure tables that you want to backup. Specifically, the system managed identity of the function app needs to be granted the Storage Table Data Reader and Storage Blob Data Contributor roles to the storage account.

The script below can do this for you. You'll need to run this against every storage account where you are backing up tables.

Download the script and set the parameters at the top of the script:

  • Tenant (tenant Id)

  • Subscription (subscription name)

  • StorageAccountName (the name of the storage account containing the tables you want to backup)

Execute the script, and upon successful execution the new role assigments will be reported:

In the storage account in the Azure portal, in the Access Control (IAM) blade, in the Role assignments tab, you will see the new role assignments added.

https://github.com/SMSAgentSoftware/AzureTableBackup/blob/main/Add-AzStorageAccountRoleAssigments.ps1
##################################################################################

## Grants the Function app identity the role assignments on the storage account ##

## required by the Azure Table Backup solution                                  ##

##################################################################################



## Check required modules

#Requires -Modules Az.Accounts,Az.Resources



$Tenant = "<tenant Id>"# The ID of the tenant containing your Azure subscription

$Subscription = "<subscription name>" # The name of the Azure subscription which hosts your resources

$StorageAccountName = "<storage account name>" # The name of the storage account containing the tables you want to backup



# Connect to Azure AD

try 

{

    $Connection = Connect-AzAccount -Subscription $Subscription -Tenant $Tenant -ErrorAction Stop

}

catch 

{

    throw $_.Exception.Message

}



# Locate the storage account resource

try 

{

    $StorageAccount = Get-AzResource `

        -Name "$StorageAccountName" `

        -ResourceType "Microsoft.Storage/storageAccounts" `

        -ErrorAction Stop

}

catch 

{

    throw $_.Exception.Message.Split([Environment]::NewLine)[0]

}

If ($null -eq $StorageAccount)

{

    throw "Storage account not found! Check the name."

}



# Locate the function app resource

try 

{

    $FunctionApp = Get-AzResource `

        -Name "func-azTableBackup*" `

        -ResourceType "Microsoft.Web/sites" `

        -ResourceGroupName "rg-azTableBackup*" `

        -ErrorAction Stop

}

catch 

{

    throw $_.Exception.Message.Split([Environment]::NewLine)[0]

}

If ($null -eq $FunctionApp)

{

    throw "Function app not found!"

}



# Add the role assignments

Write-Host "Adding role assignments for function app system identity to storage account..."

"Storage Table Data Reader","Storage Blob Data Contributor" | foreach {

    Write-Host "  $_..." -NoNewline

    try 

    {

        $RoleAssignment = New-AzRoleAssignment `

        -ObjectId $FunctionApp.Identity.PrincipalId `

        -RoleDefinitionName "$_" `

        -Scope $StorageAccount.Id `

        -WarningAction SilentlyContinue `

        -ErrorAction Stop

        Write-Host "Success!" -ForegroundColor Green

    }

    catch 

    {

        Write-Host "Failed!" -ForegroundColor Red

        Write-Warning -Message $_.Exception.Message.Split([Environment]::NewLine)[0]

    }

}