Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2e372cb

Browse files
Merge pull request #26 from lazywinadmin/appserv_vnetinteg
Add Azure-AppService-Apps_without_VNETIntegration
2 parents 99ec832 + 185643f commit 2e372cb

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<#
2+
.SYNOPSIS
3+
Retrieve Apps using a App Service Plan without VNET Integration in the current Tenant
4+
5+
.DESCRIPTION
6+
This script will do the following steps:
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
12+
.EXAMPLE
13+
./Apps_without_VNETIntegration.ps1
14+
15+
Output the Apps using a App Service Plan without VNET Integration
16+
.EXAMPLE
17+
./Apps_without_VNETIntegration.ps1|
18+
Export-Csv report.csv
19+
20+
Send the output to an excel report
21+
.LINK
22+
https://github.com/lazywinadmin/PowerShell
23+
.NOTES
24+
25+
# TODO
26+
-Support for retries
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>
31+
* Creating VNET Integration
32+
https://stackoverflow.com/questions/59976040/how-do-you-associate-an-azure-web-app-with-a-vnet-using-powershell-az
33+
34+
#>
35+
[CmdletBinding()]
36+
PARAM()
37+
try{
38+
# Load Module
39+
$Dependencies=@("Az.ResourceGraph", "Az.Accounts")
40+
if(-not(Get-Module -Name $Dependencies)){$Dependencies| import-Module}
41+
# Functions
42+
function Get-AzToken{
43+
<#
44+
.SYNOPSIS
45+
Retrieve token of the current Azure Context session
46+
.DESCRIPTION
47+
Retrieve token of the current Azure Context session
48+
This is using the Get-AzContext cmdlets from the module Az.Account and assume a session is already opened.
49+
.EXAMPLE
50+
$token=Get-AzToken
51+
$uri = "https://management.azure.com/tenants?api-version=2019年11月01日"
52+
invoke-restmethod -method get -uri $uri -Headers @{Authorization="Bearer $token";'Content-Type'='application/json'}
53+
This leverate the token of the current session to query the Azure Management
54+
API and retrieves all the tenants information
55+
.LINK
56+
https://github.com/lazywinadmin/PowerShell
57+
#>
58+
[CmdletBinding()]
59+
Param()
60+
try{
61+
$currentAzureContext = Get-AzContext
62+
$azureRmProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile;
63+
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azureRmProfile)
64+
$profileClient.AcquireAccessToken($currentAzureContext.Subscription.TenantId).AccessToken
65+
}catch{
66+
throw $_
67+
}
68+
}
69+
# Connect to Azure
70+
if(-not(Get-AzContext)){Connect-AzAccount}
71+
72+
# Retrieve All the App Service Plan (ServerFarms) using Resource Graph
73+
$servicePlans=Search-AzGraph -Query "Resources | where type == 'microsoft.web/serverfarms'" -First 1000
74+
75+
# Get Current token
76+
$token = Get-AzToken
77+
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+
$Result = invoke-restmethod -method get -uri $uri -Headers @{Authorization="Bearer $token";'Content-Type'='application/json'} -verbose:$false
82+
83+
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+
}
99+
}
100+
}
101+
}catch{
102+
throw $_
103+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /