Skip to content

Instantly share code, notes, and snippets.

@dzsquared
Created December 22, 2019 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dzsquared/86abb47dc5ed7562c20566113d7e3c47 to your computer and use it in GitHub Desktop.
Save dzsquared/86abb47dc5ed7562c20566113d7e3c47 to your computer and use it in GitHub Desktop.
# for more info:
# https://www.drewsk.tech/2019/12/24/save-on-your-powerbi-embedded-capacity/
workflow pbi-embedded-suspend-resume
{
Param
(
[Parameter(Mandatory=$true)]
[String]
$AzureResourceGroup,
[Parameter(Mandatory=$true)]
[String]
$PowerBIEmbeddedName,
[Parameter(Mandatory=$true)]
[Boolean]
$Suspend
)
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Connect-AzAccount `
-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
}
}
#checking if the PowerBI Embedded Capacity Exisit
$IsPBEmbExisit=Test-AzPowerBIEmbeddedCapacity -Name $PowerBIEmbeddedName
if($IsPBEmbExisit -eq $true)
{
if($Suspend -eq $true )
{
try
{
#Suspending the Service
"Suspending $PowerBIEmbeddedName started"
$SuspendOperation = Suspend-AzPowerBIEmbeddedCapacity -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-AzPowerBIEmbeddedCapacity -Name $PowerBIEmbeddedName -ResourceGroupName $AzureResourceGroup -PassThru
"$PowerBIEmbeddedName Resumed Successfully "
}
catch
{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
}
else
{
"The Provided Resource $PowerBIEmbeddedName doesnot exist"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment