Working with local PSRepositories - PowerShell (2024)

  • Article

The PowerShellGet module support repositories other than the PowerShell Gallery.These cmdlets enable the following scenarios:

  • Support a trusted, pre-validated set of PowerShell modules for use in your environment
  • Testing a CI/CD pipeline that builds PowerShell modules or scripts
  • Deliver PowerShell scripts and modules to systems that can't access the internet
  • Deliver PowerShell scripts and modules only available to your organization

This article describes how to set up a local PowerShell repository. The article also covers theOfflinePowerShellGetDeploy module available from the PowerShell Gallery. This module containscmdlets to install the latest version of PowerShellGet into your local repository.

Local repository types

There are two ways to create a local PSRepository: NuGet server or file share. Each type hasadvantages and disadvantages:

NuGet Server

AdvantagesDisadvantages
Mimics PowerShellGallery functionalityMulti-tier app requires operations planning & support
NuGet integrates with Visual Studio, other toolsAuthentication model and NuGet accounts management needed
NuGet supports metadata in .Nupkg packagesPublishing requires API Key management & maintenance
Provides search, package administration, etc.
AdvantagesDisadvantages
Easy to set up, back up, and maintainNo UI beyond basic file share
Simple security model - user permissions on the shareLimited security and no recording of who updates what
No constraints such as replacing existing items

PowerShellGet works with either type and supports locating versions and dependency installation.However, some features that work for the PowerShell Gallery aren't available for base NuGet serversor file shares. There is no differentiation of scripts, modules, DSC resources, or rolecapabilities.

Creating a NuGet.Server repository

The following article lists the steps for setting up your own NuGet Server.

  • NuGet.Server

Follow the steps up to the point of adding packages. The steps for publishing a package arecovered later in this article.

For a file share-based repository, make sure that your users have permissions to access the fileshare.

Registering a local repository

Before a repository can be used, it must be registered using the Register-PSRepository command. Inthe examples below, the InstallationPolicy is set to Trusted, on the assumption that you trustyour own repository.

# Register a NuGet-based server$registerPSRepositorySplat = @{ Name = 'LocalPSRepo' SourceLocation = 'http://MyLocalNuget/Api/V2/' ScriptSourceLocation = 'http://MyLocalNuget/Api/V2' InstallationPolicy = 'Trusted'}Register-PSRepository @registerPSRepositorySplat# Register a file share on my local machine$registerPSRepositorySplat = @{ Name = 'LocalPSRepo' SourceLocation = '\\localhost\PSRepoLocal\' ScriptSourceLocation = '\\localhost\PSRepoLocal\' InstallationPolicy = 'Trusted'}Register-PSRepository @registerPSRepositorySplat

Take note of the difference between how the two commands handle ScriptSourceLocation. For a fileshare-based repositories, the SourceLocation and ScriptSourceLocation must match. For aweb-based repository, they must be different, so in this example a trailing "/" is added to theSourceLocation.

When using a file sharing protocol, like NFS or SMB, be sure to follow the recommended guidance forsecuring the protocol. For more information about securing SMB on Windows, see[SMB security enhancements][09].

If you want the newly created PSRepository to be the default repository, you must unregister allother PSRepositories. For example:

Unregister-PSRepository -Name PSGallery

Note

The repository name 'PSGallery' is reserved for use by the PowerShell Gallery. You canunregister PSGallery, but you can't reuse the name PSGallery for any other repository.

If you need to restore the PSGallery, run the following command:

Register-PSRepository -Default

Publishing to a local repository

Once you've registered the local PSRepository, you can publish to your local PSRepository. There aretwo main publishing scenarios: publishing your own module and publishing a module from thePSGallery.

Publishing a module you authored

Use Publish-Module and Publish-Script to publish your module to your local PSRepository the sameway you do for the PowerShell Gallery.

  • Specify the location for your code
  • Supply an API key
  • Specify the repository name. For example, -PSRepository LocalPSRepo

