-
Notifications
You must be signed in to change notification settings - Fork 2
/
Suspend_Resume_PBI-Embedded.ps1
79 lines (68 loc) · 2.21 KB
/
Suspend_Resume_PBI-Embedded.ps1
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
68
69
70
71
72
73
74
75
76
77
78
79
workflow Suspend_Resume_PBI-Embedded
{
Param
(
[Parameter(Mandatory=$true)]
$SubscriptionId,
[Parameter(Mandatory=$true)]
[String]
$AzureResourceGroup,
[Parameter(Mandatory=$true)]
[String]
$PowerBIEmbeddedName,
[Parameter(Mandatory=$true)]
[Boolean]
$Suspend
)
#Please enable appropriate RBAC permissions to the system identity of this automation account. Otherwise, the runbook may fail...
try
{
"Logging in to Azure..."
Disable-AzContextAutosave -Scope Process
Connect-AzAccount -Identity
$AzureContext = Set-AzContext -SubscriptionId $SubscriptionId
}
catch {
Write-Error -Message $_.Exception
throw $_.Exception
}
#checking if the PowerBI Embedded Capacity Exisit
$IsPBEmbExisit = Test-AzPowerBIEmbeddedCapacity -Name $PowerBIEmbeddedName -DefaultProfile $AzureContext
if($IsPBEmbExisit -eq $true)
{
if($Suspend -eq $true )
{
try
{
#Suspending the Service
"Suspending $PowerBIEmbeddedName started"
$SuspendOperation = Suspend-AzPowerBIEmbeddedCapacity -Name $PowerBIEmbeddedName -ResourceGroupName $AzureResourceGroup -PassThru -DefaultProfile $AzureContext
"$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 -DefaultProfile $AzureContext
"$PowerBIEmbeddedName Resumed Successfully "
}
catch
{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
}
else
{
"The Provided Resource $PowerBIEmbeddedName doesnot exist"
}
}