maester icon indicating copy to clipboard operation
maester copied to clipboard

Required modules for Azure connection should be minimized

Open sassdawe opened this issue 1 year ago • 3 comments

When connecting to All or Azure services without the necessary modules being preinstalled the error message is generated too broadly:

if ($Service -contains "Azure" -or $Service -contains "All") {
      Write-Verbose "Connecting to Microsoft Azure"
      try {
         Connect-AzAccount -SkipContextPopulation -UseDeviceAuthentication:$UseDeviceCode -Environment $AzureEnvironment
      } catch [Management.Automation.CommandNotFoundException] {
         Write-Host "`nThe Azure PowerShell module is not installed. Please install the module using the following command. For more information see https://learn.microsoft.com/powershell/azure/install-azure-powershell" -ForegroundColor Red
         Write-Host "`Install-Module Az -Scope CurrentUser`n" -ForegroundColor Yellow
      }
   }

Do we need the full Azure PowerShell package or only Az.Accounts?

sassdawe avatar Jul 28 '24 16:07 sassdawe

This can be my first issue 😊

sassdawe avatar Jul 28 '24 16:07 sassdawe

Currently, I believe the only the only cmdlet using Azure is https://github.com/maester365/maester/blob/main/powershell/public/cisa/entra/Test-MtCisaDiagnosticSettings.ps1.

That does use Invoke-AzRestMethod. Assuming future cmdlets would use that method rather than the submodules Az.Accounts would be sufficient.

soulemike avatar Jul 30 '24 01:07 soulemike

@sassdawe yes please go ahead with a PR. Tx!

merill avatar Aug 04 '24 21:08 merill

It's been 3 months so I put in a PR, hope that's ok.

dnsinit avatar Nov 07 '24 23:11 dnsinit