Skip to content

Commit 8a494f0

Browse files
committed
Remove redundant code
1 parent 1ecb123 commit 8a494f0

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

utilities/ExtractScriptBlockLogging.ps1

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -162,31 +162,9 @@ try {
162162
}
163163

164164
$Results = $Results | Sort-Object -Property TimeCreated -Descending
165-
if ($Results.Count -eq 0) {
166-
Write-Warning "No Script Block Logging events were found for the specified time period."
167-
return
168-
}
169-
170-
try {
171-
$Results | Export-Csv -Path $OutputFile -NoTypeInformation -ErrorAction Stop
172-
}
173-
catch {
174-
Write-Warning "Standard CSV export failed, trying alternative method."
175-
$Header = ($Results[0].PSObject.Properties.Name -join ',')
176-
$Output = @()
177-
$Output += $Header
178-
179-
foreach ($Row in $Results) {
180-
$Line = @()
181-
foreach ($Property in $Row.PSObject.Properties) {
182-
# Quote and escape each value
183-
$Value = if ($null -eq $Property.Value) { '""' } else { '"' + ($Property.Value -replace '"', '""') + '"' }
184-
$Line += $Value
185-
}
186-
$Output += ($Line -join ',')
187-
}
188-
189-
$Output | Out-File -FilePath $OutputFile -Encoding utf8 -Force
165+
166+
if ($Results.Count -ne 0) {
167+
$Results | Select-Object * | Export-Csv -Path $OutputFile -NoTypeInformation
190168
}
191169
}
192170
catch {

0 commit comments

Comments
 (0)