src/Private/Report/Core/Get-MCSAssessmentFile.ps1
|
function Get-MCSAssessmentFile { Param( $CSVFile, $ExcelFile, $Debug ) if ($Debug.IsPresent) { $DebugPreference = "Continue" } else { $DebugPreference = "SilentlyContinue" } if ($ExcelFile) { Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'Excel file provided') $Assessment = Import-Excel -Path $ExcelFile $CSVFile = @() $CSVFile =foreach ($Resource in $Assessment) { switch (($Resource.'RiskID')[0]) { 'C' {$Priority = 'Critical'} 'H' {$Priority = 'High'} 'M' {$Priority = 'Medium'} 'L' {$Priority = 'Low'} default {$Priority = 'Unknown'} } $CSV = [PSCustomObject]@{ 'Recommendation Guid' = $Resource.'RuleName' 'Recommendation Title' = $Resource.'Synopsis' 'Description' = $Resource.'Recommendation' 'Priority' = $Priority 'Customer-facing annotation' = '' 'Internal-facing notes' = '' 'Potential Benefit' = '' 'Resource Type' = $Resource.'Resource Type' 'Resource ID' = 'Microsoft.Subscription/Subscriptions' } $CSV } $CSVFile = Convert-ExcelToCSV -ExcelFile $ExcelFile -Debug:$Debug } elseif ($CSVFile) { Write-Debug ((get-date -Format 'yyyy-MM-dd HH_mm_ss')+' - '+'CSV file provided, using it directly: ' + $CSVFile) $CSVFile = Import-Csv -Path $CSVFile } else { Write-Host "Error: No input file provided. Please provide either a CSV or Excel file." -ForegroundColor Red exit 1 } return $CSVFile } |