次の方法で共有


Update: Using PowerShell OData Provider Module for OneGet and PowerShellGet

Update 03/13/2015: the PowerShell gallery is moved from msconfiggallery.cloudapp.net to powershellgallery.com

After playing with OneGet and PowerShellGet for some time now I wanted to dive into the OData feed that both new PowerShell v5 preview features are using.

Let me first summarize OneGet and PowerShellGet.

OneGet is a new way to discover and install software packages from around the web. With OneGet, you can:

  • ·Manage a list of software repositories in which packages can be searched, acquired, and installed
  • · Search and filter your repositories to find the packages you need
  • · Seamlessly install and uninstall packages from one or more repositories with a single PowerShell command

This first version of OneGet installs and searches software from Chocolatey repositories.  Support of additional repositories will come in subsequent versions.

Both use an OData feed, Open Data Protocol (OData) is a data access protocol initially defined by Microsoft. The protocol was designed to provide standard CRUD access to a data source via a website. If you want to learn more about OData just go to wikipedia.

Now we know, we can access the OneGet and PowerShellGet repositories using an OData feed we can use the PowerShell OData Explorer. With the 'OData Explorer' PowerShell application we can browse the OData Services. After downloading and unzipping the OData Explorer we need to add the two OData Services from OneGet and PowerShellGet in the ODataServices.csv file.

PowerShell OData Explorer

image

image

Name, uri NetFlix,    "https://odata.netflix.com/Catalog" Northwind,  "https://services.odata.org/Northwind/Northwind.svc/" TechEd2010, "https://odata.msteched.com/sessions.svc/" WorldCup,   "https://www.openligadb.de/Webservices/OData.svc/" StackOverflow, "https://odata.stackexchange.com/stackoverflow/atom" SuperUser, "https://odata.stackexchange.com/superuser/atom" ServerFault, "https://odata.stackexchange.com/serverfault/atom" "Meta StackOverflow", "https://odata.stackexchange.com/meta/atom" Locations, "https://ogdi.cloudapp.net/v1/dc" Chocolatey, "https://chocolatey.org/api/v2/" Nuget, "https://www.nuget.org/api/v2/" PowerShellget, "https://powershellgallery.com/api/v2

Open the .\View-OData.ps1 PowerShell script and start browsing.

image

You can browse the Chocolatey or NuGet OData feed for the OneGet Packages or for the PowerShell Modules you can browse the PowerShelGet OData feed.

image

After browsing through the OneGet and PowerShellGet OData repositories would not it be cool if we can “just” navigate those OData feeds like we do with our other PowerShell Providers?

OData PowerShell provider

This can be done using the PowerShell OData Provider Module. The OData PowerShell provider allows you to mount OData feeds as drives in your powershell session. This enables simple and intuitive access to the catalogs, collections, and entities in the feed using the same cmdlets you use for working with files. Download, unzip and install the PowerShell OData Provider and get started navigating your OneGet and PowerShellGet OData feed just like any other PowerShell Provider.

001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 import-module OData #Get-Help on OData queries get-help about_OData_Query #Create an new OneGet Drive New-PSDrive -Name OneGet -PSProvider OData -Root "https://chocolatey.org/api/v2/" #Go to OneGet Drive cd OneGet #Search for latest 7zip package get-childitem OneGet:/packages -orderby Version -filter "Title eq '7zip'" -top 1 #Create an new PowerShelGet Drive New-PSDrive -Name PowerShellGet -PSProvider OData -Root "https://powershellgallery.com/api/v2" #Search top PowerShell Module downloads from PowerShellGet Repository get-childitem PowerShellGet:/packages | where-object {$_.Islatestversion -eq "$true"} | select-object name, @{Label="Downloads";Expression= {[int]$_.Downloadcount}}| sort Downloads -Descending

image

Have fun browsing those PowerShellGet and OneGet OData feeds using the PowerShell OData Provider Module.

Comments

  • Anonymous
    May 27, 2014
    Pingback from Using PowerShell OData Provider Module for OneGet and PowerShellGet | MS Tech BLOG
  • Anonymous
    May 16, 2016
    Nice! Glad to see this module finally getting some use!