Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View Tinus IT Wiki

View my Photo Website

Module & Script Management

published: March 4, 2022 author: Tinu tags: PowerShell categories: PowerShell-Module


Table of Contents

PowerShell Gallery API

Working with Private PowerShellGet Repositories

NuGet.exe must be available in:

  • C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\
  • C:\Users\info\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\
  • NuGet.exe can be downloaded from https://aka.ms/psget-nugetexe

HTTPS-Repository or an SMB-Share…

$Modules = @{
    Name                 = "HomeGallery"
    SourceLocation       = "\\Server\psrepo\modules"
    ScriptSourceLocation = "\\Server\psrepo\modules"
    InstallationPolicy   = 'Trusted'
}
$Scripts = @{
    Name                 = "HomeGallery"
    SourceLocation       = "\\Server\psrepo\scripts"
    ScriptSourceLocation = "\\Server\psrepo\scripts"
    InstallationPolicy   = 'Trusted'
}
Register-PSRepository @Modules
Register-PSRepository @Scripts
Get-PSRepository | Select-Object Name,Trusted,SourceLocation,ScriptSourceLocation,Registered,PackageManagementProvider | ft -a

Publish Modules

Publish a Module to a file share repo - the NuGet API key must be a non-blank string.

Publish-Module -Path 'D:\temp\PsNetTools' -Repository HomeGallery -NuGetApiKey 'AnyStringWillDo'

Publish Scripts

$Script  = 'Add-MongoDBDocument'
$Metadata = @{
    Version     = '1.0.0'
    Author      = 'it@martin-walther.ch'
    Guid        = New-Guid
    Description = 'Add a document in the inventory-table of the local MongoDB'
    Path        = "D:\temp\Database\$($Script).ps1"
}
Update-ScriptFileInfo @Metadata
Publish-Script -Path "D:\temp\Database\$($Script).ps1" -Repository HomeGallery -Force

[ Top ]

Script Template

<#PSScriptInfo

.VERSION 0.0.0

.GUID a9742dfa-3693-4538-ae02-851b26117334

.AUTHOR it@martin-walther.ch

.COMPANYNAME

.COPYRIGHT

.TAGS

.LICENSEURI

.PROJECTURI

.ICONURI

.EXTERNALMODULEDEPENDENCIES 

.REQUIREDSCRIPTS

.EXTERNALSCRIPTDEPENDENCIES

.RELEASENOTES


.PRIVATEDATA

#> 



<#

.DESCRIPTION 
Add a document in the inventory-table of the local MongoDB

.EXAMPLE
Add-MongoDBDocument -Document $Document

#> 

[CmdletBinding()]
param (
    [Parameter(
        Mandatory=$true,
        ValueFromPipeline=$true,
        ValueFromPipelineByPropertyName=$true,
        Position = 0
    )]
    [String[]] $InputString
)

begin {
    $StartTime = Get-Date
    $function = $($MyInvocation.MyCommand.Name)
    foreach($item in $PSBoundParameters.keys){
        $params = "$($params) -$($item) $($PSBoundParameters[$item])"
    }
    Write-Verbose "[Begin] $($function)$($params)"
    $ret = @()
}

process {
    $ret = foreach($item in $InputString){
        try{
            $item
        }catch{
            Write-Warning "$($function), $($item), $($_.Exception.Message)"
        }
    }
    return $ret
}

end {
    Write-Verbose "[End] $($function)"
    Write-Host "Duration: $(New-TimeSpan -Start $StartTime -End (Get-Date) | % { "{1:0}h {2:0}m {3:0}s {4:000}ms" -f $_.Days, $_.Hours, $_.Minutes, $_.Seconds, $_.Milliseconds })`n"
}

← Previous Post [ Top ] Copyright © 2024 by tinuwalther [ Blog ] Next Post →