PowerShellGet
is a powerful resource for PowerShell, built on top of the core PackageManagement
capabilities of PowerShell 5. It is one of many PackageManagment
providers available, as shown here:
Image Source: https://blogs.technet.microsoft.com/packagemanagement/2015/04/28/introducing-packagemanagement-in-windows-10/
PackageManagement
is a unified interface for software package management systems, a tool to manage package managers. You use the PackageManagement
cmdlets to perform software discovery, installation, and inventory (SDII) tasks. PackageManagement
involves working with package providers, package sources, and the software packages themselves.
Within the PackageManagement
architecture, PackageManagement
providers represent the various software installers that provide a means to distribute software via a standard plug-in model using the PackageManagement
APIs. Each PackageManagement
provider manages one or more package sources or software repositories. Providers may be publicly available or can be created within an organization to enable developers and system administrators to publish or install propriety or curated software packages.
PackageManagement
Core is effectively an API. The core includes a set of PowerShell cmdlets that enable you to discover available software packages, as well as to install, uninstall, update, and inventory packages using PackageManagement
.
Each PackageManagement
provider is a different installer technology or package manager that plugs-in via the PackageManagement
API. PowerShellGet
, NuGet
, and Chocolatey
are examples of PackageManagement
providers.
Each provider is made up of one or more sources, which may be public or private. For example, NuGet
has a public source, but your organization may add private sources for the NuGet
provider, enabling curation of approved software to make it available to corporate developers.
You use the cmdlets within the PackageManagement
module to explore the capabilities it provides.
- Review the cmdlets in the
PackageManagement
module:
Get-Command -Module PackageManagement
- Review the installed providers with
Get-PackageProvider
:
Get-PackageProvider | Select-Object -Property Name, Version
- The provider list includes
msi
,msu
, andPrograms
package providers. These providers expose applications and updates installed on your computer which you can explore:
Get-Package -ProviderName msi | Select-Object -ExpandProperty Name Get-Package -ProviderName msu | Select-Object -ExpandProperty Name Get-Package -ProviderName Programs | Select-Object -ExpandProperty Name
- The
NuGet
source contains developer library packages. This functionality is outside the scope of this book, but worth exploring if you do Windows or web development:
Get-PackageProvider -Name NuGet
- There are also other package providers you can explore:
Find-PackageProvider | Select-Object -Property Name,Summary | Format-Table -Wrap -AutoSize
- Notice
Chocolatey
, which is a very useful tool for Windows administrators and power users. Those with some Linux background may think ofChocolatey
asapt-get
for Windows. You cannot use this provider until you install it and confirm the installation:
Install-PackageProvider -Name Chocolatey -Verbose
- Verify
Chocolatey
is now in the list of installed providers:
Get-PackageProvider | Select-Object Name,Version
- Look for available software packages from the
Chocolatey
package provider. Store these in a variable so you don't request the collection more than once, and explore it:
$AvailableChocolateyPackages = ` Find-Package -ProviderName Chocolatey # How many software packages are available at Chocolatey? $AvailableChocolateyPackages | Measure-Object
- Pipe to
Out-GridView
to search for interesting software packages fromChocolatey
:
$AvailableChocolateyPackages | Sort-Object Name,Version | Select-Object Name, Version, Summary | Out-GridView
- Install one or more packages.
sysinternals
is a good example to use. Use-Verbose
to get details on the installation:
Install-Package -ProviderName Chocolatey ` -Name sysinternals ` -Verbose
- Review installed
Chocolatey
packages, stored toC:\chocolatey\
by default, this path is stored in the$env:ChocolateyPath
environment variable. Then review the executable files included with thesysinternals
package:
Get-ChildItem -Path $env:ChocolateyPath\lib | Select-Object -Property Name Get-ChildItem -Path ` $env:ChocolateyPath\lib\sysinternals.2016.11.18\tools ` -Filter *.exe | Select-Object -Property Name
- Run any installed command included with
sysinternals
:
$PSInfoCommand = ` ‘C:\Chocolatey\lib\sysinternals.2016.11.18\tools\PsInfo.exe’ Invoke-Expression -Command $PSInfoCommand
- Installed packages are enumerated with
Get-Package
and updated using the same command to install them,Install-Package
:
Get-Package -ProviderName Chocolatey |
Install-Package -Verbose
In step 1, you review the cmdlets available in the PackageManagement
module:
In step 2, you use the Get-PackageProvider
cmdlets to display the currently installed package providers:
In step 3, you use Get-Package
with the -ProviderName
parameter to review packages installed via the msi
, msu
, and Programs
package providers:
In step 4, review the NuGet
provider:
In step 5, search for other package providers:
In step 6, you use Install-PackageProvider
to install the Chocolatey
provider. Since it is untrusted as a public source, you must approve the installation (at your own risk and responsibility):
In this example, you run Install-PackageProvider
from within the ISE. By default, this pops up a confirmation dialog. If you run this cmdlet from the PowerShell console, you see a prompt there. You can suppress these confirmation requests by including the parameter -Confirm:$False
.
In step 7, you verify Chocolatey
is now installed as a package provider:
In step 8, retrieve a list of available software packages from the Chocolatey
PackageProvider
, store as a variable, and count the available packages:
In step 9, pipe the variable to Out-GridView
and use the filter feature to explore what is available. This example is filtering for the Sysinternals
package:
In step 10, you install this package (or any package you choose):
In step 11, you review the installed Chocolatey
packages, and the files contained within the sysinternals
package folder:
In step 12, run any Sysinternals
command, for example, PsInfo.Exe
:
In step 13, you enumerate the installed packages with Get-Package
. As time goes by, packages can be updated with bug fixes, new features, and so on. You can update all the installed packages if any updates exist, as follows:
Details of NuGet
package and its functionality are outside the scope of this book, but worth exploring if you do Windows or web development. More information on NuGet
packages is available from https://www.nuget.org/Packages.
Chocolatey
has both a command-line interface and a PowerShell
module. The command line interface offers functionality comparable to the PackageManagement
module, targeted toward end users and system administrators. Chocolatey
is supported on any Windows PC running Windows 7 or later. You can get more information on installing and using Chocolatey
via the command line from https://chocolatey.org/install.
Sysinternals
is a must-have toolkit for Windows administrators. You can find additional training on the Sysinternals
tools on the Channel 9 website at https://channel9.msdn.com/Series/sysinternals.