1
1
<#
2
2
. SYNOPSIS
3
- Retrieve Apps using a App Service Plan without VNET Integration in the current Tenant
3
+ Retrieve WebApps without VNET Integration in the current Tenant
4
4
5
5
. DESCRIPTION
6
6
This script will do the following steps:
7
7
8
- -Retrieve App Service Plan accross the Tenant
9
- -Check if they have a VNET Integration present
10
- -If Not, retrieve the WebApp using the App Service Plan
11
- -Output the result
8
+ -Using Resource Graph API: Retrieve WebApp accross the tenant
9
+ -Using Management API: Check if they have a VNET Integration present
10
+ -If Not, Output the WebApp information
12
11
. EXAMPLE
13
- ./Apps_without_VNETIntegration .ps1
12
+ ./WebApps_without_VNETIntegration .ps1
14
13
15
14
Output the Apps using a App Service Plan without VNET Integration
16
15
. EXAMPLE
17
- ./Apps_without_VNETIntegration .ps1|
16
+ ./WebApps_without_VNETIntegration .ps1|
18
17
Export-Csv report.csv
19
18
20
19
Send the output to an excel report
@@ -24,10 +23,14 @@ This script will do the following steps:
24
23
25
24
# TODO
26
25
-Support for retries
26
+ -Use Parallel call if v7.0+
27
27
28
- # Resources
29
- * List VnetIntegration in a particular RG for a App Service Plan
30
- az appservice vnet-integration list -g <resource group name> --plan <app Service plan name>
28
+ # RESOURCES
29
+ * List VnetIntegration in a particular RG for a webapp
30
+ az webapp vnet-integration list
31
+ https://docs.microsoft.com/en-us/cli/azure/webapp/vnet-integration?view=azure-cli-latest
32
+ * WebApp integration with VNET
33
+ https://docs.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet#automation
31
34
* Creating VNET Integration
32
35
https://stackoverflow.com/questions/59976040/how-do-you-associate-an-azure-web-app-with-a-vnet-using-powershell-az
33
36
70
73
if (-not (Get-AzContext )){Connect-AzAccount }
71
74
72
75
# Retrieve All the App Service Plan (ServerFarms) using Resource Graph
73
- $servicePlans = Search-AzGraph - Query " Resources | where type == 'microsoft.web/serverfarms'" - First 1000
76
+ # $servicePlans=Search-AzGraph -Query "Resources | where type == 'microsoft.web/serverfarms'" -First 1000
74
77
75
78
# Get Current token
76
79
$token = Get-AzToken
77
80
78
- foreach ($sp in $serviceplans ){
79
- Write-Verbose - Message " Service Plan: '$ ( $sp.name ) ' - VNET Integration - Retrieving..."
80
- $uri = " https://management.azure.com/subscriptions/$ ( $sp.subscriptionId ) /resourceGroups/$ ( $sp.resourcegroup ) /providers/Microsoft.Web/serverfarms/$ ( $sp.name ) /virtualNetworkConnections?api-version=2019-08-01"
81
+ # Retrieve all the WebApp
82
+ Write-Verbose - Message " WebApp - Retrieving WebApps in Tenant..."
83
+ $Apps = Search-AzGraph - Query " Resources |where type == 'microsoft.web/sites' and kind contains 'app'"
84
+
85
+ # Retrieve VNET Integration information for each
86
+ $Apps | ForEach-Object - Process {
87
+ $App = $_
88
+ Write-Verbose - Message " WebApp - '$ ( $App.Name ) ' - Retrieving VNET Integration..."
89
+ $Uri = " https://management.azure.com/subscriptions/$ ( $app.subscriptionId ) /resourceGroups/$ ( $App.ResourceGroup ) /providers/Microsoft.Web/sites/$ ( $App.name ) /virtualNetworkConnections?api-version=2019-08-01"
90
+ Write-Verbose - Message " WebApp - '$ ( $App.Name ) ' - Uri '$Uri '"
81
91
$Result = invoke-restmethod - method get - uri $uri - Headers @ {Authorization = " Bearer $token " ;' Content-Type' = ' application/json' } - verbose:$false
82
92
83
93
if (-not $result ){
84
- Write-Verbose - Message " Service Plan: '$ ( $sp.name ) ' - VNET Integration - Not present..."
85
- Write-Verbose - Message " Service Plan: '$ ( $sp.name ) ' - Retrieving Apps using this App Service Plan..."
86
- $Apps = Search-AzGraph - Query " Resources |where properties.serverFarmId contains '$ ( $sp.id ) '" - first 1000
87
-
88
- foreach ($app in $apps )
89
- {
90
- [pscustomobject ]@ {
91
- AppServicePlanName = $sp.name
92
- AppServicePlanResourceId = $sp.id
93
- AppName = $app.name
94
- AppResourceId = $app.id
95
- AppResourceType = $app.type
96
- }
97
-
98
- }
94
+ Write-Verbose - Message " WebApp - '$ ( $App.Name ) ' - DOT NOT HAVE VNET INTEGRATION"
95
+ $App
99
96
}
100
97
}
101
98
}catch {
0 commit comments