Skip to content

Commit

Permalink
docs:update help
Browse files Browse the repository at this point in the history
  • Loading branch information
DrIOSX committed Jun 8, 2024
1 parent 7a9d288 commit ef55447
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
Binary file modified README.md
Binary file not shown.
Binary file modified docs/index.html
Binary file not shown.
23 changes: 16 additions & 7 deletions source/Private/Merge-CISExcelAndCsvData.ps1
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
function Merge-CISExcelAndCsvData {
[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName = 'CsvInput')]
param (
[Parameter(Mandatory = $true)]
[string]$ExcelPath,

[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) {
Expand All @@ -29,4 +38,4 @@ function Merge-CISExcelAndCsvData {
# Return the merged data
return $mergedData
}
}
}
33 changes: 26 additions & 7 deletions source/Public/Sync-CISExcelAndCsvData.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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 $_ })]
Expand All @@ -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
)
Expand All @@ -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) {
Expand All @@ -68,3 +86,4 @@ function Sync-CISExcelAndCsvData {
}
}


0 comments on commit ef55447

Please sign in to comment.