Repository: microsoft/CSS-Exchange
File: Calendar/Check-SharingStatus.ps1 (PowerShell)

Code before:
.DESCRIPTION
    This function processes calendar sharing invite logs.
.PARAMETER Identity
    The SMTP Address for which to process calendar sharing accept logs.
#>
function ProcessInternetCalendarLogs {
    param (
        [string]$Identity
    )

    # Define the header row
    $header = "Timestamp", "Mailbox", "SyncDetails", "PublishingUrl", "RemoteFolderName", "LocalFolderId", "Folder"

    $csvString = @()
    $csvString = $header -join ","
    $csvString += "`n"

    try {
        # Call the Export-MailboxDiagnosticLogs cmdlet and store the output in a variable
        # -ErrorAction is not supported on Export-MailboxDiagnosticLogs
        # $logOutput = Export-MailboxDiagnosticLogs $Identity -ComponentName AcceptCalendarSharingInvite -ErrorAction SilentlyContinue

        $logOutput = Export-MailboxDiagnosticLogs $Identity -ComponentName InternetCalendar
    } catch {
        # Code to run if an error occurs
        Write-Error "An error occurred processing InternetCalendar logs."
    }

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

    $logLines =@()

    # Split the output into an array of lines
    $logLines = $logOutput.MailboxLog -split "`r`n"

    # Loop through each line of the output
    foreach ($line in $logLines) {
        if ($line -like "*Entry Sync Details for InternetCalendar subscription DataType=calendar*") {
            $csvString += $line + "`n"
        }
    }

    # Clean up output

Review comment (bug):
It might still be helpful to include the Inner Exception. Makes it easier to debug down the road if required.  #Resolved

Code after:
    )

    # Define the header row
    $header = "Timestamp", "Mailbox", "SyncDetails", "PublishingUrl", "RemoteFolderName", "LocalFolderId", "Folder"

    $csvString = @()
    $csvString = $header -join ","
    $csvString += "`n"

    try {
        # Call the Export-MailboxDiagnosticLogs cmdlet and store the output in a variable
        # -ErrorAction is not supported on Export-MailboxDiagnosticLogs
        # $logOutput = Export-MailboxDiagnosticLogs $Identity -ComponentName AcceptCalendarSharingInvite -ErrorAction SilentlyContinue
        $logOutput = Export-MailboxDiagnosticLogs $Identity -ComponentName InternetCalendar
    } catch {
        Write-Error "Ignore above error, No InternetCalendar logs found."
    }

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

    $logLines =@()

    # Split the output into an array of lines
    $logLines = $logOutput.MailboxLog -split "`r`n"

    # Loop through each line of the output
    foreach ($line in $logLines) {
        if ($line -like "*Entry Sync Details for InternetCalendar subscription DataType=calendar*") {
            $csvString += $line + "`n"
        }
    }

    # Clean up output
    $csvString = $csvString.Replace("Mailbox: ", "")
    $csvString = $csvString.Replace("Entry Sync Details for InternetCalendar subscription DataType=calendar", "InternetCalendar")
    $csvString = $csvString.Replace("PublishingUrl=", "")
    $csvString = $csvString.Replace("RemoteFolderName=", "")
    $csvString = $csvString.Replace("LocalFolderId=", "")
    $csvString = $csvString.Replace("folder ", "")

    # Convert the CSV string to an object
    $csvObject = $csvString | ConvertFrom-Csv