Skip to content

Commit 85ef993

Browse files
authored
Merge pull request #2536 from microsoft/UpdateCheckSharing
Update Check Sharing
2 parents c7cb6b5 + 7680d78 commit 85ef993

1 file changed

Lines changed: 20 additions & 49 deletions

File tree

Calendar/Check-SharingStatus.ps1

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ function ProcessCalendarSharingInviteLogs {
6161

6262
$logOutput = Export-MailboxDiagnosticLogs $Identity -ComponentName CalendarSharingInvite
6363
} catch {
64-
Write-Error "Ignore above error, No CalendarSharingInvite logs found."
64+
Write-Warning "Failed to retrieve CalendarSharingInvite logs for [$Identity]: $($_.Exception.Message)"
65+
return
6566
}
6667

6768
# check if the output is empty
@@ -70,7 +71,6 @@ function ProcessCalendarSharingInviteLogs {
7071
return
7172
}
7273

73-
$logLines =@()
7474
# Split the output into an array of lines
7575
$logLines = $logOutput.MailboxLog -split "`r`n"
7676

@@ -129,7 +129,13 @@ function ProcessCalendarSharingAcceptLogs {
129129
Write-Host "Collecting AcceptCalendarSharingInvite logs for [$Identity] ..."
130130
$logOutput = Export-MailboxDiagnosticLogs $Identity -ComponentName AcceptCalendarSharingInvite
131131
} catch {
132-
Write-Error "Ignore above error, No AcceptCalendarSharingInvite logs found."
132+
$errorMessage = $_.Exception.Message
133+
if ($errorMessage -match "(?i)not\s+found|no\s+logs") {
134+
Write-Warning "No AcceptCalendarSharingInvite logs found for [$Identity]. Details: $errorMessage"
135+
return
136+
}
137+
138+
throw "Failed to collect AcceptCalendarSharingInvite logs for [$Identity]: $errorMessage"
133139
}
134140

135141
# check if the output is empty
@@ -138,7 +144,6 @@ function ProcessCalendarSharingAcceptLogs {
138144
return
139145
}
140146

141-
$logLines =@()
142147
# Split the output into an array of lines
143148
$logLines = $logOutput.MailboxLog -split "`r`n"
144149

@@ -241,21 +246,16 @@ function ProcessInternetCalendarLogs {
241246
# $logOutput = Export-MailboxDiagnosticLogs $Identity -ComponentName AcceptCalendarSharingInvite -ErrorAction SilentlyContinue
242247
$logOutput = Export-MailboxDiagnosticLogs $Identity -ComponentName InternetCalendar
243248
} catch {
244-
Write-Error "Ignore above error, No InternetCalendar logs found."
249+
Write-Warning "No InternetCalendar logs found for [$Identity]."
245250
}
246251

247252
# check if the output is empty
248253
if ($null -eq $logOutput.MailboxLog) {
249-
Write-Host -ForegroundColor Green "==========================================="
250-
Write-Host -ForegroundColor Green "It is safe to ignore the big error above, it is just saying that there are no InternetCalendar logs."
251254
Write-Host -ForegroundColor Green "No InternetCalendar Logs found for [$Identity]."
252255
Write-Host -ForegroundColor Green "User [$Identity] is not receiving any Published Calendars."
253-
Write-Host -ForegroundColor Green "==========================================="
254256
return
255257
}
256258

257-
$logLines =@()
258-
259259
# Split the output into an array of lines
260260
$logLines = $logOutput.MailboxLog -split "`r`n"
261261

@@ -303,14 +303,6 @@ function GetOwnerInformation {
303303
Write-Host -ForegroundColor DarkYellow "Key Owner Mailbox Information:"
304304
Write-Host -ForegroundColor DarkYellow "`t Running 'Get-Mailbox $Owner'"
305305
$script:OwnerMB = Get-Mailbox $Owner
306-
# Write-Host "`t DisplayName:" $script:OwnerMB.DisplayName
307-
# Write-Host "`t Database:" $script:OwnerMB.Database
308-
# Write-Host "`t ServerName:" $script:OwnerMB.ServerName
309-
# Write-Host "`t LitigationHoldEnabled:" $script:OwnerMB.LitigationHoldEnabled
310-
# Write-Host "`t CalendarVersionStoreDisabled:" $script:OwnerMB.CalendarVersionStoreDisabled
311-
# Write-Host "`t CalendarRepairDisabled:" $script:OwnerMB.CalendarRepairDisabled
312-
# Write-Host "`t RecipientTypeDetails:" $script:OwnerMB.RecipientTypeDetails
313-
# Write-Host "`t RecipientType:" $script:OwnerMB.RecipientType
314306

315307
if (-not $script:OwnerMB) {
316308
Write-Host -ForegroundColor Yellow "Could not find Owner Mailbox [$Owner]."
@@ -337,7 +329,7 @@ function GetOwnerInformation {
337329
$OwnerCalendarStats = Get-MailboxFolderStatistics -Identity $Owner -FolderScope Calendar
338330
$OwnerCalendarName = ($OwnerCalendarStats | Where-Object FolderType -EQ "Calendar").Name
339331

340-
$OwnerCalendarStats | Format-Table -a FolderPath, ItemsInFolder, FolderAndSubfolderSize
332+
$OwnerCalendarStats | Format-Table -a FolderPath, VisibleItemsInFolder, FolderAndSubfolderSize
341333

342334
Write-Host -ForegroundColor DarkYellow "Owner Calendar Permissions:"
343335
Write-Host -ForegroundColor DarkYellow "`t Running 'Get-MailboxFolderPermission "${Owner}:\$OwnerCalendarName" | Format-Table -a User, AccessRights, SharingPermissionFlags'"
@@ -351,7 +343,7 @@ function GetOwnerInformation {
351343
}
352344

353345
# Warn if the Calendar count is greater than 100,000 items
354-
if ([int]$OwnerCalendarStats[0].ItemsInFolder -gt 100000) {
346+
if ([int]$OwnerCalendarStats[0].VisibleItemsInFolder -gt 100000) {
355347
Write-Host -ForegroundColor Yellow "Warning: Owner Calendar has more than 100,000 items. This can impact calendar performance."
356348
Write-Host -ForegroundColor Yellow "`t Consider archiving old calendar items."
357349
}
@@ -375,6 +367,7 @@ function GetOwnerInformation {
375367
$script:OwnerPublished = $false
376368
}
377369

370+
Write-Host -ForegroundColor DarkYellow "`t ExtendedFolderFlags: $($OwnerCalendarFolder.ExtendedFolderFlags)"
378371
if ($OwnerCalendarFolder.ExtendedFolderFlags.Contains("SharedOut")) {
379372
Write-Host -ForegroundColor Green "Owner Calendar is Shared Out using Modern Sharing."
380373
$script:OwnerModernSharing = $true
@@ -383,15 +376,6 @@ function GetOwnerInformation {
383376
$script:OwnerModernSharing = $false
384377
}
385378

386-
Write-Host -ForegroundColor DarkYellow "`t Running 'Get-MailboxCalendarFolder -Identity "${Owner}:\$OwnerCalendarName"'"
387-
$CalFolderProps = Get-MailboxCalendarFolder -Identity "${Owner}:\$OwnerCalendarName"
388-
Write-Host -ForegroundColor DarkYellow "`t ExtendedFolderFlags: $($CalFolderProps.ExtendedFolderFlags)"
389-
if ($CalFolderProps.ExtendedFolderFlags -like "*SharedOut*") {
390-
Write-Host -ForegroundColor Green "`t Calendar is Shared Out using Modern Sharing."
391-
} else {
392-
Write-Host -ForegroundColor Red "`t Calendar is not Shared Out using Modern Sharing."
393-
}
394-
395379
# cSpell:ignore Sharees
396380
if (Get-Command -Name Get-CalendarActiveSharingInformation -ErrorAction SilentlyContinue) {
397381
Write-Host -ForegroundColor DarkYellow "`t Running 'Get-CalendarActiveSharingInformation -Identity "${Owner}:\$OwnerCalendarName"'"
@@ -455,7 +439,7 @@ function GetReceiverInformation {
455439
Write-Host -ForegroundColor Cyan "Receiver Calendar Folders (look for a copy of [$OwnerCalendarName] Calendar):"
456440
Write-Host -ForegroundColor Cyan "Running: 'Get-MailboxFolderStatistics -Identity $Receiver -FolderScope Calendar'"
457441
$CalStats = Get-MailboxFolderStatistics -Identity $Receiver -FolderScope Calendar
458-
$CalStats | Format-Table -a FolderPath, ItemsInFolder, FolderAndSubfolderSize
442+
$CalStats | Format-Table -a FolderPath, VisibleItemsInFolder, FolderAndSubfolderSize
459443
$ReceiverCalendarName = ($CalStats | Where-Object FolderType -EQ "Calendar").Name
460444

461445
# Warning if there are multiple copies of the Owner Calendar in the Receiver Mailbox.
@@ -464,7 +448,7 @@ function GetReceiverInformation {
464448
}
465449

466450
# Warning if the Receivers copy of the Calendar name is the default "Calendar".
467-
if (($CalStats.name -like "Cal*").count -gt 1) {
451+
if (($CalStats.name -like "Calendar*").count -gt 1) {
468452
Write-Host -ForegroundColor Yellow "Warning: Receiver might have multiple Calendars named 'Calendar'."
469453
Write-Host -ForegroundColor Yellow "Warning: This can cause confusion with which calendar is being referenced."
470454
}
@@ -475,14 +459,14 @@ function GetReceiverInformation {
475459
}
476460

477461
# Note $Owner has a * at the end in case we have had multiple setup for the same user, they will be appended with a " 1", etc.
478-
if (($CalStats | Where-Object Name -Like $Owner*) -or ($CalStats | Where-Object Name -Like "$($script:OwnerMB.DisplayName)*" )) {
462+
if (($CalStats | Where-Object Name -Like "$Owner*") -or ($CalStats | Where-Object Name -Like "$($script:OwnerMB.DisplayName)*" )) {
479463
Write-Host -ForegroundColor Green "Looks like we might have found a copy of the Owner Calendar in the Receiver Mailbox."
480464
Write-Host -ForegroundColor Green "This is a good indication the there is a Modern Sharing Relationship between these users."
481465
Write-Host -ForegroundColor Green "If the clients use the Modern Sharing or not is a up to the client."
482466
$script:ModernSharing = $true
483467

484-
$CalStats | Where-Object Name -Like $Owner* | Format-Table -a FolderPath, ItemsInFolder, FolderAndSubfolderSize
485-
if (($CalStats | Where-Object Name -Like $Owner*).count -gt 1) {
468+
$CalStats | Where-Object Name -Like "$Owner*" | Format-Table -a FolderPath, VisibleItemsInFolder, FolderAndSubfolderSize
469+
if (($CalStats | Where-Object Name -Like "$Owner*").count -gt 1) {
486470
Write-Host -ForegroundColor Yellow "Warning: Might have found more than one copy of the Owner Calendar in the Receiver Mailbox."
487471
}
488472
} else {
@@ -517,19 +501,6 @@ function GetReceiverInformation {
517501
Write-Host "Consider upgrading these to the new model."
518502
$ReceiverCalEntries | Where-Object SharingModelType -Like Old | Format-Table CalendarGroupName, CalendarName, OwnerEmailAddress, SharingModelType, IsOrphanedEntry
519503
}
520-
521-
# need to check if Get-CalendarValidationResult in the PS Workspace
522-
if ((Get-Command -Name Get-CalendarValidationResult -ErrorAction SilentlyContinue) -and
523-
$null -ne $ReceiverCalEntries) {
524-
$ewsId_del= $ReceiverCalEntries[0].LocalFolderId
525-
Write-Host "Trying to run cmdlet: Get-CalendarValidationResult -Version V2 -Identity $Receiver -SourceCalendarId $ewsId_del -TargetUserId $Owner -IncludeAnalysis 1 -OnlyReportErrors 1 | FT -a GlobalObjectId, EventValidationResult "
526-
try {
527-
$ValidationResults = Get-CalendarValidationResult -Version V2 -Identity $Receiver -SourceCalendarId $ewsId_del -TargetUserId $Owner -IncludeAnalysis 1 -OnlyReportErrors 1
528-
$ValidationResults | Format-List UserPrimarySMTPAddress, Subject, GlobalObjectId, EventValidationResult, EventComparisonResult
529-
} catch {
530-
Write-Error "Failed to run Get-CalendarValidationResult: $_"
531-
}
532-
}
533504
}
534505

535506
#Output key Modern Sharing information
@@ -571,8 +542,8 @@ function GetReceiverInformation {
571542
}
572543

573544
# Main
574-
$script:ModernSharing
575-
$script:SharingType
545+
$script:ModernSharing = $false
546+
$script:SharingType = $null
576547
GetOwnerInformation -Owner $Owner
577548
GetReceiverInformation -Receiver $Receiver
578549

0 commit comments

Comments
 (0)