Skip to content

Commit 3466118

Browse files
committed
Fixing PR comments
1 parent 6472848 commit 3466118

2 files changed

Lines changed: 66 additions & 48 deletions

File tree

Calendar/CalLogHelpers/CalLogCSVFunctions.ps1

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,25 @@ function CreateExternalMasterIDMap {
108108

109109
$AllFolderNames = @($script:GCDO | Where-Object { $_.ExternalSharingMasterId -eq $ExternalID } | Select-Object -ExpandProperty OriginalParentDisplayName | Select-Object -Unique)
110110

111-
# Remove empty/null and 'Calendar' (the default folder name) entries
111+
# Default calendar folder names across the top localized versions of Exchange
112+
$DefaultCalendarNames = [System.Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
113+
[void]$DefaultCalendarNames.Add('Calendar') # English
114+
[void]$DefaultCalendarNames.Add('Kalender') # German, Dutch, Swedish, Norwegian, Danish
115+
[void]$DefaultCalendarNames.Add('Calendario') # Spanish, Italian
116+
[void]$DefaultCalendarNames.Add('Calendrier') # French
117+
[void]$DefaultCalendarNames.Add('Calendário') # Portuguese
118+
[void]$DefaultCalendarNames.Add('Календарь') # Russian
119+
120+
# Remove empty/null entries
112121
$AllFolderNames = @($AllFolderNames | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
113122

114123
if ($AllFolderNames.count -gt 1) {
115-
# We have 2+ FolderNames, remove only exact match to 'Calendar' (the default folder name, not folder names containing 'Calendar')
116-
$Filtered = $AllFolderNames | Where-Object { $_ -ne 'Calendar' }
124+
# We have 2+ FolderNames, remove default calendar folder names (localized) by exact match
125+
$Filtered = $AllFolderNames | Where-Object { -not $DefaultCalendarNames.Contains($_) }
117126
if ($Filtered.Count -gt 0) {
118127
$AllFolderNames = @($Filtered)
119128
}
120-
# else keep the original list — all entries were 'Calendar'
129+
# else keep the original list — all entries were default calendar names
121130
}
122131

123132
if ($AllFolderNames.Count -eq 0) {

Calendar/CalLogHelpers/ExportToExcelFunctions.ps1

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ function Export-CalLogExcel {
1313
# Suppress EPPlus warnings and errors that occur when writing to an existing file
1414
# (AutoNameRange validation, named range conflicts, title character warnings)
1515
$savedErrorActionPreference = $ErrorActionPreference
16-
$ErrorActionPreference = 'SilentlyContinue'
17-
18-
$excel = $GCDOResults | Export-Excel @ExcelParamsArray -PassThru 3>$null
19-
20-
$ErrorActionPreference = $savedErrorActionPreference
16+
try {
17+
$ErrorActionPreference = 'SilentlyContinue'
18+
$excel = $GCDOResults | Export-Excel @ExcelParamsArray -PassThru 3>$null
19+
} finally {
20+
$ErrorActionPreference = $savedErrorActionPreference
21+
}
2122

2223
FormatHeader ($excel)
2324
SortByLogTimestamp ($excel)
@@ -33,9 +34,12 @@ function Export-CalLogExcel {
3334

3435
# Export Raw Logs for Developer Analysis
3536
Write-Host -ForegroundColor Cyan "Exporting Raw CalLogs to Excel Tab [$($ShortId + "_Raw")]..."
36-
$ErrorActionPreference = 'SilentlyContinue'
37-
$rawExcel = $script:GCDO | Export-Excel -Path $FileName -WorksheetName $($ShortId + "_Raw") -AutoFilter -FreezeTopRow -BoldTopRow -MoveToEnd -PassThru 3>$null
38-
$ErrorActionPreference = $savedErrorActionPreference
37+
try {
38+
$ErrorActionPreference = 'SilentlyContinue'
39+
$rawExcel = $script:GCDO | Export-Excel -Path $FileName -WorksheetName $($ShortId + "_Raw") -AutoFilter -FreezeTopRow -BoldTopRow -MoveToEnd -PassThru 3>$null
40+
} finally {
41+
$ErrorActionPreference = $savedErrorActionPreference
42+
}
3943
$rawExcel.Workbook.Worksheets[$ShortId + "_Raw"].TabColor = $script:TabColor
4044
Export-Excel -ExcelPackage $rawExcel -WorksheetName $($ShortId + "_Raw")
4145
}
@@ -186,52 +190,57 @@ function LogScriptInfo {
186190

187191
# Write Script Info into the existing workbook (Enhanced tab was already saved)
188192
$savedEAP = $ErrorActionPreference
189-
$ErrorActionPreference = 'SilentlyContinue'
190-
191-
# Open existing package and add/append the Script Info sheet
192193
try {
193-
$pkg = Open-ExcelPackage -Path $FileName -ErrorAction Stop
194-
$sheetExists = $null -ne $pkg.Workbook.Worksheets["Script Info"]
194+
$ErrorActionPreference = 'SilentlyContinue'
195195

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
208-
}
196+
# Open existing package and add/append the Script Info sheet
197+
try {
198+
$pkg = Open-ExcelPackage -Path $FileName -ErrorAction Stop
199+
$sheetExists = $null -ne $pkg.Workbook.Worksheets["Script Info"]
209200

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-
}
201+
if ($sheetExists) {
202+
# Append rows after existing data
203+
$ws = $pkg.Workbook.Worksheets["Script Info"]
204+
$startRow = $ws.Dimension.End.Row + 1
205+
} else {
206+
# Create a new sheet
207+
$ws = $pkg.Workbook.Worksheets.Add("Script Info")
208+
$startRow = 1
209+
# Add header row
210+
$ws.Cells[$startRow, 1].Value = "Key"
211+
$ws.Cells[$startRow, 2].Value = "Value"
212+
$startRow = 2
213+
}
215214

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() }
224-
}
215+
foreach ($item in $RunInfo) {
216+
$ws.Cells[$startRow, 1].Value = $item.Key
217+
$ws.Cells[$startRow, 2].Value = [string]$item.Value
218+
$startRow++
219+
}
225220

226-
$ErrorActionPreference = $savedEAP
221+
$ws.Column(1).Width = 25
222+
$ws.Column(2).Width = 80
223+
$ws.TabColor = [System.Drawing.Color]::Gray
224+
$pkg.Save()
225+
$pkg.Dispose()
226+
} catch {
227+
Write-Warning "Unable to write Script Info tab: $_"
228+
if ($null -ne $pkg) { $pkg.Dispose() }
229+
}
230+
} finally {
231+
$ErrorActionPreference = $savedEAP
232+
}
227233
}
228234

229235
function Export-TimelineExcel {
230236
Write-Host -ForegroundColor Cyan "Exporting Timeline to Excel..."
231237
$savedEAP = $ErrorActionPreference
232-
$ErrorActionPreference = 'SilentlyContinue'
233-
$tlExcel = $script:TimeLineOutput | Export-Excel -Path $FileName -WorksheetName $($ShortId + "_TimeLine") -Title "Timeline for $Identity" -AutoSize -FreezeTopRow -BoldTopRow -PassThru 3>$null
234-
$ErrorActionPreference = $savedEAP
238+
try {
239+
$ErrorActionPreference = 'SilentlyContinue'
240+
$tlExcel = $script:TimeLineOutput | Export-Excel -Path $FileName -WorksheetName $($ShortId + "_TimeLine") -Title "Timeline for $Identity" -AutoSize -FreezeTopRow -BoldTopRow -PassThru 3>$null
241+
} finally {
242+
$ErrorActionPreference = $savedEAP
243+
}
235244
$tlExcel.Workbook.Worksheets[$ShortId + "_TimeLine"].TabColor = $script:TabColor
236245
Export-Excel -ExcelPackage $tlExcel -WorksheetName $($ShortId + "_TimeLine")
237246
}

0 commit comments

Comments
 (0)