Skip to content

Instantly share code, notes, and snippets.

@SteveH3032
Last active September 12, 2019 13:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SteveH3032/16a0343858bdcd0ae321f0f599539af4 to your computer and use it in GitHub Desktop.
Save SteveH3032/16a0343858bdcd0ae321f0f599539af4 to your computer and use it in GitHub Desktop.
Nov 2018 - PowerShell script to download all NuGet packages
$indexClient = new-object system.net.webclient
$jsonIndex=$indexClient.DownloadString("https://api.nuget.org/v3/catalog0/index.json") | ConvertFrom-Json
for ($h=0; $h -lt $jsonIndex.items.Length; $h++) {
$web_client = new-object system.net.webclient
$jsonObj=$web_client.DownloadString($jsonIndex.items[$h].'@id') | ConvertFrom-Json
for ($i=0; $i -lt $jsonObj.items.Length; $i++) {
$package = $jsonObj.items[$i]."nuget:id" + "/" + $jsonObj.items[$i]."nuget:version"
$web_client.DownloadFile("https://www.nuget.org/api/v2/package/" + $package, ("C:\Nuget\" + $jsonObj.items[$i]."nuget:id" + "." + $jsonObj.items[$i]."nuget:version" + ".nupkg"))
"Processing: " + ($h + 1) + " of " + $jsonIndex.count + " ---- " + ($i + 1) + " of " + $jsonObj.count + " - " + $jsonObj.items[$i]."nuget:id" + "." + $jsonObj.items[$i]."nuget:version"
}
}
@TwoXTwentyOne
Copy link

TwoXTwentyOne commented Mar 26, 2019

Running the script above in Powershell I get the following error:

$.id : The term '$.id' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At E:\Nuget_All.ps1:4 char:29
+ $OUTPUT = "E:\Nuget$\Nuget$($.id).$($.version).nupkg"
+                             ~~~~
    + CategoryInfo          : ObjectNotFound: ($.id:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

$.version : The term '$.version' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At E:\Nuget_All.ps1:4 char:37
+ $OUTPUT = "E:\Nuget$\Nuget$($.id).$($.version).nupkg"
+                                     ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ($.version:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment