Pessoal, Tudo bem?
Cenário
Alguns clientes tem se voltado para a implantação do Power BI Embedded em horários apenas administrativos encapsulando seus relatórios em um portal customizado, ou seja, fora do expediente o serviço é paralisado evitando assim cobrança desnecessária para o cliente, isto torna grande a redução de custo e potencializa a utilização do Power BI para muito mais usuários dentro da empresa.
Solução
Esta configuração é realizada via Automation do Azure, criando um runbook com o seguinte código:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
workflow PBIEmbedded_StartStop { Param ( [Parameter(Mandatory=$true)] [String] $AzureResourceGroup, [Parameter(Mandatory=$true)] [String] $PowerBIEmbeddedName, [Parameter(Mandatory=$true)] [Boolean] $Suspend ) $connectionName = "AzureRunAsConnection" try { # Get the connection "AzureRunAsConnection " $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName "Logging in to Azure..." Add-AzureRmAccount -ServicePrincipal -TenantId $servicePrincipalConnection.TenantId -ApplicationId $servicePrincipalConnection.ApplicationId -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint } catch { if (!$servicePrincipalConnection) { $ErrorMessage = "Connection $connectionName not found." throw $ErrorMessage } else{ Write-Error -Message $_.Exception throw $_.Exception } } if($Suspend -eq $true ) { try { #Suspending the Service "Suspending $PowerBIEmbeddedName started" $SuspendOperation = Suspend-AzureRmPowerBIEmbeddedCapacity -Name $PowerBIEmbeddedName -ResourceGroupName $AzureResourceGroup -PassThru "$PowerBIEmbeddedName is Suspended Successfully" } catch { Write-Error -Message $_.Exception throw $_.Exception } } else { try { #Resuming the Service "Resuming $PowerBIEmbeddedName" $ResumeOperation = Resume-AzureRmPowerBIEmbeddedCapacity -Name $PowerBIEmbeddedName -ResourceGroupName $AzureResourceGroup -PassThru "$PowerBIEmbeddedName Resumed Successfully " } catch { Write-Error -Message $_.Exception throw $_.Exception } } } |
O que pode ocorrer ao você tentar implementar pela primeira vez é o seguinte erro:
Suspend-AzureRmPowerBIEmbeddedCapacity’ is not recognized as the name of a cmdlet + automation
Outro erro comum:
Cannot find the ‘Test-AzureRmPowerBIEmbeddedCapacity’ command. If this command is defined as a workflow, ensure it is defined before the workflow that calls it. If it is a command intended to run directly within Windows PowerShell (or is not available on this system), place it in an InlineScript: ‘InlineScript { Test-AzureRmPowerBIEmbeddedCapacity }’

Para isto, basta você importar os seguintes módulos em sua conta do Automation:
- AzureRM.profile
- AzureRM.PowerBIEmbedded
Eles possibiltam a utilização do cmdlets que o script necessita.
Espero que ajude!
Até breve,
Vithor da Silva e Silva | Consultor e Instrutor | SQL Server e Power BI
vithor@vssti.com.br