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

(New) Add Licensing Information to AAD Report #1011

Merged
merged 7 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,27 @@ function New-Report {

# Handle AAD-specific reporting
if ($BaselineName -eq "aad") {
$LicenseInfoArray = $SettingsExport.license_information | ForEach-Object {
[pscustomobject]@{
"License SKU Identifier" = $_.SkuPartNumber
"Licenses in Use" = $_.ConsumedUnits
"Total Licenses" = $_.PrepaidUnits.Enabled
}
}
# Convert the custom objects to an HTML table
$LicenseTable = $LicenseInfoArray | ConvertTo-Html -As Table -Fragment
$LicenseTable = $LicenseTable -replace '^(.*?)<table>','<table id="license-info" style = "text-align:center;">'

# Create a section header for the licensing information
$LicensingHTML = "<h2>Tenant Licensing Information</h2>" + $LicenseTable

$ReportHTML = $ReportHTML.Replace("{AADWARNING}", $AADWarning)
$ReportHTML = $ReportHTML.Replace("{CAPTABLES}", "")
$ReportHTML = $ReportHTML.Replace("{LICENSING_INFO}", $LicensingHTML)
$CapJson = ConvertTo-Json $SettingsExport.cap_table_data
}
else {
$ReportHTML = $ReportHTML.Replace("{AADWARNING}", $NoWarning)
$ReportHTML = $ReportHTML.Replace("{CAPTABLES}", "")
$ReportHTML = $ReportHTML.Replace("{LICENSING_INFO}", "")
$CapJson = "null"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<h1>{TITLE}</h1>
<h4>{AADWARNING}</h4>
{TABLES}
{LICENSING_INFO}
</main>
</body>
</html>
3 changes: 2 additions & 1 deletion PowerShell/ScubaGear/Modules/CreateReport/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* Adds the red, green, yellow, and gray coloring to the individual report pages.
*/
const colorRows = () => {
let rows = document.querySelectorAll('tr');
//Adjusted the querySelector to only use the rows which have policy data within them instead of every table in report
let rows = document.querySelectorAll('.policy-data tr');
const requirementCol = 1;
const statusCol = 2;
const criticalityCol = 3;
Expand Down
10 changes: 6 additions & 4 deletions PowerShell/ScubaGear/Modules/Providers/ExportAADProvider.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ function Export-AADProvider {

$AllPolicies = ConvertTo-Json -Depth 10 @($AllPolicies)

$SubscribedSku = $Tracker.TryCommand("Get-MgBetaSubscribedSku")

# Get a list of the tenant's provisioned service plans - used to see if the tenant has AAD premium p2 license required for some checks
# The Rego looks at the service_plans in the JSON
$ServicePlans = $Tracker.TryCommand("Get-MgBetaSubscribedSku").ServicePlans | Where-Object -Property ProvisioningStatus -eq -Value "Success"
$ServicePlans = $SubscribedSku.ServicePlans | Where-Object -Property ProvisioningStatus -eq -Value "Success"

#Obtains license information for tenant and total number of active users
$LicenseInfo = $SubscribedSku | Select-Object -Property Sku*, ConsumedUnits, PrepaidUnits | ConvertTo-Json -Depth 3

if ($ServicePlans) {
# The RequiredServicePlan variable is used so that PIM Cmdlets are only executed if the tenant has the premium license
Expand Down Expand Up @@ -89,9 +94,6 @@ function Export-AADProvider {
}
$ServicePlans = ConvertTo-Json -Depth 3 @($ServicePlans)

#Obtains license information for tenant and total number of active users
$LicenseInfo = $Tracker.TryCommand("Get-MgBetaSubscribedSku") | Select-Object -Property Sku*, ConsumedUnits, PrepaidUnits | ConvertTo-Json -Depth 3

# Checking to ensure command runs successfully
$UserCount = $Tracker.TryCommand("Get-MgBetaUserCount", @{"ConsistencyLevel"='eventual'})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22444,7 +22444,32 @@
},
"Identity": "Tag:Default"
}
],
"license_information": [
{
"SkuId": "f30db892-07e9-47e9-837c-80727f46fd3d",
"SkuPartNumber": "FLOW_FREE",
"ConsumedUnits": 3,
"PrepaidUnits": {
"Enabled": 10000,
"LockedOut": 0,
"Suspended": 0,
"Warning": 0
}
},
{
"SkuId": "c42b9cae-ea4f-4ab7-9717-81576235ccac",
"SkuPartNumber": "DEVELOPERPACK_E5",
"ConsumedUnits": 22,
"PrepaidUnits": {
"Enabled": 25,
"LockedOut": 0,
"Suspended": 0,
"Warning": 0
}
}
],
"total_user_count": 51,
"teams_successful_commands": [
"Get-CsTenant",
"Get-CsTeamsMeetingPolicy",
Expand Down
3 changes: 3 additions & 0 deletions Testing/Functional/Products/Products.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ Describe "Policy Checks for <ProductName>"{
}
}
}
elseif ($Table.GetProperty("id") -eq "license-info"){
#Currently empty to determine if necessary and what to test in section
}
else {
# Control report tables
ForEach ($Row in $Rows){
Expand Down
16 changes: 16 additions & 0 deletions Testing/Functional/SmokeTest/SmokeTest002.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ Describe -Tag "UI","Chrome" -Name "Test Report with <Browser> for $OrganizationN
}
}
}
elseif ($Table.GetProperty("id") -eq "license-info"){

# Iterate through each row in the table ensuring there are 3 columns
foreach ($Row in $Rows) {
$RowHeaders = Get-SeElement -Element $Row -By TagName 'th'
$RowData = Get-SeElement -Element $Row -By TagName 'td'

if ($RowHeaders.Count -gt 0){
$RowHeaders.Count | Should -BeExactly 3
}

if ($RowData.Count -gt 0){
$RowData.Count | Should -BeExactly 3
}
}
}
# Default is normal policy results table
else {
# Control report tables
Expand Down