Skip to content

Commit 66f645a

Browse files
authored
Merge pull request lazywinadmin#27 from lazywinadmin/appserv_vnetinteg
Update code to retrieve VNET Integration directly from WebApp
2 parents 2e372cb + 224e133 commit 66f645a

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

AZURE-AppService-Apps_without_VNETIntegration/Apps_without_VNETIntegration.ps1 renamed to AZURE-AppService-WebApps_without_VNETIntegration/WebApps_without_VNETIntegration.ps1

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
<#
22
.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
44
55
.DESCRIPTION
66
This script will do the following steps:
77
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
1211
.EXAMPLE
13-
./Apps_without_VNETIntegration.ps1
12+
./WebApps_without_VNETIntegration.ps1
1413
1514
Output the Apps using a App Service Plan without VNET Integration
1615
.EXAMPLE
17-
./Apps_without_VNETIntegration.ps1|
16+
./WebApps_without_VNETIntegration.ps1|
1817
Export-Csv report.csv
1918
2019
Send the output to an excel report
@@ -24,10 +23,14 @@ This script will do the following steps:
2423
2524
# TODO
2625
-Support for retries
26+
-Use Parallel call if v7.0+
2727
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
3134
* Creating VNET Integration
3235
https://stackoverflow.com/questions/59976040/how-do-you-associate-an-azure-web-app-with-a-vnet-using-powershell-az
3336
@@ -70,32 +73,26 @@ try{
7073
if(-not(Get-AzContext)){Connect-AzAccount}
7174

7275
# 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
7477

7578
# Get Current token
7679
$token = Get-AzToken
7780

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'"
8191
$Result = invoke-restmethod -method get -uri $uri -Headers @{Authorization="Bearer $token";'Content-Type'='application/json'} -verbose:$false
8292

8393
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
9996
}
10097
}
10198
}catch{

0 commit comments

Comments
 (0)