Note

You must create an account in the NuGet server, then sign in to generate and save the API key. Fora file share, use any non-blank string for the NuGetApiKey value.

Examples:

# Publish to a NuGet Server repository using my NuGetAPI key$publishModuleSplat = @{ Path = 'c:\projects\MyModule' Repository = 'LocalPsRepo' NuGetApiKey = $nuGetApiKey}Publish-Module @publishModuleSplat

Important

To ensure security, API keys shouldn't be hard-coded in scripts. Use a secure key managementsystem. When executing a command manually, API keys shouldn't be passed as plain-text to avoid itbeing logged, the Read-Host cmdlet can be used to safely pass the value of the API key.

# Publish to a file share repo - the NuGet API key must be a non-blank string$publishModuleSplat = @{ Path = 'c:\projects\MyModule' Repository = 'LocalPsRepo' NuGetApiKey = 'AnyStringWillDo'}Publish-Module @publishModuleSplat

Publishing a module from the PSGallery

To publish a module from the PSGallery to your local PSRepository, you can use the Save-Packagecmdlet.

  • Specify the Name of the Package
  • Specify 'NuGet' as the Provider
  • Specify the PSGallery location as the source (https://www.powershellgallery.com/api/v2)
  • Specify the path to your local Repository

Example:

# Publish from the PSGallery to your local Repository$savePackageSplat = @{ Name = 'PackageName' ProviderName = 'NuGet' Source = 'https://www.powershellgallery.com/api/v2' Path = '\\localhost\PSRepoLocal\'}Save-Package @savePackageSplat

If your local PSRepository is web-based, it requires an additional step that uses nuget.exe topublish. See the documentation for using nuget.exe.

Installing PowerShellGet on a disconnected system

Deploying PowerShellGet is difficult in environments that require systems to be disconnected fromthe internet. PowerShellGet has a bootstrap process that installs the latest version the first timeit's used. The OfflinePowerShellGetDeploy module in the PowerShell Gallery provides cmdlets thatsupport this bootstrap process.

To bootstrap an offline deployment, you need to:

  • Download and install the OfflinePowerShellGetDeploy your internet-connected system and yourdisconnected systems
  • Download PowerShellGet and its dependencies on the internet-connected system using theSave-PowerShellGetForOffline cmdlet
  • Copy PowerShellGet and its dependencies from the internet-connected system to the disconnectedsystem
  • Use the Install-PowerShellGetOffline on the disconnected system to place PowerShellGet and itsdependencies into the proper folders

The following commands use Save-PowerShellGetForOffline to put all the components into a folderf:\OfflinePowerShellGet

# Requires -RunAsAdministrator#Download the OfflinePowerShellGetDeploy to a location that can be accessed# by both the connected and disconnected systems.Save-Module -Name OfflinePowerShellGetDeploy -Path 'F:\' -Repository PSGalleryImport-Module F:\OfflinePowerShellGetDeploy# Put PowerShellGet somewhere locallySave-PowerShellGetForOffline -LocalFolder 'F:\OfflinePowerShellGet'

At this point, you must make the contents of F:\OfflinePowerShellGet available to yourdisconnected systems. Run the Install-PowerShellGetOffline cmdlet to install PowerShellGet on thedisconnected system.

Note

It's important that you don't run PowerShellGet in the PowerShell session before running thesecommands. Once PowerShellGet is loaded into the session, the components can't be updated. If youdo start PowerShellGet by mistake, exit and restart PowerShell.

Import-Module F:\OfflinePowerShellGetDeployInstall-PowerShellGetOffline -LocalFolder 'F:\OfflinePowerShellGet'

After running these commands, you are ready to publish PowerShellGet to your local repository.

# Publish to a NuGet Server repository using my NuGetAPI key$publishModuleSplat = @{ Path = 'F:\OfflinePowershellGet' Repository = 'LocalPsRepo' NuGetApiKey = $nuGetApiKey}Publish-Module @publishModuleSplat

Important

To ensure security, API keys shouldn't be hard-coded in scripts. Use a secure key managementsystem. When executing a command manually, API keys shouldn't be passed as plain-text to avoid itbeing logged, the Read-Host cmdlet can be used to safely pass the value of the API key.

# Publish to a file share repo - the NuGet API key must be a non-blank string$publishModuleSplat = @{ Path = 'F:\OfflinePowerShellGet' Repository = 'LocalPsRepo' NuGetApiKey = 'AnyStringWillDo'}Publish-Module @publishModuleSplat

Use Packaging solutions to host PowerShellGet repositories

You can also use packaging solutions like Azure Artifacts to host a private or public PowerShellGetrepository. For more information and instructions, see the Azure Artifacts documentation.

Working with local PSRepositories - PowerShell (2024)
Top Articles
filthy rich werewolves by taylor caine
The Libraries Consortium
排期 一亩三分地
Extranet Landing Page Delta
Best Pre Med Schools U.s. News
Busted Newspaper Birmingham Al
Wyze Thermostat vs Nest: Detailed Comparison
Mta Bus Time Q85
Lowes Maytag Pet Pro Commercial Actress
Thomas the Tank Engine
Teen Movie Night at Kimball Junction (Percy Jackson and the Lightning Thief)
Brookdale Okta Login
Ff14 Cloth Softening Powder
Ice Crates Terraria
Aluminum Model Toys
Dawat Restaurant Novi
Ck3 Culture Map
Arsenal news LIVE: Latest updates from the Emirates
Hose Woe Crossword Clue
Kaelis Dahlias
Rubios Listens Com
Horseheads Schooltool
Courtney Lynn Playboy
Ethos West Mifflin
Mybackpack Bolles
Lil Coffea Shop 6Th Ave Photos
Keanu Reeves cements his place in action genre with ‘John Wick: Chapter 4’
2005 Volvo XC 70 XC90 V70 SUV Wagon for sale by owner - Banning, CA - craigslist
Anker GaNPrime™️ | Our Best Multi-Device Fast Charging Lineup
Target Savannah Mall Evicted
Tcu Jaggaer
Solve x^2+2x-24=0 | Microsoft Math Solver
MAELLE MAGNETISEUSE A ST-MALO ATTENUE VOTRE LUMBAGO
Managementassistent directie Wonen
Did You Hear About Worksheet Answers Page 211
My Perspectives Grade 10 Volume 1 Answer Key Pdf
Pre-Order Apple Watch Series 10 – Best Prices in Dubai, UAE
Sour Power OG (Karma Genetics) :: Cannabis Strain Info
Limestone Bank Hillview
Gowilkes For Rent
Uncg Directions
Gen 50 Kjv
Sona Systems Tcu
Bonbast قیمت ارز
3143656395
Olive Onyx Amora
Can You Change Your Breathing Style In Demonfall
Al Horford House Brookline
American Medical Response hiring EMT Basic - Bridgeport in Bridgeport, CT | LinkedIn
Caldo Tlalpeño de Pollo: Sabor Mexicano - Paulina Cocina
Dumb Money Showtimes Near Cinema Cafe - Edinburgh
Highplainsobserverperryton
Latest Posts
Article information

Author: Kareem Mueller DO

Last Updated:

Views: 6091

Rating: 4.6 / 5 (66 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Kareem Mueller DO

Birthday: 1997-01-04

Address: Apt. 156 12935 Runolfsdottir Mission, Greenfort, MN 74384-6749

Phone: +16704982844747

Job: Corporate Administration Planner

Hobby: Mountain biking, Jewelry making, Stone skipping, Lacemaking, Knife making, Scrapbooking, Letterboxing

Introduction: My name is Kareem Mueller DO, I am a vivacious, super, thoughtful, excited, handsome, beautiful, combative person who loves writing and wants to share my knowledge and understanding with you.