Skip to content

Instantly share code, notes, and snippets.

@chrdek
Created November 6, 2023 11:40
Show Gist options
  • Save chrdek/f8c099dd4ea2daed2574eb2dd0a720ff to your computer and use it in GitHub Desktop.
Save chrdek/f8c099dd4ea2daed2574eb2dd0a720ff to your computer and use it in GitHub Desktop.
Retrieve nuget.org v2 API xml package data feeds by nuget package owner name (includes timing of response, preset url status change)
$roundtrip = (Measure-Command -Expression {
$mainXml = Invoke-WebRequest -Uri "https://www.nuget.org/api/v2/Search()?$filter=IsLatestVersion&searchTerm=%27owner%3Aownernamereplacehere%27&targetFramework=%27%27&includePrerelease=false&$skip=0&$top=5&semVerLevel=2.0.0" -UseBasicParsing -Method Get})
[string]$respTime = "$($roundtrip.TotalSeconds) secs";
$mainXml.Content
# NOTE: DateTime req. convert from ISO 8601 format by Newtonsoft JSONConvert.DeserializeObject
[PSCustomObject[]]$xmlMap = @();
[xml]$XmlInfo = (Get-Content "$($pwd.Path)/xmlfeed_pack.xml");
$XmlInfo.feed.entry | %{
$xmlMap += [PSCustomObject] @{
"Name" = $_.properties.Id
"Version" = $_.properties.Version
"DateCreated" = $_.properties.Created."#text" -replace "T", " - " -replace "\+00:00" , "" # datetime N/A @v5.0
"Description" = $_.properties.Description
"Downloads" = [long]$_.properties.DownloadCount."#text"
"IsDocActive" = [bool]$($_.properties.ProjectUrl.null -eq $false)
"RequestTime" = $roundtrip # time for xml result retrieval.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment