functions/Show-PackageLicences.ps1

<#
.SYNOPSIS
Shows Package Licences with licence type
 
.DESCRIPTION
Shows Package Licences with licence type
 
.PARAMETER pathToSource
locataion of source
 
.PARAMETER tfsSiteUrl
site url for tfs
.PARAMETER project
project in tfs
 
.PARAMETER repository
repository in project in tfs
 
.PARAMETER nugetFeedUrl
site url for nuget / package feed
 
.PARAMETER wip
folder for process
 
.EXAMPLE
Show-PackageLicences -pathToSource "C:\g\repo" -nugetFeedUrl "http://proget/nuget/nuget.org" -wip "C:\temp\wip"
 
Show-PackageLicences -pathToSource "$(Build.SourcesDirectory)" -nugetFeedUrl "http://proget/nuget/nuget.org" -wip "$(build.artifactstagingdirectory)"
 
Show-PackageLicences -tfsSiteUrl http://tfs/tfs/UKHO -project "ALM" -repository "BuildAndDeploy" -nugetFeedUrl "http://proget/nuget/nuget.org" -wip "C:\a\A001\work\s"
 
.NOTES
There are 2 version that work with a local source on a disk or a remote git repo on tfs
#>

function Show-PackageLicences {
    [CmdletBinding()]
    param(
        $pathToSource,
        $tfsSiteUrl,
        $project,
        $repository,
        [Parameter(Mandatory=$true)]
        $nugetFeedUrl
    )

    begin {
        $ErrorActionPreference = "Stop"
        Write-Information "Start combine package lists"
        if($pathToSource -eq $null -and $tfsSiteUrl -eq $null -and $repository -eq $null -and $project -eq $null) {
            Write-Error "No parameters have been found that will provide a successful run, please check help"
        }
        if($pathToSource -eq $null) {
            if (!($tfsSiteUrl -ne $null -and $repository -ne $null -and $project -ne $null)) {
                Write-Error "One or more of the following parameter have not been set, tfsSiteUrl: $tfsSiteUrl; repository: $repository; project: $project;"
            }
        }
    }
    process {
        if($pathToSource -ne $null) {
            $packagesInRepo = Get-PackagesInSource -pathToSource $pathToSource
        }
        else {
            $packagesInRepo = Get-PackagesInRepo -tfsSiteUrl $tfsSiteUrl -project $project -repository $repository
        }
        
        Write-Information "End combine package lists"
        
        Write-Information "Start Licence Get"
        
        $currentListOfLicences = Find-LicenceSpdx -nugetFeedUrl $nugetFeedUrl -combined $packagesInRepo
        
        Write-Information "End Licence Get"
        
        $currentListOfLicences | Group-Object { $_.licenceType } | Select-Object Count, Name
        
        Write-Information "File output generated: $pathToSource\licence.json"
        $currentListOfLicences | ConvertTo-Json | Set-Content -Path "$pathToSource\licence.json"
    }
    end {

    }
}