Modules/Core/ARIAzCli.psm1

<#
.Synopsis
Test Azure CLI components
 
.DESCRIPTION
This module is use to validate if the required components are present.
 
.Link
https://github.com/microsoft/ARI/Core/Test-AzCli.psm1
 
.COMPONENT
This powershell Module is part of Azure Resource Inventory (ARI)
 
.NOTES
Version: 4.0.1
First Release Date: 15th Oct, 2024
Authors: Claudio Merola
 
#>

function Test-ARIAzCli {
    Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Starting Test-AzCli function')
    Write-Output "Validating Az Cli.."
    $azcli = az --version
    Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Current az cli version: ' + $azcli[0])
    if ($null -eq $azcli) {
        Read-Host "Azure CLI Not Found. Press <Enter> to finish script"
        Exit
    }
    Write-Host "Validating Az Cli Extension.."
    $azcliExt = az extension list --output json | ConvertFrom-Json
    $azcliExt = $azcliExt | Where-Object {$_.name -eq 'resource-graph'}
    Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Current Resource-Graph Extension Version: ' + $azcliExt.version)
    $AzcliExtV = $azcliExt | Where-Object {$_.name -eq 'resource-graph'}
    if (!$AzcliExtV) {
        Write-Host "Adding Az Cli Extension"
        az extension add --name resource-graph
    }
    Write-Host "Validating ImportExcel Module.."
    $VarExcel = Get-InstalledModule -Name ImportExcel -ErrorAction silentlycontinue
    Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'ImportExcel Module Version: ' + ([string]$VarExcel.Version.Major + '.' + [string]$VarExcel.Version.Minor + '.' + [string]$VarExcel.Version.Build))
    if ($null -eq $VarExcel) {
        Write-Host "Trying to install ImportExcel Module.."
        Install-Module -Name ImportExcel -Force
    }
    $VarExcel = Get-InstalledModule -Name ImportExcel -ErrorAction silentlycontinue
    if ($null -eq $VarExcel) {
        Read-Host 'Admininstrator rights required to install ImportExcel Module. Press <Enter> to finish script'
        Exit
    }
}