Search code examples
powershellnugetpackagenuget-package

How to get NuGet package authors in PowerShell?


I want to get a NuGet packages information. I have already script , like this:

@( Get-Project -All | ? { $_.ProjectName } | %  {
Get-Package -ProjectName $_.ProjectName } ) | ? { $_.LicenseUrl } | % {
$pkg  = $_ ;

$pkg.Id is accessible $pkg.LicenseUrl is accessible

But I cannot understand when I print $pkg , the output contains Id, Versions,ProjectName. How to acces LicenseUrl .

$pkg.Authors is not accessible . I cannot any script for getting autohers from NugetPackages. Pls help me.


Solution

  • You could query the NuGet API:

    function Get-PackageAuthors {
        param (
            [Parameter(
                Mandatory = $true,
                ValueFromPipeline = $true,
                ValueFromPipelineByPropertyName = $true
            )]
            [string]$Id,
    
            [Uri]$Url = "https://api-v2v3search-0.nuget.org"
        )
        process {
            $response = Invoke-RestMethod "${Url}query?q=${Id}&take=1"
            if ($response.totalHits -gt 0) {
                return $response.data.authors
            }
        }
    }
    
    # usage:
    Get-Package | Get-PackageAuthors