Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/Improve script #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions Get-AzureAppGatewayExpiringCertificates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ param(
$pageSize = 100
$iteration = 0
$searchParams = @{
Query = 'where type =~ "Microsoft.Network/applicationGateways" | project id, subscriptionId, subscriptionDisplayName, resourceGroup, name, sslCertificates = properties.sslCertificates | order by id'
Query = 'resources
| where type =~ "Microsoft.Network/applicationGateways"
| extend certs = parse_json(properties.sslCertificates)
| join kind=inner (
resourcecontainers
| where type == "microsoft.resources/subscriptions"
| project subscriptionId, subscriptionName = name)
on subscriptionId
| project name, subscriptionName, resourceGroup, certs
| order by name'
First = $pageSize
Include = 'displayNames'
}

$results = do {
Expand All @@ -21,16 +29,16 @@ $results = do {
} while ($pageResults.Count -eq $pageSize)

$90daysfromNow = (Get-Date).AddDays($ExpiresInDays)
$results | % {
$results | foreach-object {
$record = $_

$record.sslCertificates | % {
$record.certs | foreach-object {
$sslCertRecord = $_
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]([System.Convert]::FromBase64String($_.properties.publicCertData.Substring(60,$_.properties.publicCertData.Length-60)))
if ($cert.NotAfter -le $90daysfromNow) {
@{
[pscustomobject]@{
SubscriptionId = $record.subscriptionId
SubscriptionName = $record.subscriptionDisplayName
SubscriptionName = $record.subscriptionName
ResourceGroup = $record.resourceGroup
Name = $record.Name
Cert = $cert
Expand All @@ -41,4 +49,4 @@ $results | % {
}
}
}
}
}