diff --git a/README.md b/README.md index b277981..f583057 100644 Binary files a/README.md and b/README.md differ diff --git a/docs/index.html b/docs/index.html index 8cea2a9..20f1530 100644 Binary files a/docs/index.html and b/docs/index.html differ diff --git a/source/Private/Merge-CISExcelAndCsvData.ps1 b/source/Private/Merge-CISExcelAndCsvData.ps1 index 7fd7cfc..0922c9b 100644 --- a/source/Private/Merge-CISExcelAndCsvData.ps1 +++ b/source/Private/Merge-CISExcelAndCsvData.ps1 @@ -1,5 +1,5 @@ function Merge-CISExcelAndCsvData { - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = 'CsvInput')] param ( [Parameter(Mandatory = $true)] [string]$ExcelPath, @@ -7,16 +7,25 @@ function Merge-CISExcelAndCsvData { [Parameter(Mandatory = $true)] [string]$WorksheetName, - [Parameter(Mandatory = $true)] - [string]$CsvPath + [Parameter(Mandatory = $true, ParameterSetName = 'CsvInput')] + [string]$CsvPath, + + [Parameter(Mandatory = $true, ParameterSetName = 'ObjectInput')] + [CISAuditResult[]]$AuditResults ) process { - # Import data from Excel and CSV + # Import data from Excel $import = Import-Excel -Path $ExcelPath -WorksheetName $WorksheetName - $csvData = Import-Csv -Path $CsvPath - # Iterate over each item in the imported Excel object and merge with CSV data + # Import data from CSV or use provided object + $csvData = if ($PSCmdlet.ParameterSetName -eq 'CsvInput') { + Import-Csv -Path $CsvPath + } else { + $AuditResults + } + + # Iterate over each item in the imported Excel object and merge with CSV data or audit results $mergedData = foreach ($item in $import) { $csvRow = $csvData | Where-Object { $_.Rec -eq $item.'recommendation #' } if ($csvRow) { @@ -29,4 +38,4 @@ function Merge-CISExcelAndCsvData { # Return the merged data return $mergedData } -} +} \ No newline at end of file diff --git a/source/Public/Sync-CISExcelAndCsvData.ps1 b/source/Public/Sync-CISExcelAndCsvData.ps1 index e07b725..4b79249 100644 --- a/source/Public/Sync-CISExcelAndCsvData.ps1 +++ b/source/Public/Sync-CISExcelAndCsvData.ps1 @@ -1,14 +1,16 @@ <# .SYNOPSIS - Synchronizes data between an Excel file and a CSV file and optionally updates the Excel worksheet. + Synchronizes data between an Excel file and either a CSV file or an output object from Invoke-M365SecurityAudit, and optionally updates the Excel worksheet. .DESCRIPTION - The Sync-CISExcelAndCsvData function merges data from a specified Excel file and a CSV file based on a common key. It can also update the Excel worksheet with the merged data. This function is particularly useful for updating Excel records with additional data from a CSV file while preserving the original formatting and structure of the Excel worksheet. + The Sync-CISExcelAndCsvData function merges data from a specified Excel file with data from either a CSV file or an output object from Invoke-M365SecurityAudit based on a common key. It can also update the Excel worksheet with the merged data. This function is particularly useful for updating Excel records with additional data from a CSV file or audit results while preserving the original formatting and structure of the Excel worksheet. .PARAMETER ExcelPath The path to the Excel file that contains the original data. This parameter is mandatory. .PARAMETER WorksheetName The name of the worksheet within the Excel file that contains the data to be synchronized. This parameter is mandatory. .PARAMETER CsvPath - The path to the CSV file containing data to be merged with the Excel data. This parameter is mandatory. + The path to the CSV file containing data to be merged with the Excel data. This parameter is mandatory when using the CsvInput parameter set. + .PARAMETER AuditResults + An array of CISAuditResult objects from Invoke-M365SecurityAudit to be merged with the Excel data. This parameter is mandatory when using the ObjectInput parameter set. .PARAMETER SkipUpdate If specified, the function will return the merged data object without updating the Excel worksheet. This is useful for previewing the merged data. .EXAMPLE @@ -17,6 +19,14 @@ .EXAMPLE PS> $mergedData = Sync-CISExcelAndCsvData -ExcelPath "path\to\excel.xlsx" -WorksheetName "DataSheet" -CsvPath "path\to\data.csv" -SkipUpdate Retrieves the merged data object for preview without updating the Excel worksheet. + .EXAMPLE + PS> $auditResults = Invoke-M365SecurityAudit -TenantAdminUrl "https://tenant-admin.url" -DomainName "example.com" + PS> Sync-CISExcelAndCsvData -ExcelPath "path\to\excel.xlsx" -WorksheetName "DataSheet" -AuditResults $auditResults + Merges data from the audit results into 'excel.xlsx' on the 'DataSheet' worksheet and updates the worksheet with the merged data. + .EXAMPLE + PS> $auditResults = Invoke-M365SecurityAudit -TenantAdminUrl "https://tenant-admin.url" -DomainName "example.com" + PS> $mergedData = Sync-CISExcelAndCsvData -ExcelPath "path\to\excel.xlsx" -WorksheetName "DataSheet" -AuditResults $auditResults -SkipUpdate + Retrieves the merged data object for preview without updating the Excel worksheet. .INPUTS None. You cannot pipe objects to Sync-CISExcelAndCsvData. .OUTPUTS @@ -30,8 +40,9 @@ https://criticalsolutionsnetwork.github.io/M365FoundationsCISReport/#Sync-CISExcelAndCsvData #> + function Sync-CISExcelAndCsvData { - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = 'CsvInput')] param ( [Parameter(Mandatory = $true)] [ValidateScript({ Test-Path $_ })] @@ -40,10 +51,13 @@ function Sync-CISExcelAndCsvData { [Parameter(Mandatory = $true)] [string]$WorksheetName, - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true, ParameterSetName = 'CsvInput')] [ValidateScript({ Test-Path $_ })] [string]$CsvPath, + [Parameter(Mandatory = $true, ParameterSetName = 'ObjectInput')] + [CISAuditResult[]]$AuditResults, + [Parameter(Mandatory = $false)] [switch]$SkipUpdate ) @@ -55,8 +69,12 @@ function Sync-CISExcelAndCsvData { Assert-ModuleAvailability -ModuleName $module.ModuleName -RequiredVersion $module.RequiredVersion -SubModuleName $module.SubModuleName } - # Merge Excel and CSV data - $mergedData = Merge-CISExcelAndCsvData -ExcelPath $ExcelPath -WorksheetName $WorksheetName -CsvPath $CsvPath + # Merge Excel and CSV data or Audit Results + if ($PSCmdlet.ParameterSetName -eq 'CsvInput') { + $mergedData = Merge-CISExcelAndCsvData -ExcelPath $ExcelPath -WorksheetName $WorksheetName -CsvPath $CsvPath + } else { + $mergedData = Merge-CISExcelAndCsvData -ExcelPath $ExcelPath -WorksheetName $WorksheetName -AuditResults $AuditResults + } # Output the merged data if the user chooses to skip the update if ($SkipUpdate) { @@ -68,3 +86,4 @@ function Sync-CISExcelAndCsvData { } } +