Private/Get-CitrixReport.ps1

<#
.SYNOPSIS
    Generates Citrix license reports for daily or monthly usage.
 
.DESCRIPTION
    The `Get-CitrixReport` function dynamically processes Citrix license reports based on the selected report type.
    It supports both daily and monthly reports, fetching data from specified input folders and saving it to output folders.
 
.PARAMETER InputFolder
    The folder containing the source Citrix license report files.
 
.PARAMETER OutputFolder
    The folder where the final processed reports should be saved.
 
.PARAMETER ReportType
    The type of report to generate. Accepts "Daily" or "Monthly".
 
.EXAMPLE
    Get-CitrixReport -InputFolder "C:\Reports\Raw" -OutputFolder "C:\Reports\Processed" -ReportType Daily
 
.EXAMPLE
    Get-CitrixReport -InputFolder "C:\Reports\Raw" -OutputFolder "C:\Reports\Processed" -ReportType Monthly
 
#>

Function Get-CitrixReport {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [string]$InputFolder,

        [Parameter(Mandatory = $true)]
        [string]$OutputFolder,

        [Parameter(Mandatory = $true)]
        [ValidateSet("Daily", "Monthly")]
        [string]$ReportType
    )

    try {
        # Ensure input folder exists
        if (-not (Test-Path -Path $InputFolder)) {
            Write-Host "`n[ERROR] Input folder '$InputFolder' does not exist." -ForegroundColor Red
            return
        }

        # Ensure output folder exists or create it
        if (-not (Test-Path -Path $OutputFolder)) {
            New-Item -Path $OutputFolder -ItemType Directory -Force | Out-Null
        }

        # Generate report based on type
        if ($ReportType -eq "Daily") {

             # If today is Monday, pick Friday's CSV; otherwise, pick yesterday's CSV
            if ((Get-Date).DayOfWeek -eq "Monday") {
                $ReportDate = (Get-Date).AddDays(-3).ToString("yyyy-MM-dd")  # Get Friday's date
                Write-Host "`n[INFO] Today is Monday, picking Friday's report ($ReportDate)" -ForegroundColor Cyan
            } else {
                $ReportDate = (Get-Date).AddDays(-1).ToString("yyyy-MM-dd")  # Get Yesterday's date
            }

            $parentFolder = Split-Path -Path $InputFolder -Parent
            $foldernme = Join-Path -Path $parentFolder -ChildPath CSV
            $dailyReportFile = Join-Path -Path $foldernme -ChildPath "licreport_$ReportDate.csv"

            if (Test-Path -Path $dailyReportFile) {
                Write-Host "`n[INFO] Processing Daily Report: $dailyReportFile" -ForegroundColor Cyan
                Get-CitrixDailyReport -csvfile $dailyReportFile -Folder $OutputFolder
            } else {
                Write-Host "`n[WARNING] Daily report file not found: $dailyReportFile" -ForegroundColor Yellow
            }

        } elseif ($ReportType -eq "Monthly") {
            Write-Host "`n[INFO] Processing Monthly Report from folder: $InputFolder" -ForegroundColor Cyan
            Get-CitrixMonthlyReport -ExcelFolder $InputFolder -MonthlyFolder $OutputFolder
        }

        Write-Host "`n[SUCCESS] Citrix $ReportType Report has been generated successfully!" -ForegroundColor Green

    } catch {
        Write-Host "`n[ERROR] Failed to generate Citrix report: $($_.Exception.Message)" -ForegroundColor Red
    }
}