@@ -115,6 +115,18 @@ function LogScriptInfo {
115115 Value = ($ValidatedIdentities -join ' ; ' )
116116 })
117117
118+ if ($script :SubjectSearch ) {
119+ $RunInfo.Add ([PSCustomObject ]@ {
120+ Key = " Collection Method"
121+ Value = " Subject search (no Exception or Tracking Log data). Use -MeetingID for full collection."
122+ })
123+ } else {
124+ $RunInfo.Add ([PSCustomObject ]@ {
125+ Key = " Collection Method"
126+ Value = " MeetingID"
127+ })
128+ }
129+
118130 # Only log environment info on the first run
119131 if ($script :RunNumber -eq 1 ) {
120132 $RunInfo.Add ([PSCustomObject ]@ {
@@ -172,33 +184,46 @@ function LogScriptInfo {
172184 # Update snapshot so next identity only captures new errors
173185 $script :PreRunErrorCount = $Error.Count
174186
175- # Append to the existing Script Info tab (skip -Append on first write when the tab doesn't exist yet )
187+ # Write Script Info into the existing workbook (Enhanced tab was already saved )
176188 $savedEAP = $ErrorActionPreference
177189 $ErrorActionPreference = ' SilentlyContinue'
178- $appendToSheet = $false
179- if (Test-Path $FileName ) {
180- try {
181- $testPkg = Open-ExcelPackage - Path $FileName - ErrorAction SilentlyContinue
182- if ($null -ne $testPkg -and $null -ne $testPkg.Workbook.Worksheets [" Script Info" ]) {
183- $appendToSheet = $true
184- }
185- if ($null -ne $testPkg ) { $testPkg.Dispose () }
186- } catch {
187- Write-Verbose " Unable to check for existing Script Info tab: $_ "
190+
191+ # Open existing package and add/append the Script Info sheet
192+ try {
193+ $pkg = Open-ExcelPackage - Path $FileName - ErrorAction Stop
194+ $sheetExists = $null -ne $pkg.Workbook.Worksheets [" Script Info" ]
195+
196+ if ($sheetExists ) {
197+ # Append rows after existing data
198+ $ws = $pkg.Workbook.Worksheets [" Script Info" ]
199+ $startRow = $ws.Dimension.End.Row + 1
200+ } else {
201+ # Create a new sheet
202+ $ws = $pkg.Workbook.Worksheets.Add (" Script Info" )
203+ $startRow = 1
204+ # Add header row
205+ $ws.Cells [$startRow , 1 ].Value = " Key"
206+ $ws.Cells [$startRow , 2 ].Value = " Value"
207+ $startRow = 2
188208 }
189- }
190209
191- if ($appendToSheet ) {
192- $infoExcel = $RunInfo | Export-Excel - Path $FileName - WorksheetName " Script Info" - Append - PassThru 3> $null
193- } else {
194- $infoExcel = $RunInfo | Export-Excel - Path $FileName - WorksheetName " Script Info" - PassThru 3> $null
195- }
196- $ErrorActionPreference = $savedEAP
210+ foreach ($item in $RunInfo ) {
211+ $ws.Cells [$startRow , 1 ].Value = $item.Key
212+ $ws.Cells [$startRow , 2 ].Value = [string ]$item.Value
213+ $startRow ++
214+ }
197215
198- if ($null -ne $infoExcel ) {
199- $infoExcel.Workbook.Worksheets [" Script Info" ].TabColor = [System.Drawing.Color ]::Gray
200- Export-Excel - ExcelPackage $infoExcel - WorksheetName " Script Info"
216+ $ws.Column (1 ).Width = 25
217+ $ws.Column (2 ).Width = 80
218+ $ws.TabColor = [System.Drawing.Color ]::Gray
219+ $pkg.Save ()
220+ $pkg.Dispose ()
221+ } catch {
222+ Write-Warning " Unable to write Script Info tab: $_ "
223+ if ($null -ne $pkg ) { $pkg.Dispose () }
201224 }
225+
226+ $ErrorActionPreference = $savedEAP
202227}
203228
204229function Export-TimelineExcel {
@@ -232,6 +257,10 @@ function GetExcelParams($path, $tabName) {
232257 $script :TabColor = [System.Drawing.Color ]::FromArgb(255 , 0 , 0 ) # Red for Disabled CalLogs
233258 }
234259
260+ if ($script :SubjectSearch ) {
261+ $TitleExtra += " , Collected with Subject search (no Exception info)"
262+ }
263+
235264 $script :lastRow = $script :GCDO.Count + $firstRow - 1 # Last row is the number of items in the GCDO array + 2 for the header and title rows.
236265 Write-Host - ForegroundColor Gray " Last Row is $lastRow , First Row is $firstRow , Last Column is $lastColumn "
237266
0 commit comments