NMM-PS.psm1
|
#Requires -Version 7 #region Classes # Classes must be defined in the module file itself to be accessible to callers # NMMReportSection must be defined before NMMReportBuilder (dependency) class NMMReportSection { [string]$Title [string]$Description [string]$SectionType = 'table' # table, chart, summary, custom [object]$Data [bool]$ShowDataTable = $true [bool]$ShowChart = $false [string]$ChartType = 'bar' # bar, pie, donut, line, area [hashtable]$ChartConfig = @{} [string]$CustomHtml [int]$Order = 0 NMMReportSection() { $this.ChartConfig = @{} } NMMReportSection([string]$title) { $this.Title = $title $this.ChartConfig = @{} } NMMReportSection([string]$title, [object]$data) { $this.Title = $title $this.Data = $data $this.ChartConfig = @{} } } class NMMReportBuilder { [string]$Title [string]$Subtitle [datetime]$GeneratedAt [string]$LogoSource = 'base64' # base64 or url [string]$LogoData [System.Collections.Generic.List[NMMReportSection]]$Sections [hashtable]$Metadata = @{} [string]$Theme = 'light' # light or dark [bool]$IncludeTimestamp = $true [string]$FooterText = "Generated by NMM-PS Module" # Nerdio brand colors hidden [hashtable]$BrandColors = @{ NavyOrbit = '#042838' NerdioBlue = '#1E9DB8' White = '#FFFFFF' GreenGalaxy = '#CDFF4E' ProtonPurple = '#A795C7' } NMMReportBuilder() { $this.Sections = [System.Collections.Generic.List[NMMReportSection]]::new() $this.GeneratedAt = Get-Date $this.Metadata = @{} } NMMReportBuilder([string]$title) { $this.Title = $title $this.Sections = [System.Collections.Generic.List[NMMReportSection]]::new() $this.GeneratedAt = Get-Date $this.Metadata = @{} } [void] AddSection([NMMReportSection]$section) { if ($section.Order -eq 0) { $section.Order = $this.Sections.Count + 1 } $this.Sections.Add($section) } [void] SetLogo([string]$source, [string]$data) { $this.LogoSource = $source $this.LogoData = $data } [hashtable] GetBrandColors() { return $this.BrandColors } } #endregion Classes # Then load functions (excluding Classes folder which is already loaded) $Functions = @(Get-ChildItem -Path $PSScriptRoot\Public\ -Include *.ps1 -Recurse) + @(Get-ChildItem -Path $PSScriptRoot\Private\ -Include *.ps1 -Recurse | Where-Object { $_.DirectoryName -notlike '*\Classes*' -and $_.DirectoryName -notlike '*Classes' }) # Import functions. foreach ($Function in @($Functions)) { try { Write-Verbose "Importing function $($Function.FullName)" . $Function.FullName } catch { Write-Error -Message "Failed to import function $($Function.FullName): $_" } } |