Public/Invoke-CitrixReportProcessing.ps1

<#
.SYNOPSIS
    Generates and sends Citrix License Reports (Daily or Monthly).
 
.DESCRIPTION
    The `Invoke-CitrixReportProcessing` function automates:
    - Generating Citrix reports (Daily or Monthly).
    - Sending those reports via email.
    - Requires the user to specify `-ReportType Daily` or `-ReportType Monthly`.
 
.PARAMETER Recipients
    Email recipients for the reports (comma-separated).
 
.PARAMETER InputFolder
    Folder containing raw CSV license reports.
 
.PARAMETER OutputFolder
    Folder where processed reports will be stored
 
.PARAMETER SmtpServer
    SMTP server address for sending reports via email.
 
.PARAMETER ReportType
    Specifies which reports to run. Options: "Daily", "Monthly".
 
.EXAMPLE
    Invoke-CitrixReportProcessing -Recipients "user@example.com" -InputFolder "C:\Reports\Raw" -OutputFolder "C:\Reports\Processed" -SmtpServer "smtp.ppdi.com" -ReportType Daily
 
.EXAMPLE
    Invoke-CitrixReportProcessing -Recipients "user@example.com" -InputFolder "C:\Reports\Raw" -OutputFolder "C:\Reports\Processed" -SmtpServer "smtp.ppdi.com" -ReportType Monthly
 
#>

Function Invoke-CitrixReportProcessing {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [string]$Recipients,

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

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

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

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

    try {
        switch ($ReportType) {
            "Daily" {
                Write-Host "`n[INFO] Processing Daily Citrix Report..." -ForegroundColor Cyan
                Get-CitrixReport -InputFolder $InputFolder -OutputFolder $OutputFolder -ReportType Daily
                Send-CitrixLicenseReport -Recipients $Recipients -Folder $OutputFolder -SmtpServer $SmtpServer -ReportType Daily
                Write-Host "[SUCCESS] Daily report processed and emailed successfully!" -ForegroundColor Green
            }

            "Monthly" {
                Write-Host "`n[INFO] Processing Monthly Citrix Report..." -ForegroundColor Cyan
                Get-CitrixReport -InputFolder $InputFolder -OutputFolder $OutputFolder -ReportType Monthly
                Send-CitrixLicenseReport -Recipients $Recipients -Folder $OutputFolder -SmtpServer $SmtpServer -ReportType Monthly
                Write-Host "[SUCCESS] Monthly report processed and emailed successfully!" -ForegroundColor Green
            }

            default {
                Write-Host "`n[ERROR] Invalid selection. Please specify -ReportType Daily or -ReportType Monthly." -ForegroundColor Red
                return
            }
        }
    } catch {
        Write-Host "[ERROR] An error occurred: $($_.Exception.Message)" -ForegroundColor Red
    }
}