docs:update help

This commit is contained in:
DrIOS
2024-06-08 14:03:55 -05:00
parent 7a9d2885f3
commit ef55447e67
4 changed files with 42 additions and 14 deletions

BIN
README.md

Binary file not shown.

Binary file not shown.

View File

@@ -1,5 +1,5 @@
function Merge-CISExcelAndCsvData { function Merge-CISExcelAndCsvData {
[CmdletBinding()] [CmdletBinding(DefaultParameterSetName = 'CsvInput')]
param ( param (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$ExcelPath, [string]$ExcelPath,
@@ -7,16 +7,25 @@ function Merge-CISExcelAndCsvData {
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$WorksheetName, [string]$WorksheetName,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true, ParameterSetName = 'CsvInput')]
[string]$CsvPath [string]$CsvPath,
[Parameter(Mandatory = $true, ParameterSetName = 'ObjectInput')]
[CISAuditResult[]]$AuditResults
) )
process { process {
# Import data from Excel and CSV # Import data from Excel
$import = Import-Excel -Path $ExcelPath -WorksheetName $WorksheetName $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) { $mergedData = foreach ($item in $import) {
$csvRow = $csvData | Where-Object { $_.Rec -eq $item.'recommendation #' } $csvRow = $csvData | Where-Object { $_.Rec -eq $item.'recommendation #' }
if ($csvRow) { if ($csvRow) {
@@ -29,4 +38,4 @@ function Merge-CISExcelAndCsvData {
# Return the merged data # Return the merged data
return $mergedData return $mergedData
} }
} }

View File

@@ -1,14 +1,16 @@
<# <#
.SYNOPSIS .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 .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 .PARAMETER ExcelPath
The path to the Excel file that contains the original data. This parameter is mandatory. The path to the Excel file that contains the original data. This parameter is mandatory.
.PARAMETER WorksheetName .PARAMETER WorksheetName
The name of the worksheet within the Excel file that contains the data to be synchronized. This parameter is mandatory. The name of the worksheet within the Excel file that contains the data to be synchronized. This parameter is mandatory.
.PARAMETER CsvPath .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 .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. If specified, the function will return the merged data object without updating the Excel worksheet. This is useful for previewing the merged data.
.EXAMPLE .EXAMPLE
@@ -17,6 +19,14 @@
.EXAMPLE .EXAMPLE
PS> $mergedData = Sync-CISExcelAndCsvData -ExcelPath "path\to\excel.xlsx" -WorksheetName "DataSheet" -CsvPath "path\to\data.csv" -SkipUpdate 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. 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 .INPUTS
None. You cannot pipe objects to Sync-CISExcelAndCsvData. None. You cannot pipe objects to Sync-CISExcelAndCsvData.
.OUTPUTS .OUTPUTS
@@ -30,8 +40,9 @@
https://criticalsolutionsnetwork.github.io/M365FoundationsCISReport/#Sync-CISExcelAndCsvData https://criticalsolutionsnetwork.github.io/M365FoundationsCISReport/#Sync-CISExcelAndCsvData
#> #>
function Sync-CISExcelAndCsvData { function Sync-CISExcelAndCsvData {
[CmdletBinding()] [CmdletBinding(DefaultParameterSetName = 'CsvInput')]
param ( param (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[ValidateScript({ Test-Path $_ })] [ValidateScript({ Test-Path $_ })]
@@ -40,10 +51,13 @@ function Sync-CISExcelAndCsvData {
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$WorksheetName, [string]$WorksheetName,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true, ParameterSetName = 'CsvInput')]
[ValidateScript({ Test-Path $_ })] [ValidateScript({ Test-Path $_ })]
[string]$CsvPath, [string]$CsvPath,
[Parameter(Mandatory = $true, ParameterSetName = 'ObjectInput')]
[CISAuditResult[]]$AuditResults,
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[switch]$SkipUpdate [switch]$SkipUpdate
) )
@@ -55,8 +69,12 @@ function Sync-CISExcelAndCsvData {
Assert-ModuleAvailability -ModuleName $module.ModuleName -RequiredVersion $module.RequiredVersion -SubModuleName $module.SubModuleName Assert-ModuleAvailability -ModuleName $module.ModuleName -RequiredVersion $module.RequiredVersion -SubModuleName $module.SubModuleName
} }
# Merge Excel and CSV data # Merge Excel and CSV data or Audit Results
$mergedData = Merge-CISExcelAndCsvData -ExcelPath $ExcelPath -WorksheetName $WorksheetName -CsvPath $CsvPath 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 # Output the merged data if the user chooses to skip the update
if ($SkipUpdate) { if ($SkipUpdate) {
@@ -68,3 +86,4 @@ function Sync-CISExcelAndCsvData {
} }
} }