Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Windows Server 2019 Automation with PowerShell Cookbook

You're reading from   Windows Server 2019 Automation with PowerShell Cookbook Powerful ways to automate and manage Windows administrative tasks

Arrow left icon
Product type Paperback
Published in Feb 2019
Publisher Packt
ISBN-13 9781789808537
Length 542 pages
Edition 3rd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Thomas Lee Thomas Lee
Author Profile Icon Thomas Lee
Thomas Lee
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Establishing a PowerShell Administrative Environment FREE CHAPTER 2. Managing Windows Networking 3. Managing Windows Active Directory 4. Managing Windows Storage 5. Managing Shared Data 6. Managing Windows Update 7. Managing Printing 8. Introducing Containers 9. Managing Windows Internet Information Server 10. Managing Desired State Configuration 11. Managing Hyper-V 12. Managing Azure 13. Managing Performance and Usage 14. Troubleshooting Windows Server Index

Exploring package management

The PackageMangement PowerShell module implements a provider interface that software package management systems use to manage software packages. You can use the cmdlets in the PackageMangement module to work with a variety of package management systems. You can think of this module as providing an API to package management providers such as PowerShellGet, discussed in the Exploring PowerShellGet and PowerShell Gallery recipe.

The key function of the PackageMangement module is to manage the set of software repositories in which package management tools can search, obtain, install, and remove packages. The module enables you to discover and utilize software packages from a variety of sources (and potentially varying in quality).

This recipe explores the PackageManagement module from SRV1.

Getting ready

This recipe uses SRV1—a domain-joined server that you partially configured in the Installing RSAT Tools on Windows 10 and Windows Server 2019 recipe.

How to do it...

  1. Review the cmdlets in the PackageManagement module:
    Get-Command -Module PackageManagement
  2. Review the installed providers with Get-PackageProvider:
    Get-PackageProvider |
      Format-Table -Property Name,
                             Version,
                             SupportedFileExtensions,
                             FromtrustedSource
  3. Get details of a packages loaded on SRV1 of the MSU type (representing Microsoft Updates downloaded by Windows Update):
    Get-Package -ProviderName 'msu' |
      Select-Object -ExpandProperty Name
  4. Get details of the NuGet provider, which provides access to developer library packages. This step also loads the NuGet provider if it is not already installed:
    Get-PackageProvider -Name NuGet -ForceBootstrap
  5. Display the other package providers available on SRV1:
    Find-PackageProvider |
      Select-Object -Property Name,Summary |
        Format-Table -Wrap -AutoSize
  6. Chocolatey is a popular repository for Windows administrators and power users. You have to install the provider before you can use it, as follows:
    Install-PackageProvider -Name Chocolatey -Force
  7. Verify that the Chocolatey provider is now available:
    Get-PackageProvider | Select-Object -Property Name,Version
  8. Display the packages now available in Chocolatey:
    $Packages = Find-Package -ProviderName Chocolatey
    "$($Packages.Count) packages available from Chocolatey"

How it works...

In step 1, you review the cmdlets contained in the PackageManagement module, which looks like this:

How it works...

In step 2, you review the package providers installed by default in Windows Server 2019, which looks like this:

How it works...

In step 3, you examined the packages downloaded by the msu provider. In this case, you only see one update, but you may see more, and it looks like this:

How it works...

In step 4, you examine details of the NuGet provider. If the provider doesn't exist, then using the -ForceBootstrap parameter installs the provider without asking for confirmation, like this:

How it works...

In step 5, you search for additional package providers, like this:

How it works...

In step 6, you install the Chocolatey package provider, which looks like this:

How it works...

In step 7, you examine the list of package providers now available to confirm that the Chocolatey provider is available, which looks like this:

How it works...

In step 8, you check to see how many packages are available to download from Chocolatey, as follows:

How it works...

There's more...

In step 6, you installed the Chocolatey package provider. To see more details about what Install-PackageProvider is doing, run this step with the -Verbose flag.

You have been reading a chapter from
Windows Server 2019 Automation with PowerShell Cookbook - Third Edition
Published in: Feb 2019
Publisher: Packt
ISBN-13: 9781789808537
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image