Az.Plus.psm1

# Az.Accounts
$authModuleName = 'Az.Accounts'
$authModuleVersion = '2.7.5'
$authModule = Get-Module -Name $authModuleName
if(-not $authModule) {
  if(-not $authModule) {
    $hasAdequateVersion = (Get-Module -Name $authModuleName -ListAvailable | Where-Object { $_.Version -ge [System.Version]$authModuleVersion } | Measure-Object).Count -gt 0
    if($hasAdequateVersion) {$authModule = Import-Module -Name $authModuleName -MinimumVersion $authModuleVersion -Scope Global -PassThru}
  }
}
if(-not $authModule) {
  Write-Error "`nThis module requires $authModuleName version $authModuleVersion or greater. For installation instructions, please see: https://docs.microsoft.com/powershell/azure/install-az-ps" -ErrorAction Stop
} elseif ($authModule.Version -lt [System.Version]$authModuleVersion) {
  Write-Error "`nThis module requires $authModuleName version $authModuleVersion or greater. An earlier version of Az.Accounts is imported in the current PowerShell session.`nAdditionally, this error could indicate that multiple incompatible versions of Azure PowerShell modules are installed on your system. For troubleshooting information, please see: https://aka.ms/azps-version-error" -ErrorAction Stop
}

<#
.SYNOPSIS
    Get-AzAppServiceRuntimeVersion
.DESCRIPTION
    Get Azure App Service runtime version (webapp + function)
.NOTES
    (c) 2023 JDMSFT. All rights reserved.
    Function developed using following modules:
    2.10.4 Az.Accounts
    4.0.6 Az.Functions
    0.13.0 Az.Resource Graph
.EXAMPLE
    Get-AzAppServiceRuntimeVersion
#>

Function Get-AzAppServiceRuntimeVersion {
    # Function App
    $resources = Search-AzGraph 'resources | where type == "microsoft.web/sites" and kind == "functionapp" | project id, kind, state = properties.state' -UseTenantScope
    $resources | % {
        $functionApp = $null
        $appSettings = $null
        $functionApp = Get-AzFunctionApp -SubscriptionId $_.ResourceId.Split('/')[2] -ResourceGroupName $_.ResourceId.Split('/')[4] -Name $_.ResourceId.Split('/')[8]
        $appSettings = $functionApp.ApplicationSettings
        [array]$pso += [PSCustomObject]@{resourceId = $_.ResourceId; kind = $_.Kind; state = $_.state ; system = $functionApp.OSType ; runtimeWorker = $appSettings.FUNCTIONS_WORKER_RUNTIME; runtimeVersion = $appSettings.FUNCTIONS_EXTENSION_VERSION }
    }
    # WebApp
    $resources = Search-AzGraph 'resources | where type == "microsoft.web/sites" and kind != "functionapp" | mv-expand FxVersion = properties.siteProperties.properties | where isnotempty(FxVersion.value) | extend system = iff(FxVersion.name == "LinuxFxVersion", "Linux", "Windows") | extend runtimeWorker = split(FxVersion.value,"|")[0] | extend runtimeVersion = split(FxVersion.value,"|")[1] | project id, kind, state=properties.state, system, runtimeWorker, runtimeVersion' -UseTenantScope
    $resources | % {[array]$pso += [PSCustomObject]@{resourceId = $_.ResourceId; kind = 'webapp'; state = $_.state ; system = $_.system ; runtimeWorker = $_.runtimeWorker; runtimeVersion = $_.runtimeVersion }}
    $pso
}