Skip to content

Commit 6472848

Browse files
committed
Fixing PR and Testing issues
1 parent 58e5421 commit 6472848

5 files changed

Lines changed: 105 additions & 45 deletions

File tree

Calendar/CalLogHelpers/CalLogCSVFunctions.ps1

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ $script:CalendarItemTypes = @{
2525
'IPM.OLE.CLASS.{00061055-0000-0000-C000-000000000046}' = "Exception"
2626
'IPM.Schedule.Meeting.Notification.Forward' = "Forward.Notification"
2727
'IPM.Appointment' = "Ipm.Appointment"
28-
'IPM.Appointment.MP' = "Ipm.Appointment"
2928
'IPM.Schedule.Meeting.Request' = "Meeting.Request"
3029
'IPM.CalendarSharing.EventUpdate' = "SharingCFM"
3130
'IPM.CalendarSharing.EventDelete' = "SharingDelete"
@@ -36,6 +35,28 @@ $script:CalendarItemTypes = @{
3635
'(Occurrence Deleted)' = "Exception.Deleted"
3736
}
3837

38+
<#
39+
.SYNOPSIS
40+
Resolves the ItemClass to a friendly type name using the CalendarItemTypes table.
41+
If no exact match is found, progressively strips the last dot-segment and retries.
42+
e.g. IPM.Schedule.Meeting.Resp.Tent.Follow → IPM.Schedule.Meeting.Resp.Tent → "Resp.Tent"
43+
#>
44+
function GetItemType {
45+
param([string]$ItemClass)
46+
$lookup = $ItemClass
47+
while (-not [string]::IsNullOrEmpty($lookup)) {
48+
$type = $script:CalendarItemTypes[$lookup]
49+
if (-not [string]::IsNullOrEmpty($type)) {
50+
return $type
51+
}
52+
# Strip the last segment and try the parent
53+
$lastDot = $lookup.LastIndexOf('.')
54+
if ($lastDot -le 0) { break }
55+
$lookup = $lookup.Substring(0, $lastDot)
56+
}
57+
return $null
58+
}
59+
3960
# ===================================================================================================
4061
# Functions to support the script
4162
# ===================================================================================================
@@ -87,6 +108,9 @@ function CreateExternalMasterIDMap {
87108

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

111+
# Remove empty/null and 'Calendar' (the default folder name) entries
112+
$AllFolderNames = @($AllFolderNames | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
113+
90114
if ($AllFolderNames.count -gt 1) {
91115
# We have 2+ FolderNames, remove only exact match to 'Calendar' (the default folder name, not folder names containing 'Calendar')
92116
$Filtered = $AllFolderNames | Where-Object { $_ -ne 'Calendar' }
@@ -161,7 +185,7 @@ function BuildCSV {
161185
$Index = 0
162186
$GCDOResults = foreach ($CalLog in $script:GCDO) {
163187
$Index++
164-
$ItemType = $CalendarItemTypes.($CalLog.ItemClass)
188+
$ItemType = GetItemType $CalLog.ItemClass
165189

166190
# CleanNotFounds
167191
$PropsToClean = "FreeBusyStatus", "ClientIntent", "AppointmentSequenceNumber", "AppointmentLastSequenceNumber", "RecurrencePattern", "AppointmentAuxiliaryFlags", "EventEmailReminderTimer", "IsSeriesCancelled", "AppointmentCounterProposal", "MeetingRequestType", "SendMeetingMessagesDiagnostics", "AttendeeCollection"

Calendar/CalLogHelpers/CalLogInfoFunctions.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function SetIsRecurring {
6565
# See if this is a recurring meeting
6666
foreach ($CalLog in $CalLogs) {
6767
if ($null -ne $CalLog.ItemClass -and
68-
$CalendarItemTypes.($CalLog.ItemClass) -eq "Ipm.Appointment" -and
68+
(GetItemType $CalLog.ItemClass) -eq "Ipm.Appointment" -and
6969
# Commenting this out will get all the updates for shared calendars, which is important with Delegates.
7070
# $CalLog.ExternalSharingMasterId -eq "NotFound" -and
7171
$CalLog.CalendarItemType.ToString() -eq "RecurringMaster") {

Calendar/CalLogHelpers/ExportToExcelFunctions.ps1

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

204229
function 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

Calendar/CalLogHelpers/TimelineFunctions.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function BuildTimeline {
122122

123123
# Setup Previous log (if current logs is an IPM.Appointment)
124124
if ($null -ne $CalLog.ItemClass -and
125-
($CalendarItemTypes.($CalLog.ItemClass) -eq "Ipm.Appointment" -or $CalendarItemTypes.($CalLog.ItemClass) -eq "Exception")) {
125+
((GetItemType $CalLog.ItemClass) -eq "Ipm.Appointment" -or (GetItemType $CalLog.ItemClass) -eq "Exception")) {
126126
$script:PreviousCalLog = $CalLog
127127
}
128128
}

Calendar/Get-CalendarDiagnosticObjectsSummary.ps1

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,35 +149,42 @@ if (!$ExportToCSV.IsPresent) {
149149
. $PSScriptRoot\CalLogHelpers\ExportToExcelFunctions.ps1
150150
}
151151

152-
# Default to Collecting Tracking Logs
153-
if (!$NoTrackingLogs.IsPresent) {
154-
$TrackingLogs = $true
155-
Write-Host -ForegroundColor Yellow "Collecting Tracking Logs."
156-
Write-Host -ForegroundColor Yellow "`tTo skip collecting Tracking Logs, use the -NoTrackingLogs switch."
157-
} else {
158-
Write-Host -ForegroundColor Green "Not Collecting Tracking Logs."
159-
}
152+
# Default to Collecting Tracking Logs (MeetingID only)
153+
if (-not ([string]::IsNullOrEmpty($MeetingID))) {
154+
if (!$NoTrackingLogs.IsPresent) {
155+
$TrackingLogs = $true
156+
Write-Host -ForegroundColor Yellow "Collecting Tracking Logs."
157+
Write-Host -ForegroundColor Yellow "`tTo skip collecting Tracking Logs, use the -NoTrackingLogs switch."
158+
} else {
159+
Write-Host -ForegroundColor Green "Not Collecting Tracking Logs."
160+
}
160161

161-
# Default to Collecting Exceptions
162-
if ((!$NoExceptions.IsPresent) -and ([string]::IsNullOrEmpty($ExceptionDate))) {
163-
$Exceptions=$true
164-
Write-Host -ForegroundColor Yellow "Collecting Exceptions."
165-
Write-Host -ForegroundColor Yellow "`tTo skip collecting Exceptions, use the -NoExceptions switch."
166-
} else {
167-
Write-Host -ForegroundColor Green "---------------------------------------"
168-
if ($NoExceptions.IsPresent) {
169-
Write-Host -ForegroundColor Green "Not Checking for Exceptions"
162+
# Default to Collecting Exceptions (MeetingID only)
163+
if ((!$NoExceptions.IsPresent) -and ([string]::IsNullOrEmpty($ExceptionDate))) {
164+
$Exceptions=$true
165+
Write-Host -ForegroundColor Yellow "Collecting Exceptions."
166+
Write-Host -ForegroundColor Yellow "`tTo skip collecting Exceptions, use the -NoExceptions switch."
170167
} else {
171-
Write-Host -ForegroundColor Green "Checking for Exceptions on $ExceptionDate"
168+
Write-Host -ForegroundColor Green "---------------------------------------"
169+
if ($NoExceptions.IsPresent) {
170+
Write-Host -ForegroundColor Green "Not Checking for Exceptions"
171+
} else {
172+
Write-Host -ForegroundColor Green "Checking for Exceptions on $ExceptionDate"
173+
}
174+
Write-Host -ForegroundColor Green "---------------------------------------"
172175
}
173-
Write-Host -ForegroundColor Green "---------------------------------------"
176+
} else {
177+
# Subject-based search
178+
$script:SubjectSearch = $true
179+
Write-Host -ForegroundColor Yellow "Using Subject search. Tracking Logs and Exception collection are only available with -MeetingID."
180+
Write-Host -ForegroundColor Yellow "`tTip: Use the MeetingID from this output to recollect with full details."
174181
}
175182

176183
# ===================================================================================================
177184
# Main
178185
# ===================================================================================================
179186

180-
$ValidatedIdentities = CheckIdentities -Identity $Identity
187+
[array]$ValidatedIdentities = CheckIdentities -Identity $Identity
181188

182189
if ($ExportToExcel.IsPresent) {
183190
CheckExcelModuleInstalled

0 commit comments

Comments
 (0)