Skip to content

Commit 9f521aa

Browse files
authored
Merge pull request #1 from slapointe/feature/refresh-q2-2021
Refreshed versions of scripts as of 2021-06-14
2 parents e24034b + 4cdde14 commit 9f521aa

File tree

6 files changed

+47
-36
lines changed

6 files changed

+47
-36
lines changed

app-service/list-outbound-ips-legacy/Get-AppServiceWebAppsOutboundIpAddresses.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ $ErrorActionPreference = 'Stop'
1010
$webApps = @()
1111
$SubscriptionName | % {
1212
Write-Host ('Switching to subscription {0}' -f $_)
13-
$subContext = Set-AzureRmContext -SubscriptionName $_
14-
$webApps += Get-AzureRmWebApp
15-
13+
$subContext = Set-AzContext -SubscriptionName $_
14+
$webApps += Get-AzWebApp
1615
}
1716

1817
$ipMatch = @(

app-service/list-outbound-ips-legacy/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
You'll find in this function an easy way to extract the outbound IP addresses information used by all your App Services in your subscriptions by using the Azure Resource Graph, it is very fast compared to the old version scanning all subscription one at a time (50x faster for me)
44

55
## Requirements
6-
Tested with AzureRM.Profile Version 3.2.x & AzureRM.Websites 3.2.x
7-
8-
Tested with AzureRM.Profile Version 5.8.x & AzureRM.Websites 5.2.x
6+
Tested with Az.Accounts Version 2.2.x & Az.Websites 2.5.X
97

108
## Usage
119
```powershell
12-
Login-AzureRmAccount
10+
Connect-AzAccount
1311
1412
.\Get-AppServiceWebAppsOutboundIpAddresses.ps1 -SubscriptionName 'mysub1','mysub2' -IncludePossibleOutputIpAddresses
1513
```

app-service/list-outbound-ips/Get-AzureWebAppsOutboundIpAddresses.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,17 @@ $queryParams = @{
2929
if($matchedSubscriptions) {
3030
$queryParams.Subscription = $matchedSubscriptions.Id
3131
}
32-
$webApps = Search-AzGraph @queryParams
32+
33+
$webApps = @()
34+
do {
35+
$webApps += Search-AzGraph @queryParams
36+
if($webApps.SkipToken) {
37+
$queryParams.SkipToken = $webApps.SkipToken
38+
}
39+
} while ($webApps.SkipToken)
3340

3441
$ipMatch = @(
35-
$webApps | % {
42+
$webApps.Data | % {
3643
$webAppName = $_.name
3744
$ipAddresses = @($_.outboundIpAddresses -split ',' | % { @{ IpAddress = $_; Type='Outbound' } })
3845
if($IncludePossibleOutputIpAddresses) {

app-service/list-outbound-ips/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
You'll find in this function an easy way to extract the outbound IP addresses information used by all your App Services in your subscriptions by using the Azure Resource Graph, it is very fast compared to the old version scanning all subscription one at a time (50x faster for me)
44

55
## Requirements
6-
Tested with Az.ResourceGraph Version 0.7.x
6+
Tested with Az.ResourceGraph Version 0.10.x
77

88
## Usage
99
```powershell

application-gateway/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Did you ever had developers or engineers coming to your desk in panic realizing
55
## Requirements
66
Tested with Azure PowerShell Az v1.x.x
77

8-
Tested with Azure PowerShell Az.ResourceGraph module v0.7.6
8+
Tested with Azure PowerShell Az.ResourceGraph module v0.10.0
99

1010
## The problematic
1111
Did you ever had developers or engineers coming to your desk in panic realizing their Azure Application Gateway' certificates expired without them knowing it in advance. Causing them downtime in their release pipeline, dev or worst, their production environment!

application-gateway/expiring-certificates/Get-AzureAppGatewayExpiringCertificates.ps1

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,46 @@ param(
66
$pageSize = 100
77
$iteration = 0
88
$searchParams = @{
9-
Query = 'where type =~ "Microsoft.Network/applicationGateways" | project id, subscriptionId, subscriptionDisplayName, resourceGroup, name, sslCertificates = properties.sslCertificates | order by id'
10-
First = $pageSize
11-
Include = 'displayNames'
9+
Query = 'Resources | where type =~ "Microsoft.Network/applicationGateways" | join kind=leftouter (ResourceContainers | where type=="microsoft.resources/subscriptions" | project subscriptionName=name, subscriptionId) on subscriptionId | project id, subscriptionId, subscriptionName, resourceGroup, name, sslCertificates = properties.sslCertificates | order by id'
10+
First = $pageSize
1211
}
1312

14-
$results = do {
13+
$results = @()
14+
do {
1515
$iteration += 1
1616
Write-Verbose "Iteration #$iteration"
17-
$pageResults = Search-AzGraph @searchParams
18-
$searchParams.Skip += $pageResults.Count
19-
$pageResults
20-
Write-Verbose $pageResults.Count
21-
} while ($pageResults.Count -eq $pageSize)
17+
$results += Search-AzGraph @searchParams
18+
if ($results.SkipToken) {
19+
$searchParams.SkipToken = $results.SkipToken
20+
}
21+
} while ($results.SkipToken)
2222

23-
$90daysfromNow = (Get-Date).AddDays($ExpiresInDays)
24-
$results | % {
23+
$expirationDate = (Get-Date).AddDays($ExpiresInDays)
24+
$results.Data | ForEach-Object {
2525
$record = $_
2626

27-
$record.sslCertificates | % {
27+
$record.sslCertificates | ForEach-Object {
2828
$sslCertRecord = $_
29-
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]([System.Convert]::FromBase64String($_.properties.publicCertData.Substring(60,$_.properties.publicCertData.Length-60)))
30-
if ($cert.NotAfter -le $90daysfromNow) {
31-
@{
32-
SubscriptionId = $record.subscriptionId
33-
SubscriptionName = $record.subscriptionDisplayName
34-
ResourceGroup = $record.resourceGroup
35-
Name = $record.Name
36-
Cert = $cert
37-
CertificateName = $sslCertRecord.name
38-
NotAfter = $cert.NotAfter
39-
Thumbprint = $cert.Thumbprint
40-
ImpactedListeners = ,@($sslCertRecord.properties.httpListeners | ForEach-Object { ($_.id -split'/')[-1] } )
41-
}
29+
if (-not $_.properties.publicCertData) {
30+
$msg = 'Certificate {0} is linked to Key Vault secret: {1}. Certificate scanning is not supported in this scenario. You can leverage Azure Policy to do so.' -f $_.name, $_.properties.keyVaultSecretId
31+
Write-Warning $msg -Verbose
32+
}
33+
else {
34+
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]([System.Convert]::FromBase64String($_.properties.publicCertData.Substring(60, $_.properties.publicCertData.Length - 60)))
35+
if ($cert.NotAfter -le $expirationDate) {
36+
@{
37+
SubscriptionId = $record.subscriptionId
38+
SubscriptionName = $record.subscriptionDisplayName
39+
ResourceGroup = $record.resourceGroup
40+
Name = $record.Name
41+
Cert = $cert
42+
CertificateName = $sslCertRecord.name
43+
NotAfter = $cert.NotAfter
44+
Thumbprint = $cert.Thumbprint
45+
ImpactedListeners = , @($sslCertRecord.properties.httpListeners | ForEach-Object { ($_.id -split '/')[-1] } )
46+
}
47+
48+
}
4249
}
4350
}
4451
}

0 commit comments

Comments
 (0)