Home

Awesome

Package Source List Provider (PSL)

PSL provider provides a way for enterprise administrators to configure package sources for their business through a PSL manifest file in json format, known as PSL json file or source list file. Those package source locations are usually trusted, validated, approved or preferred before putting them in the PSL json file.

Targeted Scenarios

Supported Package Types

Prerequisites

How to Use the PSL

First you need to get the PSL provider on your machine. There are two ways to do that.

1. You can clone the repo and build it by your own.

git clone https://github.com/OneGet/PSLProvider.git

# Open the .csproj file in Visual Studio and build it.
# After the successful build, you can import the provider assembly directly from the build location. For example,

import-packageprovider C:\psl\PSLProvider\output\Debug\bin\Microsoft.PackageManagement.PackageSourceListProvider.dll

Run Get-PackageProvider, you will see the PSL provider is listed from the output of Get-PackageProvider.

This experience is mainly for developers. For IT pros let's see the following.

2. You can download the provider via Install-PackageProvider

Find-PackageProvider -name PSL
Install-PackageProvider -name PSL -verbose
Get-PackageProvider

To make the above scenario to work, your machine needs internet access. In case you do not internet access, you can follow the instruction to get the provider.

Now we have the provider is installed and imported on your PowerShell session. As a first time experience, PSL is trying to download an sample psl.json source list file. In the example below, If you hit y, PSL will download the psl.json, saves it under $env:appdata, and register it for you.

PS C:\Test> Find-Package -ProviderName PSL

Cannot find source list file 'C:\Users\jianyunt\AppData\Roaming\PSL\PSL.json'.
Do you want to download package source list from 'http://go.microsoft.com/fwlink/?LinkID=821777&clcid=0x409'?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y

Name                           Version          Source           Summary
----                           -------          ------           -------
PowerShell                     6.0.0.9          https://githu... Powershell

Now you can run install-package to install the PowerShell package on your machine, show below.


install-package -name PowerShell -provider psl

How to Create PSL Source List File

Let's take look at the syntax first.

Syntax of PSL Source List File

If you open the sample psl.json file, you see the following:

PS C:\Test> Get-Content  C:\Users\jianyunt\AppData\Roaming\PSL\PSL.json
{
        "PowerShell": {
                "name": "PowerShell_6.0.0.9",
                "displayName": "PowerShell",
                "source": "https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.9/PowerShell_6.0.0.9-alpha.9-win10-x64.msi",
                "hash": {
                        "algorithm": "sha512",
                        "hashCode": "/9D5iBELrs3GFq2l50NYHVq85Ctor3jhqV25EfgqWubLrM2b5XEs8mO3b6IIc3GFoJPNtH1N6Qd2V8YR2v5NqQ=="
                },
                "summary": "Powershell",
                "type": "msi",
                "version": "6.0.0.9"
        }
}

If you want to manage more packages, you can add more entries to the existing psl.json.

For example, if you wish to install docker, you can add something like following to psl.json:

"docker": {
  "source": "https://get.docker.com/builds/Windows/x86_64/docker-1.12.0.zip",
  "hash": {
          "algorithm": "sha512",
          "hashCode": "A64DB25C5B0CF30BDD8CA253CCBB5F5D97B4F8E68895CEE7AD0E908CAEAC1BA3F1FC0DA5FADA8111D393C7148562362EA465934E61B7E823935F9687E80D8091"
  },
  "summary": "Docker zip package",
  "type": "zip",
  "version": "1.12.0",
  "destination": "%programfiles%"
},

Let's use the above example to explain the syntax of the PSL json file.

Test json Source List File

You can check the syntax correctness of json file through Json Validator. Once passing the syntax checking, you can test if the json file works properly with PSL by following the steps below. Let's use docker as an example and assuming 'c:\test\mypsl.json' is the json file you created.


Register-PackageSource -Name testpsl -ProviderName PSL -Location c:\test\mypsl.json
Get-PackageSource

