Functions/Get-BCStatusDetailed.ps1

function Get-BCStatusDetailed(){
    <#
    .Synopsis
    Returns Branch Cache usage statistsics of the last downloads per source host including peer usage statistics.
 
    .Description
    Returns Windows BranchCache usage statistsics of the last downloads per source host including peer usage statistics. With this information you are able to analyze if downloads are using the peers and save internet bandwidth.
 
    .Example
    # Displays a full report BranchCache downloads.
    Get-BCStatusDetailed
    #>

    $Events = Get-WinEvent -LogName "Microsoft-Windows-Bits-Client/Operational" | Where-Object { 60 -eq $_.Id }

    ForEach ($Event in $Events) {            
        # Convert the event to XML
        $eventXML = [xml]$Event.ToXml()            
        # Iterate through each one of the XML message properties
        For ($i=0; $i -lt $eventXML.Event.EventData.Data.Count; $i++) {    
            if($eventXML.Event.EventData.Data[$i].name -eq "url"){
                Add-Member -InputObject $Event -MemberType NoteProperty -Force -Name "UrlHost" -Value ([uri]($eventXML.Event.EventData.Data[$i].'#text')).DnsSafeHost 
            }        
            # Append these as object properties
            Add-Member -InputObject $Event -MemberType NoteProperty -Force -Name  $eventXML.Event.EventData.Data[$i].name -Value $eventXML.Event.EventData.Data[$i].'#text'            
        }            
    } 
    $BCStatsExtended = @()
    $BCStats = $Events | Group-Object -Property "UrlHost" 
    foreach($BCStat in $BCStats){ 
        $t = New-Object PSObject
        Add-Member -InputObject $t -MemberType NoteProperty -Force -Name  "UrlHost" -Value $BCStat.Name
        Add-Member -InputObject $t -MemberType NoteProperty -Force -Name  "Count" -Value $BCStat.Count
        Add-Member -InputObject $t -MemberType NoteProperty -Force -Name  "MBTotal" -Value (($BCStat.Group | Measure-Object -Property bytesTotal -Sum).Sum/1MB)
        Add-Member -InputObject $t -MemberType NoteProperty -Force -Name  "MBTransferedFromPeers" -Value (($BCStat.Group | Measure-Object -Property bytesTransferredFromPeer -Sum).Sum/1MB)
        Add-Member -InputObject $t -MemberType NoteProperty -Force -Name  "peerProtocolFlagsOfFirstDownload" -Value (($BCStat.Group | Select-Object -First 1 -Property peerProtocolFlags).peerProtocolFlags)
        $BCStat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