Private/Get-VcRedistAppsFromIntune.ps1

function Get-VcRedistAppsFromIntune {
    <#
        .SYNOPSIS
        Retrieves existing Microsoft Visual C++ Win32 applications from Intune that match a given VcList object.

        .DESCRIPTION
        The Get-VcRedistAppsFromIntune function queries Intune for Win32 applications whose display names start with
        "Microsoft Visual C" and whose notes contain metadata indicating they were created by VcRedist.
        It then filters these applications to return only those whose GUIDs match the PackageId values in the provided VcList object.

        .PARAMETER VcList
        A PSObject representing a list of Visual C++ Redistributable packages, typically generated by Save-VcRedist.
        The function uses the PackageId property from this object to match against Intune applications.

        .EXAMPLE
        $VcList = Save-VcRedist
        Get-VcRedistAppsFromIntune -VcList $VcList

        This example retrieves all Visual C++ Redistributable applications in Intune that match the packages in $VcList.

        .NOTES
        Requires the IntuneWin32App module to be available in the session.
    #>

    [CmdletBinding(SupportsShouldProcess = $false)]
    param (
        [Parameter(
            Mandatory = $true,
            Position = 0,
            ValueFromPipeline,
            HelpMessage = "Pass a VcList object from Save-VcRedist.")]
        [ValidateNotNullOrEmpty()]
        [System.Management.Automation.PSObject] $VcList
    )

    begin {
        $DisplayNamePattern = "^Microsoft Visual C*"
        $NotesPattern = '^{"CreatedBy":"VcRedist","Guid":.*}$'

        # Get the existing Win32 applications from Intune
        Write-Verbose -Message "Retrieving existing Win32 applications from Intune."
        $ExistingIntuneApps = Get-IntuneWin32App | `
            Where-Object { $_.displayName -match $DisplayNamePattern -and $_.notes -match $NotesPattern } | `
            Select-Object -Property * -ExcludeProperty "largeIcon"
        if ($ExistingIntuneApps.Count -gt 0) {
            Write-Verbose -Message "Found $($ExistingIntuneApps.Count) existing Visual C++ applications in Intune."
        }
    }

    process {
        Write-Verbose -Message "Filtering existing applications to match VcList PackageId."
        foreach ($Application in $ExistingIntuneApps) {
            if (($Application.notes | ConvertFrom-Json -ErrorAction "Stop").Guid -in $VcList.PackageId) {

                # Add the packageId to the application object for easier reference
                $Application | Add-Member -MemberType "NoteProperty" -Name "packageId" -Value $($Application.notes | ConvertFrom-Json -ErrorAction "Stop").Guid -Force
                Write-Output -InputObject $Application
            }
        }
    }
}