# Installation Instructions

{% hint style="warning" %}
Make sure you have all the [prerequisites](https://docs.bsure.io/v1/installation/prerequisites) in place before you begin.

If you encounter any problems during the installation please review the [Frequently asked questions](https://docs.bsure.io/v1/support/frequently-asked-questions).
{% endhint %}

<details>

<summary>Step 1 - Run the requirements check script</summary>

To install the Bsure Insights Data Collector you need to be a Global Administrator with the Owner RBAC role on at least 1 subscription in an Entra ID P1 enabled tenant. The script will validate that you meet those requirements.

Click the **Azure Cloud Shell** to start a PowerShell session. \
![](https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/5sSqdehNfzwSsznUwASY/image.png)\
(*If you have not used the Cloud Shell before, you will be prompted to select/create a storage account)*\
\
![](https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/PlBL1DTzuqqDIPYMdLWz/image.png)

Copy this script to your clipboard:&#x20;

```powershell
#Builds Auth Headers for Graph API
$graphAPIReqHeader = @{
    Authorization = "Bearer $($(Get-AzAccessToken -ResourceTypeName MSGraph).token | ConvertFrom-SecureString -AsPlainText)"
    Host = "graph.microsoft.com"
    ConsistencyLevel = 'eventual'
}

# Get the signed in user's ID
$userId = $(az ad signed-in-user show --query id -o tsv)

# Gets the available licenses for the tenant
$licensesUrl = "https://graph.microsoft.com/v1.0/subscribedSkus"
$licenses = Invoke-RestMethod -Uri $licensesUrl -Headers $graphAPIReqHeader

# Check if the Azure AD Premium P1 license is available
$isP1Enabled = $licenses.value.servicePlans | Where-Object {$_.servicePlanName -eq "AAD_PREMIUM"} | Select-Object -First 1

$rolesUrl = "https://graph.microsoft.com/beta/rolemanagement/directory/transitiveRoleAssignments?`$count=true&`$filter=principalId eq '$userId'"
$roles = Invoke-RestMethod -Uri $rolesUrl -Headers $graphAPIReqHeader

# Check if the user is a member of the Global Administrator role
$isGlobalAdmin = $roles.value | Where-Object {$_.roleDefinitionId -eq "62e90394-69f5-4237-9190-012177145e10"} | Select-Object -First 1

# Get the list of subscriptions
$subIds = $(az account list --query "[].id" -o tsv)

# Get the list of subscriptions where the user is a Resource Owner
$resSubCunt = $subIds | ForEach-Object{
    $(az role assignment list --assignee $userId --all --query "[?roleDefinitionName == 'Owner'].scope" --subscription "$_" -o tsv)
}

if($resSubCunt.Count -gt 1){
    $subscriptionReplacement = "subscriptions"
}else{
    $subscriptionReplacement = "subscription"
}

# Clear the screen
# Display the results
$allRequired = $isP1Enabled -and $isGlobalAdmin -and ($resSubCunt.Count -gt 0)
$allRequiredMessage = if ($allRequired) {"You have all the required permissions & licenses."} else {"You do not have all the required permissions & licenses."}
$aadP1Result = if ($isP1Enabled) {"Entra ID P1 is enabled in your tenant."} else {"Entra ID P1 is not enabled in your tenant."}
$globalAdminMessage = if ($isGlobalAdmin) {"You are a Global Administrator in your tenant."} else {"You are not a Global Administrator in your tenant."}
$ownerMessage = if ($resSubCunt.Count -gt 0) {"You have the Owner RBAC Role for $($resSubCunt.Count) $subscriptionReplacement."} else {"You are do not have the Owner RBAC Role on any subscription."}
$sb = {
Clear-Host
Write-Host "--------------------------" -ForegroundColor Yellow
Write-Host $aadP1Result -ForegroundColor $(if ($isP1Enabled) {"Green"} else {"Red"})
Write-Host $globalAdminMessage -ForegroundColor $(if ($isGlobalAdmin) {"Green"} else {"Red"})
Write-Host $ownerMessage -ForegroundColor $(if ($resSubCunt.Count -gt 0) {"Green"} else {"Red"})
Write-Host $allRequiredMessage -ForegroundColor $(if ($allRequired) {"Green"} else {"Red"})
Write-Host "--------------------------" -ForegroundColor Yellow
}
Invoke-Command -ScriptBlock $sb

# Press Enter
```

Paste the script to the PowerShell session, and hit Enter.

A failed run will contain red text on the failed checks:

<img src="https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/alIbVN2W94kUwdB4FHUY/precheckfail.png" alt="" data-size="original">

Please correct any missing requirements and rerun the requirements check.

A successful run will contain all green text:

![](https://1625452539-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8ZA9wzEc66a3iRTBh11w%2Fuploads%2F8wA96nSjS8gsaH1iZX19%2Fimage.png?alt=media\&token=14659aeb-7bb2-43ab-8851-2d880a8c34f5)

If all the checks are green it means you have the required access to proceed to Step 2:<br>

</details>

<details>

<summary>Step 2 - Start the permissions script</summary>

To collect license and user information, the Bsure Insights Data Collector application need read permissions to your Azure Active Directory.

Click the **Azure Cloud Shell** to start a PowerShell session. \
![](https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/5sSqdehNfzwSsznUwASY/image.png)\
(*If you have not used the Cloud Shell before, you will be prompted to select/create a storage account)*\
\
![](https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/PlBL1DTzuqqDIPYMdLWz/image.png)

Copy this script to your clipboard:&#x20;

```powershell
$BSureSpnName = 'Bsure-Umi-'

$BsurePermissions = @(
  "Directory.Read.All"
  "AuditLog.Read.All"
  "Domain.Read.All"
  "Reports.Read.All"
  "Policy.Read.All"
  "MailboxSettings.Read"
  "DeviceManagementManagedDevices.Read.All"
)

$RunStartTime = (Get-Date).AddMinutes(-30)
$RunAbortTime = (Get-Date).AddMinutes(30)

$GraphAppId = "00000003-0000-0000-c000-000000000000"

$msGraphSpn = Get-AzADServicePrincipal -Filter "appId eq '$GraphAppId'"

$RolesToAdd = $msGraphSpn.AppRole | Where-Object {($_.Value -in $BsurePermissions) -and ($_.AllowedMemberType -contains "Application")}

do{
    $spnBsure = (Get-AzADServicePrincipal -DisplayNameBeginsWith $BSureSpnName).Where({[datetime]($_.AdditionalProperties.createdDateTime) -ge $RunStartTime})
    Clear-Host
    Write-Host ""
    Write-Host "Waiting for the Bsure Azure Managed Application Installation..."
    Write-Host "Do not close this window"
    Write-Host ""

    Start-Sleep -Seconds 30
    if((Get-Date) -gt $RunAbortTime){
        Write-Host "Service principal not created within 30 minutes. Exiting..."
        exit
    }
}while($spnBsure.count -eq 0)

$spnBsure | ForEach-Object{

    $script:graphAPIReqHeader = @{
        Authorization = "Bearer $($(Get-AzAccessToken -ResourceTypeName MSGraph).token | ConvertFrom-SecureString -AsPlainText)"
        Host = "graph.microsoft.com"
    }

    $currentSPN = $_
    $currentSPN
    $assignedPermissionsUri = "https://graph.microsoft.com/v1.0/servicePrincipals/$($currentSPN.Id)/appRoleAssignments"

    $currentAssignments = Invoke-RestMethod -Method Get -Uri $assignedPermissionsUri -Headers $script:graphAPIReqHeader | Select-Object -ExpandProperty value
    
    $RolesToAddClean = $RolesToAdd | Where-Object {($_.id -notin $($currentAssignments.appRoleId))}
    
    foreach($AppRole in $RolesToAddClean)
    {
        $body = @{
            principalId = $currentSPN.Id
            resourceId = $msGraphSpn.id
            appRoleId = $AppRole.id
        } | ConvertTo-Json -Depth 99 -Compress -EscapeHandling EscapeNonAscii
    
        Invoke-RestMethod -Method Post -Uri $assignedPermissionsUri -Headers $script:graphAPIReqHeader -Body $body -ContentType "application/json"
    }
    
    $RolesToRemoveClean = $currentAssignments.appRoleId | Where-Object {($_ -notin $($RolesToAdd.id))}
    
    foreach($AppRole in $RolesToRemoveClean)
    {
        $toRemoveId = $currentAssignments | Where-Object -Property appRoleId -eq $AppRole | Select-Object -ExpandProperty id
        Invoke-RestMethod -Method Delete -Uri "$assignedPermissionsUri/$toRemoveId" -Headers $script:graphAPIReqHeader
    }
}

Write-Host "Done setting permissions for $($spnBsure.DisplayName) ($($spnBsure.Id))"

```

Paste the script to the PowerShell session, and hit Enter.

**The script will poll for Stage 3, do not wait for the script to complete, please start Stage 3 immediately after pasting the script and pressing enter.**

The application will get read permissions to your Azure AD, and is able to collect license and user information once Step 2 completes.

You can see the permissions granted to the Collector app if you go to Azure Active Directory, Enterprise Applications and find the Bsure-Fn-DataCollector app.\ <img src="https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/f26CqFHnQhLQQ2MCKMve/image.png" alt="" data-size="original"><br>

</details>

{% hint style="danger" %}
**IMPORTANT!** \
Make sure you have the permissions script running before you proceed to Step 3. \
The installation will **FAIL** if you skip Step 2.
{% endhint %}

<details>

<summary>Step 3 - Install Bsure Insights Data Collector</summary>

1. Login to [Azure portal](https://portal.azure.com) using your Global Administrator credentials.
2. Select **Create a resource.**

   <figure><img src="https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/EdEBTddxQVsqEPUGnE8P/image.png" alt=""><figcaption></figcaption></figure>
3. In the **Search services and marketplace** box, enter **Bsure Insights**.

   <figure><img src="https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/uCd9G4QvnJb2MjFUNNla/image.png" alt=""><figcaption></figcaption></figure>
4. From the results, select **Bsure Insights for Microsoft 365 and Entra ID - Data Collector** ([direct link](https://portal.azure.com/#create/bsureas1656340440185.bsure_ma_insightsdaily_per_user_rated)).
5. Select the default Plan **Bsure PayGo**, and click **Create**.
6. On the **Create Bsure Insights** page, the first section is **Basics**.&#x20;
   * **Subscription** - Select the subscription you have decided to use for your installation.
   * **Resource group** - Select your resource group, or create a new one if needed.
   * **Region** - Select your region (recommended to use the same region as your Storage Account).
   * **Application Name** - Select a name for the application.
   * **Managed Resource Group** - Use the provided name.\
     ![](https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/eEsV0uwTIrjgUJDnVdHY/image.png)<br>
7. The next section is **Storage Configuration**
   * **Data Retention Days** - Number of days to retain data in the storage account.
   * **Storage Account 1 Connection String** - Enter a valid Storage Account connection string. (*You will find the connection string by going to your storage account and choose the menu **Access Keys***).
   * **Confirm Connection String** - Paste the same connection string again.
   * **Advanced Configuration (**<mark style="color:red;">**Optional**</mark>**)**

     Select only if you want to write data to a second Storage Account. A second storage account can be used for multi-tenant support, or as a separate archive (*Data Retention Days does not apply to the second storage account*).<br>

     <figure><img src="https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/UuYUkMpehmdijClnbq06/confsa.png" alt=""><figcaption></figcaption></figure>
8. Select **Next : Review + create**\
   After validation is passed, agree to the terms and conditions, and select **Create**.
9. Wait for deployment to finish (less than 5 minutes).

</details>

{% hint style="info" %}
After the installation is complete, the Data Collector will start collecting data within 15 minutes.
{% endhint %}

<details>

<summary>Step 4 - Install Bsure Insights Power Bi app</summary>

1. Go to [Microsoft Appsource](https://appsource.microsoft.com/) with a Power Bi Pro licensed user.
2. Search for  **Bsure Insights**, and select our app. \
   You can also use this direct link: \
   [Bsure Insights for Microsoft 365 and Entra ID](https://appsource.microsoft.com/en-us/product/power-bi/bsureas1656340440185.bsure_pbi_insight)<br>

   <figure><img src="https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/9UmEsuXXbA2Ax3jPKhSY/image.png" alt=""><figcaption></figcaption></figure>
3. Select **Get it now**. (Sign in if prompted)\
   ![](https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/X20WcjObeangfnjNHCPG/image.png)\
   If prompted - confirm your details, agree to the terms of use and select **Get it now** again.
4. Select **Install**.\
   ![](https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/6sfTFMAfZ7VurumqAUCz/image.png)
5. Wait for installation to complete (less than 5 minutes)
6. Go to **Apps** and start **Bsure Insights**\
   ![](https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/1lBVVEcNcwAtrrXFOtLs/image.png)
7. You are now viewing the app with sample data. Select **Connect your data** in the yellow ribbon.\
   ![](https://content.gitbook.com/content/8ZA9wzEc66a3iRTBh11w/blobs/ADAjadMc2mxxTPEeknGu/image.png)
8. Enter the **Name** of your storage account (from [prerequisites](https://docs.bsure.io/v1/installation/prerequisites)) and select **Next**.
9. Enter the **Access Key** to your storage account in the **Account key** field, and select **Sign in and connect**.

You should now be able to see your own data in the Power Bi app!

</details>

{% hint style="info" %}
Typically, it is sufficient for a single user in your organization to install the Power BI app.

You can find instructions on how to share the app with others in our [sharing guide](https://docs.bsure.io/v1/user-guides/share-the-power-bi-app).
{% endhint %}

<details>

<summary>Step 5 - Configure Power BI app data refresh</summary>

Go to Workspaces and select Bsure Insights

![](https://1625452539-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8ZA9wzEc66a3iRTBh11w%2Fuploads%2FdcmwRUTRXFBeKokBf705%2Fimage.png?alt=media\&token=e36e03e6-c930-4c9c-900e-6b301a99633a)

Move mouse over Bsure Insights and select icon to configure refresh

![](https://1625452539-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8ZA9wzEc66a3iRTBh11w%2Fuploads%2Fuye0PPTzixnwBi7S3jpX%2Fimage.png?alt=media\&token=06193ffd-e19c-4fed-9af0-e058a65a6dce)

Expand Refresh, Add another time and set it to 6 AM local time of Your Azure region.

![](https://1625452539-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8ZA9wzEc66a3iRTBh11w%2Fuploads%2FGo9gi30n5NkJJyxLNDxJ%2Fimage.png?alt=media\&token=ced9dce4-c610-4a13-b6df-0057bfe4278b)

Press apply

</details>
