File tree Expand file tree Collapse file tree 1 file changed +3
-25
lines changed Expand file tree Collapse file tree 1 file changed +3
-25
lines changed Original file line number Diff line number Diff line change @@ -162,31 +162,9 @@ try {
162
162
}
163
163
164
164
$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
190
168
}
191
169
}
192
170
catch {
You can’t perform that action at this time.
0 commit comments