Hello;
I created an azure function that connects to Power BI service, retrieves logs and saves data in a Storage blob. Knowing that the service principal has access to all workspaces. There is a large number of datasets related to each workspace. My function runs almost several attempts. I would like to know how to solve this problem knowing that I cannot expand my resources.
Here is the code of the function :
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
$name = $Request.Body.Name
}
$body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
if ($name) {
#Initialisation des paramétres d'identification pour le service principale
$appId = $env:APP_ID
$tenantId = $env:APP_TENANT_ID
$secret = $env:APP_SECRET
$password = ConvertTo-SecureString $secret -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ($appId, $password)
#Write-Output $Cred
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#configure proxy
$webclient=New-Object System.Net.WebClient
$webclient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
#Connexion au service POWER BI
Connect-PowerBIServiceAccount -ServicePrincipal -Tenant $tenantId -Credential $Cred
#Write-Host $name
for($i=0;$i -lt $name;$i++)
{
$activitiesDate = [System.DateTime]::Now.Date.AddDays(-$i)
$dateTimeStart = $activitiesDate.Date.ToString("s")
$dateTimeEnd = $activitiesDate.Date.AddHours(23).AddMinutes(59).AddSeconds(59).ToString("s")
Write-Host $activitiesDate
Write-Host $dateTimeStart
Write-Host $dateTimeEnd
#activities = Get-PowerBIActivityEvent -StartDateTime $dateTimeStart -EndDateTime: $dateTimeEnd | ConvertFrom-Json
#Récuperation des données logs
$activities = Get-PowerBIActivityEvent -StartDateTime $dateTimeStart -EndDateTime $dateTimeEnd | ConvertFrom-Json
Write-Host $activities
$psObjectForCsv = $activities | ForEach-Object {
[PSCustomObject]@{
"id"=$_.Id
"RecordType" = $_.RecordType
"CreationTime" = $_.CreationTime
"Operation" = $_.Operation
"OrganizationId" = $_.OrganizationId
"UserType" = $_.UserType
"UserKey" = $_.UserKey
"Workload"=$_.Workload
"UserId"=$_.UserId
"ClientIP"=$_.ClientIP
"UserAgent"=$_.UserAgent
"Activity"=$_.Activity
"ItemName"=$_.ItemName
"WorkSpaceName"=$_.WorkSpaceName
"DatasetName"=$_.DatasetName
"ReportName"=$_.ReportName
"WorkspaceId"=$_.WorkspaceId
"ObjectId"=$_.ObjectId
"DatasetId"=$_.DatasetId
"ReportId"=$_.ReportId
"EmbedTokenId"=$_.EmbedTokenId
"IsSuccess"=$_.IsSuccess
"ReportType"=$_.ReportType
"RequestId"=$_.RequestId
"ActivityId"=$_.ActivityId
"DistributionMethod"=$_.DistributionMethod
"ConsumptionMethod"=$_.ConsumptionMethod
}
}
}
#saving data in the output file blob
Push-OutputBinding -Name outputBlob -Value $psObjectForCsv
Write-Host $psObjectForCsv
}
Here is the error that is shown.
][1]
Any help will be appreciated.


][4]