Skip to content

A comprehensive Windows security auditing and threat detection toolkit. Features 58 production-ready PowerShell functions organized into 14 modules for enterprise-grade security assessment, compliance validation, and incident response.

PowerShell

v1.6.2 #9: all remaining CSV exports escape formula injection via ConvertTo-CsvSafeObject (23 sites); helper added to Private/ExportHelpers.ps1 with Pester coverage

Okan YILDIZc90b61a77543
diff --git a/CloudSecurity/Get-CloudComplianceStatus.ps1 b/CloudSecurity/Get-CloudComplianceStatus.ps1
index 183417c..6a83558 100644
--- a/CloudSecurity/Get-CloudComplianceStatus.ps1
+++ b/CloudSecurity/Get-CloudComplianceStatus.ps1
@@ -175,7 +175,7 @@ function Get-CloudComplianceStatus {
if ($Format -in @('CSV', 'All')) {
$csvPath = Join-Path $ExportPath "Compliance_${Framework}_$timestamp.csv"
- $results.Controls | Export-Csv $csvPath -NoTypeInformation
+ $results.Controls | ConvertTo-CsvSafeObject | Export-Csv $csvPath -NoTypeInformation
Write-Host "Exported CSV: $csvPath" -ForegroundColor Green
}
diff --git a/CloudSecurity/Test-M365SecurityPosture.ps1 b/CloudSecurity/Test-M365SecurityPosture.ps1
index 9ce9dde..c16f16c 100644
--- a/CloudSecurity/Test-M365SecurityPosture.ps1
+++ b/CloudSecurity/Test-M365SecurityPosture.ps1
@@ -306,7 +306,7 @@ function Test-M365SecurityPosture {
if ($Format -in @('CSV', 'All')) {
$csvPath = Join-Path $ExportPath "M365Security_$timestamp.csv"
- $results.SecurityFindings | Export-Csv $csvPath -NoTypeInformation
+ $results.SecurityFindings | ConvertTo-CsvSafeObject | Export-Csv $csvPath -NoTypeInformation
Write-Host "Exported CSV: $csvPath" -ForegroundColor Green
}
diff --git a/Compliance/Export-ComplianceEvidence.ps1 b/Compliance/Export-ComplianceEvidence.ps1
index 654d488..2b1d699 100644
--- a/Compliance/Export-ComplianceEvidence.ps1
+++ b/Compliance/Export-ComplianceEvidence.ps1
@@ -129,7 +129,7 @@ function Export-ComplianceEvidence {
Write-Host " Exporting firewall rules..." -ForegroundColor Gray
$fwPath = Join-Path $directories.Configuration "FirewallRules.csv"
Get-NetFirewallRule | Select-Object Name, DisplayName, Enabled, Direction, Action, Profile |
- Export-Csv $fwPath -NoTypeInformation
+ ConvertTo-CsvSafeObject | Export-Csv $fwPath -NoTypeInformation
$manifest.CollectedFiles += "01_Configuration\FirewallRules.csv"
$hash = (Get-FileHash $fwPath -Algorithm SHA256).Hash
@@ -224,7 +224,7 @@ function Export-ComplianceEvidence {
if ($failedLogons) {
$logonPath = Join-Path $directories.Logs "FailedLogons.csv"
$failedLogons | Select-Object TimeCreated, Id, Message |
- Export-Csv $logonPath -NoTypeInformation
+ ConvertTo-CsvSafeObject | Export-Csv $logonPath -NoTypeInformation
$manifest.CollectedFiles += "02_Logs\FailedLogons.csv"
}
@@ -238,7 +238,7 @@ function Export-ComplianceEvidence {
if ($psLogs) {
$psPath = Join-Path $directories.Logs "PowerShellLogs.csv"
$psLogs | Select-Object TimeCreated, Id, LevelDisplayName, Message |
- Export-Csv $psPath -NoTypeInformation
+ ConvertTo-CsvSafeObject | Export-Csv $psPath -NoTypeInformation
$manifest.CollectedFiles += "02_Logs\PowerShellLogs.csv"
}
@@ -305,14 +305,14 @@ function Export-ComplianceEvidence {
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Where-Object { $_.DisplayName } |
- Export-Csv $softwarePath -NoTypeInformation
+ ConvertTo-CsvSafeObject | Export-Csv $softwarePath -NoTypeInformation
$manifest.CollectedFiles += "04_SystemInfo\InstalledSoftware.csv"
# Local Users
Write-Host " Collecting local users information..." -ForegroundColor Gray
$usersPath = Join-Path $directories.SystemInfo "LocalUsers.csv"
Get-LocalUser | Select-Object Name, Enabled, LastLogon, PasswordLastSet, PasswordExpires |
- Export-Csv $usersPath -NoTypeInformation
+ ConvertTo-CsvSafeObject | Export-Csv $usersPath -NoTypeInformation
$manifest.CollectedFiles += "04_SystemInfo\LocalUsers.csv"
# Local Groups - FIXED: Proper error handling with foreach
@@ -339,7 +339,7 @@ function Export-ComplianceEvidence {
}
if ($groupData.Count -gt 0) {
- $groupData | Export-Csv $groupsPath -NoTypeInformation
+ $groupData | ConvertTo-CsvSafeObject | Export-Csv $groupsPath -NoTypeInformation
$manifest.CollectedFiles += "04_SystemInfo\LocalGroups.csv"
}
@@ -353,7 +353,7 @@ function Export-ComplianceEvidence {
Write-Host " Collecting services list..." -ForegroundColor Gray
$servicesPath = Join-Path $directories.SystemInfo "Services.csv"
Get-Service | Select-Object Name, DisplayName, Status, StartType |
- Export-Csv $servicesPath -NoTypeInformation
+ ConvertTo-CsvSafeObject | Export-Csv $servicesPath -NoTypeInformation
$manifest.CollectedFiles += "04_SystemInfo\Services.csv"
# Windows Updates
@@ -374,7 +374,7 @@ function Export-ComplianceEvidence {
4 { 'Failed' }
5 { 'Aborted' }
}
- }} | Export-Csv $updatesPath -NoTypeInformation
+ }} | ConvertTo-CsvSafeObject | Export-Csv $updatesPath -NoTypeInformation
$manifest.CollectedFiles += "04_SystemInfo\WindowsUpdates.csv"
}
}
diff --git a/Core/Compare-SecurityBaseline.ps1 b/Core/Compare-SecurityBaseline.ps1
index aeebda5..c27391d 100644
--- a/Core/Compare-SecurityBaseline.ps1
+++ b/Core/Compare-SecurityBaseline.ps1
@@ -312,7 +312,7 @@ function Compare-SecurityBaseline {
$csvFile = Join-Path -Path $OutputPath -ChildPath "CompareChanges_$timestamp.csv"
$result | ConvertTo-Json -Depth 10 | Out-File -FilePath $jsonFile -Encoding UTF8
- $changes | Export-Csv -Path $csvFile -NoTypeInformation -Encoding UTF8
+ $changes | ConvertTo-CsvSafeObject | Export-Csv -Path $csvFile -NoTypeInformation -Encoding UTF8
Write-Host "Results exported to: $jsonFile" -ForegroundColor Green
Write-Host "Changes exported to: $csvFile" -ForegroundColor Green
diff --git a/Enterprise/Get-MultiSystemAudit.ps1 b/Enterprise/Get-MultiSystemAudit.ps1
index b5c907d..4acf2de 100644
--- a/Enterprise/Get-MultiSystemAudit.ps1
+++ b/Enterprise/Get-MultiSystemAudit.ps1
@@ -445,7 +445,7 @@ function Get-MultiSystemAudit {
# Export system summary
$auditResults.SystemAudits | Select-Object ComputerName, Status, SecurityScore, SecurityLevel, @{N='FindingsCount';E={$_.Findings.Count}} |
- Export-Csv (Join-Path $OutputPath "SystemSummary.csv") -NoTypeInformation
+ ConvertTo-CsvSafeObject | Export-Csv (Join-Path $OutputPath "SystemSummary.csv") -NoTypeInformation
# Export all findings
$allFindings = @($auditResults.SystemAudits | ForEach-Object {
@@ -454,7 +454,7 @@ function Get-MultiSystemAudit {
})
if ($allFindings.Count -gt 0) {
- $allFindings | Export-Csv (Join-Path $OutputPath "AllFindings.csv") -NoTypeInformation
+ $allFindings | ConvertTo-CsvSafeObject | Export-Csv (Join-Path $OutputPath "AllFindings.csv") -NoTypeInformation
}
# Generate HTML report if requested
diff --git a/Enterprise/Invoke-EnterpriseSecurityScan.ps1 b/Enterprise/Invoke-EnterpriseSecurityScan.ps1
index f712257..6e921e4 100644
--- a/Enterprise/Invoke-EnterpriseSecurityScan.ps1
+++ b/Enterprise/Invoke-EnterpriseSecurityScan.ps1
@@ -906,7 +906,7 @@ function Invoke-EnterpriseSecurityScan {
# Create CSV summary
$results.SystemResults | Select-Object ComputerName, Status, SecurityScore, @{N='FindingsCount';E={$_.Findings.Count}} |
- Export-Csv (Join-Path $OutputPath "EnterpriseScan_Summary.csv") -NoTypeInformation
+ ConvertTo-CsvSafeObject | Export-Csv (Join-Path $OutputPath "EnterpriseScan_Summary.csv") -NoTypeInformation
# Export detailed findings
$allFindings = @($results.SystemResults | ForEach-Object {
@@ -915,7 +915,7 @@ function Invoke-EnterpriseSecurityScan {
})
if ($allFindings.Count -gt 0) {
- $allFindings | Export-Csv (Join-Path $OutputPath "EnterpriseScan_Findings.csv") -NoTypeInformation
+ $allFindings | ConvertTo-CsvSafeObject | Export-Csv (Join-Path $OutputPath "EnterpriseScan_Findings.csv") -NoTypeInformation
}
Write-Host "`nResults saved to: $OutputPath" -ForegroundColor Cyan
diff --git a/Enterprise/Invoke-SecurityAssessment.ps1 b/Enterprise/Invoke-SecurityAssessment.ps1
index bcd623d..b549bb5 100644
--- a/Enterprise/Invoke-SecurityAssessment.ps1
+++ b/Enterprise/Invoke-SecurityAssessment.ps1
@@ -1155,7 +1155,7 @@ foreach ($categoryName in $assessment.Categories.Keys) {
# Export findings
if ($assessment.Findings.Count -gt 0) {
- $assessment.Findings | Export-Csv (Join-Path $OutputPath "SecurityFindings.csv") -NoTypeInformation
+ $assessment.Findings | ConvertTo-CsvSafeObject | Export-Csv (Join-Path $OutputPath "SecurityFindings.csv") -NoTypeInformation
}
# Export recommendations
diff --git a/Private/ExportHelpers.ps1 b/Private/ExportHelpers.ps1
index 2e346d9..2c9dee4 100644
--- a/Private/ExportHelpers.ps1
+++ b/Private/ExportHelpers.ps1
@@ -29,6 +29,20 @@ function Protect-CsvField {
return $text
}
+function ConvertTo-CsvSafeObject {
+ [CmdletBinding()]
+ param([Parameter(ValueFromPipeline = $true)][AllowNull()][object]$InputObject)
+ process {
+ if ($null -eq $InputObject) { return }
+ $row = [ordered]@{}
+ foreach ($property in $InputObject.PSObject.Properties) {
+ $value = $property.Value
+ $row[$property.Name] = if ($value -is [string]) { Protect-CsvField $value } else { $value }
+ }
+ [PSCustomObject]$row
+ }
+}
+
function ConvertTo-HtmlEncoded {
[CmdletBinding()]
[OutputType([string])]
diff --git a/Response/Export-SecurityReport.ps1 b/Response/Export-SecurityReport.ps1
index 74986e4..e08d899 100644
--- a/Response/Export-SecurityReport.ps1
+++ b/Response/Export-SecurityReport.ps1
@@ -284,7 +284,7 @@ if ($highSeverityProcs.Count -gt 0) {
if ($Format -in @('CSV', 'All')) {
Write-Host "Generating CSV reports..." -ForegroundColor Yellow
$csvPath = Join-Path $OutputPath "${reportBaseName}_Findings.csv"
- $reportData.Findings | Export-Csv $csvPath -NoTypeInformation
+ $reportData.Findings | ConvertTo-CsvSafeObject | Export-Csv $csvPath -NoTypeInformation
$generatedFiles += $csvPath
}
diff --git a/Vulnerability/Find-EOLSoftware.ps1 b/Vulnerability/Find-EOLSoftware.ps1
index dac3781..08b0c6d 100644
--- a/Vulnerability/Find-EOLSoftware.ps1
+++ b/Vulnerability/Find-EOLSoftware.ps1
@@ -371,7 +371,7 @@ function Find-EOLSoftware {
if ($Format -in @('CSV', 'All')) {
$csvPath = Join-Path $OutputPath "$reportName.csv"
$allFindings = $findings.EOLSoftware + $findings.ExpiringSoon
- $allFindings | Export-Csv $csvPath -NoTypeInformation
+ $allFindings | ConvertTo-CsvSafeObject | Export-Csv $csvPath -NoTypeInformation
Write-Host " CSV report saved: $csvPath" -ForegroundColor Green
}
diff --git a/Vulnerability/Get-ExposedServices.ps1 b/Vulnerability/Get-ExposedServices.ps1
index c717193..586c786 100644
--- a/Vulnerability/Get-ExposedServices.ps1
+++ b/Vulnerability/Get-ExposedServices.ps1
@@ -329,7 +329,7 @@ function Get-ExposedServices {
# Export CSV
if ($Format -in @('CSV', 'All')) {
$csvPath = Join-Path $OutputPath "$reportName.csv"
- $findings.ExposedServices | Export-Csv $csvPath -NoTypeInformation
+ $findings.ExposedServices | ConvertTo-CsvSafeObject | Export-Csv $csvPath -NoTypeInformation
Write-Host " CSV report saved: $csvPath" -ForegroundColor Green
}
diff --git a/Vulnerability/Get-SecurityMisconfigurations.ps1 b/Vulnerability/Get-SecurityMisconfigurations.ps1
index 90fc31b..fda2a1f 100644
--- a/Vulnerability/Get-SecurityMisconfigurations.ps1
+++ b/Vulnerability/Get-SecurityMisconfigurations.ps1
@@ -556,7 +556,7 @@ function Get-SecurityMisconfigurations {
# Export CSV
if ($Format -in @('CSV', 'All')) {
$csvPath = Join-Path $OutputPath "$reportName.csv"
- $findings.Misconfigurations | Export-Csv $csvPath -NoTypeInformation
+ $findings.Misconfigurations | ConvertTo-CsvSafeObject | Export-Csv $csvPath -NoTypeInformation
Write-Host " CSV report saved: $csvPath" -ForegroundColor Green
}
diff --git a/Vulnerability/Get-VulnerabilityAssessment.ps1 b/Vulnerability/Get-VulnerabilityAssessment.ps1
index 16ccddd..8b6c39d 100644
--- a/Vulnerability/Get-VulnerabilityAssessment.ps1
+++ b/Vulnerability/Get-VulnerabilityAssessment.ps1
@@ -511,7 +511,7 @@ function Get-VulnerabilityAssessment {
# Export CSV (Vulnerabilities)
if ($Format -in @('CSV', 'All')) {
$csvPath = Join-Path $OutputPath "$reportName.csv"
- $assessment.Vulnerabilities | Export-Csv $csvPath -NoTypeInformation
+ $assessment.Vulnerabilities | ConvertTo-CsvSafeObject | Export-Csv $csvPath -NoTypeInformation
Write-Host " CSV report saved: $csvPath" -ForegroundColor Green
}
diff --git a/Vulnerability/Test-CertificateHealth.ps1 b/Vulnerability/Test-CertificateHealth.ps1
index e79138a..b13950d 100644
--- a/Vulnerability/Test-CertificateHealth.ps1
+++ b/Vulnerability/Test-CertificateHealth.ps1
@@ -386,7 +386,7 @@ function Test-CertificateHealth {
# Export CSV
if ($Format -in @('CSV', 'All')) {
$csvPath = Join-Path $OutputPath "$reportName.csv"
- $results.Issues | Export-Csv $csvPath -NoTypeInformation
+ $results.Issues | ConvertTo-CsvSafeObject | Export-Csv $csvPath -NoTypeInformation
Write-Host " CSV report saved: $csvPath" -ForegroundColor Green
}
diff --git a/Vulnerability/Test-PatchCompliance.ps1 b/Vulnerability/Test-PatchCompliance.ps1
index 735a1a1..fd43339 100644
--- a/Vulnerability/Test-PatchCompliance.ps1
+++ b/Vulnerability/Test-PatchCompliance.ps1
@@ -331,7 +331,7 @@ function Test-PatchCompliance {
# Export CSV (Missing Updates)
if ($Format -in @('CSV', 'All')) {
$csvPath = Join-Path $OutputPath "$reportName.csv"
- $compliance.MissingUpdates | Export-Csv $csvPath -NoTypeInformation
+ $compliance.MissingUpdates | ConvertTo-CsvSafeObject | Export-Csv $csvPath -NoTypeInformation
Write-Host " CSV report saved: $csvPath" -ForegroundColor Green
}