-
Notifications
You must be signed in to change notification settings - Fork 0
/
Start-Stop-All-Web-Apps.ps1
49 lines (45 loc) · 1.33 KB
/
Start-Stop-All-Web-Apps.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
workflow Start-Stop-All-Web-Apps
{
Param
(
[Parameter(Mandatory=$true)][ValidateSet("Start","Stop")]
[String]
$Action
)
$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
}
}
$WebApps = Get-AzureRmWebApp
Write-Output "--------------"
if($Action -eq "Stop")
{
Write-Output "Stopping all Web Apps";
foreach -parallel ($WebApp in $WebApps)
{
Stop-AzureRmWebApp -ResourceGroupName $WebApp.ResourceGroup -Name $WebApp.Name
}
}
else
{
Write-Output "Starting all Web Apps";
}
}