Powershell Packages Management

2024-06-21

All articles from this blog can ONLY be redistributed on an Attribution-NonCommercial-NoDerivs basis. Please credit the source, thank you.
Twitter:@kelvinshen
Blog:Kelvin Shen's Blog

Introduction

Powershell packages are very powerful

An Example

Install-Module -name Microsoft.PowerPlatform.DevOps
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Import-Module Microsoft.PowerPlatform.DevOps

What is the difference between the Install-Module command and the Import-Module command?

Install-Module downloads and installs a PowerShell module from a repository, such as the PowerShell Gallery, to your local computer. This makes the module’s files available on your system in one of the PowerShell module paths (e.g., C:\Program Files\WindowsPowerShell\Modules or C:\Users<YourUsername>\Documents\WindowsPowerShell\Modules).

What does Install-Module work under the hood?

PowerShellGet is a PowerShell module provides a set of cmdlets, including Install-Module, Find-Module, Update-Module, and Uninstall-Module, among others.

The PowerShellGet module uses the NuGet provider to interact with the PowerShell Gallery. If you don’t have NuGet provider installed, powershell will prompt you to install one upon running the Install-Module command.

How to package a NuGet package for PowerShell module distribution?

  1. Create your PowerShell module with a .psm1 script and .psd1 manifest.
  2. Organize the module files in the appropriate directory structure.
  3. Create a .nuspec file containing metadata about your module.
  4. Use the NuGet CLI to create the NuGet package.
  5. Publish the NuGet package to the PowerShell Gallery using Publish-Module.

Leave a Reply

comments powered by Disqus


Table of Content