2
0

Added the ability to exclude a specific SKU from reporting an Error status

This commit is contained in:
2025-02-17 11:19:45 +01:00
parent 294437781b
commit e066a28008

View File

@@ -27,10 +27,11 @@
#region Global script settings and variables
#General
$Version = "v1.0"
$Version = "v1.1"
$logfilelocation = "$($MyInvocation.MyCommand.Path | Split-Path -Parent)\Logs"
$logfilename = "$(Get-Date -Format yyyyMMddHHmmss)-Azure-Licensing-Report.log"
$summaryfilename = "$(Get-Date -Format yyyyMMddHHmmss)-Azure-Licensing-Summary.txt"
$ExludeFromError = @("") #Add the SkuPartNumbers of the licenses you want to exclude from Error
#Azure Enterprise app configuration
$STR_TenantID = ""
@@ -118,7 +119,7 @@
#Setup MSGraph connection
$ClientSecretPass = ConvertTo-SecureString -String $STR_ClientSecret -AsPlainText -Force
$ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $STR_AppID, $ClientSecretPass
Connect-MgGraph -TenantId $STR_TenantID -ClientSecretCredential $ClientSecretCredential
Connect-MgGraph -TenantId $STR_TenantID -ClientSecretCredential $ClientSecretCredential -NoWelcome
Write-Log -Message "Connected to MsGraph API" -Level INFO
#Download the latest product name translation file
@@ -167,7 +168,9 @@
$availableLicensesCount = $totalLicenses - $assignedLicenses
# Calculate license status
if ($availableLicensesCount -le 1) {
if ($licenseDetails.SkuPartNumber -in $ExludeFromError) {
$licenseStatus = "UNMONITORED"
} elseif ($availableLicensesCount -le 1) {
$licenseStatus = "ERROR"
} elseif ($availableLicensesCount -le ($totalLicenses * 0.05)) {
$licenseStatus = "WARNING"