internal/Get-PackagesInSource.ps1

<#
.SYNOPSIS
Get packages from source location on disk
 
.DESCRIPTION
Get packages from source location on disk
 
.PARAMETER pathToRepo
Path to the source repository
 
.EXAMPLE
Get-PackagesInSource "C:\g\gitrepohere"
 
.NOTES
General notes
#>

function Get-PackagesInSource {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [String]
        $pathToSource
    )
    begin {
        if (!(Test-Path $pathToSource)) {
            Write-Error "Path not found to $pathToSource"                                    
        }

        $combined = [xml]"<?xml version=""1.0"" encoding=""utf-8""?><packages></packages>"

    }
    process {
        Write-Information "Start combine package lists"

        $packages = Get-ChildItem -Path $pathToSource -Filter "packages.config" -Recurse

        foreach ($package in $packages) {
            $path = $package.FullName
            $get = Get-Content $path

            $xml = ConvertTo-XmlResponse $get

            foreach ($child in $xml.packages.ChildNodes) {        
                $childcheck = $combined.packages.ChildNodes
                if (($childcheck | Where-Object { $_.id -eq $child.id -and $_.version -eq $child.version -and $_.targetFramework -eq $child.targetFramework }) -ne $null) {
                    Write-Debug "got one: $($child.id):$($child.version):$($child.targetFramework)"
                    continue
                }
                $ch = $combined.CreateElement("package")

                $ch.SetAttribute("id", $child.id)
                $ch.SetAttribute("version", $child.version)
                $ch.SetAttribute("targetFramework", $child.targetFramework)
        
                Write-Debug $combined.DocumentElement.AppendChild($ch)
        
            }
        }

        Write-Information "End combine package lists"
    }
    end {
        $combined
    }
}