Skip to content

Instantly share code, notes, and snippets.

@CosmosKey
Created February 16, 2017 12:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save CosmosKey/999990845d5ec2cf46288ffedc56a7dc to your computer and use it in GitHub Desktop.
Save CosmosKey/999990845d5ec2cf46288ffedc56a7dc to your computer and use it in GitHub Desktop.
PowerShellGet - Setup a local repository demo
###############################################################
#
# A quick look at setting up local PowerShellGet repositories
#
###############################################################
#
# Find and install a module from PSGallery
#
Find-Module ImportExcel | Install-Module -Force -Verbose
Get-Command -Module ImportExcel -Noun Excel
#
# Create folders and a share for our PSGet Repository
#
$repo = New-Item -Path C:\LocalPSRepository -ItemType Directory -Force
$psmodRoot = New-Item -Path C:\TempModulePath\MyCimUtils -ItemType Directory -Force
New-SmbShare -Name LocalPSRepository -Path $repo -FullAccess everyone
# Create a new CIM utility module
{
function Get-CimNamespace {
[cmdletbinding()]
param([string]$NameSpace = "root")
Get-CimInstance -Class __Namespace -Namespace $NameSpace | ForEach-Object {
Get-CimNamespace -NameSpace ($NameSpace,$_.Name -join "\")
}
$NameSpace
}
} | Out-File "$psmodRoot\MyCimUtils.psm1"
# Create a module manifest
$manifestParam = @{
Path = "$psmodRoot\MyCimUtils.psd1"
RootModule = "MyCimUtils.psm1"
ModuleVersion = "0.0.0.1"
FunctionsToExport = "Get-CimNamespace"
Description = "A CIM Utility module"
Author = "Johan Åkerström"
}
New-ModuleManifest @manifestParam
# Is the new module there?
Get-Module MyCimUtils -ListAvailable
$originalModulePath = $env:PSModulePath
$env:PSModulePath = "$env:PSModulePath;$psmodRoot"
Get-Module MyCimUtils -ListAvailable
dir $psmodRoot
#
# Now to the fun part. Lets create a local PSGet repository
#
Get-PSRepository
$registerRepoParam = @{
Name = "LocalPSRepository"
SourceLocation = "\\$env:COMPUTERNAME\LocalPSRepository\"
ScriptSourceLocation = "\\$env:COMPUTERNAME\LocalPSRepository\"
InstallationPolicy = "Trusted"
}
Register-PSRepository @registerRepoParam
Get-PSRepository
#
# Let's publish out module
#
Get-Module MyCimUtils -ListAvailable
Publish-Module -Name MyCimUtils -Repository LocalPSRepository
$env:PSModulePath = $originalModulePath
Get-Module MyCimUtils -ListAvailable
# Check the repository
dir $repo
Find-Module MyCimUtils
Find-Module MyCimUtils | Install-Module -Verbose
Get-Module MyCimUtils -ListAvailable
Get-Module MyCimUtils -ListAvailable | Select Name,Version,Path
Get-CimNamespace
# Enjoy!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment