PowerShellGet

PowerShellGet is the key component to find, install, upgrade, and remove PowerShell scripts, modules, and DSC resources. Additionally, it provides cmdlets to add documentation data to scripts and modules and update them later. All cmdlets are vital components of a PowerShell module release pipeline.

PowerShellGet operates with the NuGet and Chocolatey repositories, and PackageManagement further extends this with additional package providers to handle MSI and MSU files:

# Listing installed software with PackageManagement
Get-Package -ProviderName Programs
NuGet or Chocolatey? Use NuGet for libraries that you publish as a developer and Chocolatey when publishing binaries. Get more info at https://www.nuget.org/ and https://chocolatey.org/. Why not use both?

In order to deploy modules and binary data with PowerShellGet, the Install-* cmdlets are necessary. While installing a cmdlet or script, the PackageManagement module is triggered internally by ultimately calling the Install-Package cmdlet:

# Interactive
# AllowClobber allows installing modules that overwrite existing cmdlets
Install-Module AutomatedLab -Scope CurrentUser -RequiredVersion 5.3 -AllowClobber
Install-Script -Name Speedtest -Scope CurrentUser

# 1-m
Invoke-Command -ComputerName HostA,HostB,HostC -ScriptBlock {
Install-Module -Name MyInfrastructureModule -Repository InternalGallery
}

You can examine the code that handles the installation yourself by exploring the script module:

# Explore the PowerShellGet module
psedit (Join-Path (Get-Module PowerShellGet -List)[-1].ModuleBase PSModule.psm1)

After a module has been initially deployed, a new folder for the module will be created within your $env:PSModulePath, depending on the chosen scope. In this folder, a versioned subfolder will appear, indicating that the module was indeed installed from a module repository:

To find out which modules have been installed from a package repository, you can either access PowerShellGet or PackageManagement:

# Explore all installed modules
# using PowerShellGet
Get-InstalledModule

# PowerShellGet uses PackageManagement internally
Get-Package -ProviderName PowerShellGet

# In case you were wondering: There is more you can do with PackageManagement
Get-Package -ProviderName msi,Programs

# Removing modules is very easy
Get-InstalledModule -Name Format-Pester | Uninstall-Module

# And removing software is very easy as well!
Get-Package -Name Graphviz | Uninstall-Package

As you can see, it is very easy to not only install and remove PowerShell modules but also arbitrary executables and installers. PackageManagement in Windows supports MSI and MSU, for example, allowing you to even uninstall update packages:


The PackageManagement and PowerShellGet cmdlets not only allow you to install and remove packages, but also help when upgrading them. PowerShell modules will be stored in a new version folder thanks to side-by-side installations. In your scripts and DSC configurations, you can use specific versions of modules in case you have downloaded some unstable releases.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset