OpsaC - Operating as PowerShell code
published: March 4, 2022 author: Tinu tags: PowerShell categories: PowerShell-Module
Working with Private PowerShellGet Repositories
NuGet.exe must be available in:
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 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'
$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 ]
<#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"
}