Created
December 22, 2019 21:45
-
-
Save dzsquared/86abb47dc5ed7562c20566113d7e3c47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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