Find-Package -ProviderName PSL
Install-Package -ProviderName PSL -Name docker

Security Consideration

Try it

Let's walk through the following, assuming you are on Windows 10 anniversary edition.


# Find and install the provider
Find-PackageProvider -name PSL
Install-PackageProvider -name PSL

# Check to make sure the PSL provider is imported
Get-PackageProvider

PS C:\Test> Find-Package -ProviderName PSL

Cannot find source list file 'C:\Users\jianyunt\AppData\Roaming\PSL\PSL.json'.
Do you want to download package source list from 'http://go.microsoft.com/fwlink/?LinkID=821777&clcid=0x409'?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y

Name                           Version          Source           Summary
----                           -------          ------           -------
PowerShell                     6.0.0.9          https://githu... Powershell

Now you can run Install-Package to install the latest PowerShell bits on your machine. As an example, let's open PSL.json file and add docker to it, it will look like below:

PS C:\Test> Get-Content  C:\Users\jianyunt\AppData\Roaming\PSL\PSL.json
{
    "PowerShell": {
        "displayName": "PowerShell_6.0.0.9",  
        "source": "https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.9/PowerShell_6.0.0.9-alpha.9-win10-x64.msi",
        "hash": {
                "algorithm": "sha512",
                "hashCode": "FFD0F988110BAECDC616ADA5E743581D5ABCE42B68AF78E1A95DB911F82A5AE6CBACCD9BE5712CF263B76FA208737185A093CDB47D4DE9077657C611DAFE4DA9"
            },
          "summary": "Powershell",
          "type": "msi",
          "version": "6.0.0.9"
        },
    "docker": {
        "source": "https://get.docker.com/builds/Windows/x86_64/docker-1.12.0.zip",
        "hash": {
                "algorithm": "sha512",
                "hashCode": "A64DB25C5B0CF30BDD8CA253CCBB5F5D97B4F8E68895CEE7AD0E908CAEAC1BA3F1FC0DA5FADA8111D393C7148562362EA465934E61B7E823935F9687E80D8091"
        },
          "summary": "Docker zip package",
          "type": "zip",
          "version": "1.12.0",
          "destination": "%programfiles%"
        }
}

Save the file, and let's try the following.

PS C:\Test> Find-Package -ProviderName PSL

Name                           Version          Source           Summary
----                           -------          ------           -------
docker                         1.12.0           https://get.d... Docker zip package
PowerShell                     6.0.0.9          https://githu... Powershell


PS C:\Test> Install-Package docker -AddToPath

The package(s) come(s) from a package source that is not marked as trusted.
Are you sure you want to install software from 'https://get.docker.com/builds/Windows/x86_64/docker-1.12.0.zip'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y

Name                           Version          Source           Summary
----                           -------          ------           -------
docker                         1.12.0           https://get.d... Docker zip package



PS C:\Test> Install-Package docker -AddToPath

# "-AddToPath": adding the package path to your $env:path,
# so that after the install, you can launch docker.exe on your current session.
# The path to be added is destination\packagename\packageversion.

# Here the destination is provided in the json file.
# If you do not specify AddToPath, then $env:path will not be updated.
# This switch is used for zip package only.

PS C:\Test> Get-Package docker

Name                           Version          Source                           ProviderName
----                           -------          ------                           ------------
docker                         1.12.0           C:\Program Files\docker\1.12.0   PSL


PS C:\Test> Uninstall-Package docker -RemoveFromPath

Name                           Version          Source           Summary
----                           -------          ------           -------
docker                         1.12.0           https://get.d... Docker zip package


# "RemoveFromPath" is opposite to "AddToPath". It removes the path from $env:Path.
# If you do not add "RemoveFromPath" switch,  then $env:path will not be updated.


Design

Now we learned how to use PSL. See its design flow diagram if you have interests. Also see the known issues.

Developing and Contributing

We welcome and appreciate contributions from the community. Please follow the PowerShell contribution guidelines.

Legal and Licensing

PSL is licensed under the MIT license.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.