Additions/Get-TFSBranchesWithObjects.ps1

function Get-TFSBranchesWithObjects
{        
    Param(
        [Parameter(Mandatory=$false)]
        [int]$NAVVersion = 0,
        [ValidateSet('None','Csv','Screen')]
        [Parameter(Mandatory=$false)]
        [string]$Output,
        [Parameter(Mandatory=$false)]
        [string]$OutputPath = ''
    )
    $Objects = Build-ObjectArray -NAVVersion $NAVVersion
    $BranchArray = Build-BranchArray -ObjectArray $Objects

    foreach($Object in $Objects)
    {
        Remove-Item $Object.Path -Recurse -Force
    }

    if ($Output -eq 'Csv')
    {
        if ($OutputPath -eq '')
        {
            $OutputPath = '{0}/{1}' -f $env:TEMP, 'BranchesWithObjects.csv'
        }

        $BranchArray | Export-Csv -Path $OutputPath -Force
        Start-Process -FilePath $OutputPath
    }
    elseif ($Output -eq 'Screen')
    {
        $BranchArray | Out-GridView -Title 'Results'
    }

    $BranchArray
}

Export-ModuleMember -Function Get-TFSBranchesWithObjects

function Build-BranchArray
{
    Param(
    [Parameter(Mandatory=$true)]
    $ObjectArray
    )

    $BranchArray = @()

    $Branches = Get-TFSBranches | Out-GridView -Title 'Select project branch(es)' -OutputMode Multiple

    #create the set of files to investigate in each of the select additions branches
    foreach($Object in $ObjectArray)
    {
        $DeltaResult = Create-AdditionDeltaFromBase -AdditionPath $Object.Branch -NoContent
        $Object | Add-Member -MemberType NoteProperty -Name Object -Value ((Get-ChildItem $DeltaResult.ReplacementsPath).Item(0).Name)
        $Object | Add-Member -MemberType NoteProperty -Name Path -Value $DeltaResult.ReplacementsPath
    }

    Write-Progress -Activity 'Searching TFS Branches'

    $BranchCount            

    foreach ($Branch in $Branches)
    {
        $BranchCount++
        [boolean]$HasAnAddition = $false
        [string]$HasThisAddition = ''

        Write-Progress -Activity 'Searching TFS Branches' -Status ('Branch {0} of {1}' -f $BranchCount, $Branches.Count) -PercentComplete (($BranchCount / $Branches.Count) * 100)
        
        $BranchObject = New-Object System.Object
        $BranchObject | Add-Member -MemberType NoteProperty -Name Branch -Value $Branch

        foreach ($Object in $ObjectArray)
        {
            $HasThisAddition = Get-BranchIncludesObject -BranchPath $Branch -Object $Object.Object
            
            if ($HasThisAddition -eq 'Yes')
            {                

                $HasThisAddition = Get-AdditionVersionInBranch -BranchPath $Branch -AdditionBranchPath $Object.Path
            }

            $BranchObject | Add-Member -MemberType NoteProperty -Name $Object.Addition -Value $HasThisAddition
            $HasAnAddition = ($HasThisAddition -ne '') -or $HasAnAddition
        }

        if ($HasAnAddition)
        {
            $BranchArray += $BranchObject
        }
    }

    Write-Progress -Activity 'Searching TFS Branches' -Completed

    $BranchArray
}

function Build-ObjectArray
{
    Param(
        [Parameter(Mandatory=$false)]
        [int]$NAVVersion = 0
    )

    $ObjectArray = @()

    $AdditionsBranches = Get-TFSBranches -AdditionBranches -NAVVersion $NAVVersion | Out-GridView -Title 'Select addition branch(es) (optional)' -OutputMode Multiple
    if ($AdditionsBranches -eq $null)
    {
        $AdditionsBranches = Get-TFSBranches -AdditionBranches -NAVVersion $NAVVersion
    }

    foreach ($AdditionBranch in $AdditionsBranches)
    {        
        

        $Object = New-Object System.Object        
        $Object | Add-Member -MemberType NoteProperty -Name Addition -Value (Split-Path $AdditionBranch -Leaf)
        $Object | Add-Member -MemberType NoteProperty -Name Branch -Value $AdditionBranch        
        $ObjectArray += $Object
    }           

    $ObjectArray
}

function Get-BranchIncludesObject
{
    Param(
        [Parameter(Mandatory=$true)]
        [string]$BranchPath,
        [Parameter(Mandatory=$true)]
        [string]$Object
    )

    [string]$Result = ''

    $url = '_apis/tfvc/items?scopepath={0}/{1}' -f $BranchPath, $Object
    $Items = Invoke-TFSAPI -Url $url

    if ($Items.Count -gt 0)
    {
        $Result = 'Yes'
    }

    $Result
}