PowerShellGallery.psm1
[CmdletBinding()] param() $baseName = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath) $script:PSModuleInfo = Test-ModuleManifest -Path "$PSScriptRoot\$baseName.psd1" $script:PSModuleInfo | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ } $scriptName = $script:PSModuleInfo.Name Write-Debug "[$scriptName] - Importing module" #region [functions] - [private] Write-Debug "[$scriptName] - [functions] - [private] - Processing folder" #region [functions] - [private] - [Get-PSGalleryResource] Write-Debug "[$scriptName] - [functions] - [private] - [Get-PSGalleryResource] - Importing" function Get-PSGalleryResource { <# .SYNOPSIS Get a resource from the PowerShell Gallery. .DESCRIPTION Long description .EXAMPLE Get-PSGalleryResource -Name 'MyModule' -Version '1.0.0' .NOTES General notes #> [CmdletBinding()] param ( # Name of the module. [Parameter(Mandatory)] [string] $Name, # The API key for the PowerShell Gallery. [Parameter(Mandatory)] [string] $APIKey ) $uri = "https://www.powershellgallery.com/packages/$Name" $body = @{ __RequestVerificationToken = $APIKey } Invoke-RestMethod -Uri $uri -Method Get -Body $body } Write-Debug "[$scriptName] - [functions] - [private] - [Get-PSGalleryResource] - Done" #endregion [functions] - [private] - [Get-PSGalleryResource] #region [functions] - [private] - [Update-PSGalleryResourceListing] Write-Debug "[$scriptName] - [functions] - [private] - [Update-PSGalleryResourceListing] - Importing" function Update-PSGalleryResourceListing { <# .SYNOPSIS Updates the listing status of a module on the PowerShell Gallery. .EXAMPLE Update-PSGalleryResourceListing -Name 'MyModule' -Version '1.0.0' -Listed $true -APIKey 'myapikey' #> [CmdletBinding(SupportsShouldProcess)] param ( # Name of the module. [Parameter(Mandatory)] [string] $Name, # Version of the module. [Parameter(Mandatory)] [string] $Version, # Whether the module is listed on the PowerShell Gallery. [Parameter(Mandatory)] [bool] $Listed, # API key for the PowerShell Gallery. [Parameter(Mandatory)] [string] $APIKey ) $uri = "https://www.powershellgallery.com/packages/$Name/$Version/UpdateListed" $body = @{ __RequestVerificationToken = $APIKey Version = $Version Listed = $Listed } if ($PSCmdlet.ShouldProcess("module [$Name]", 'Update listing status')) { Invoke-RestMethod -Uri $uri -Method Post -Body $body } } Write-Debug "[$scriptName] - [functions] - [private] - [Update-PSGalleryResourceListing] - Done" #endregion [functions] - [private] - [Update-PSGalleryResourceListing] Write-Debug "[$scriptName] - [functions] - [private] - Done" #endregion [functions] - [private] #region [functions] - [public] Write-Debug "[$scriptName] - [functions] - [public] - Processing folder" #region [functions] - [public] - [Get-PSGalleryAPI] Write-Debug "[$scriptName] - [functions] - [public] - [Get-PSGalleryAPI] - Importing" function Get-PSGalleryAPI { <# .SYNOPSIS Get the PowerShell Gallery API. #> [CmdletBinding()] param() Invoke-RestMethod -Method Get -Uri 'https://www.powershellgallery.com/api/v2/' -ContentType 'application/json' } Write-Debug "[$scriptName] - [functions] - [public] - [Get-PSGalleryAPI] - Done" #endregion [functions] - [public] - [Get-PSGalleryAPI] #region [functions] - [public] - [Hide-PowerShellGalleryItem] Write-Debug "[$scriptName] - [functions] - [public] - [Hide-PowerShellGalleryItem] - Importing" function Hide-PowerShellGalleryItem { <# .SYNOPSIS Unlist a package on the PowerShell Gallery. #> [CmdletBinding()] [Alias('Unlist-PowerShellGalleryItem')] param () Write-Warning 'This cmdlet is not yet implemented.' } Write-Debug "[$scriptName] - [functions] - [public] - [Hide-PowerShellGalleryItem] - Done" #endregion [functions] - [public] - [Hide-PowerShellGalleryItem] #region [functions] - [public] - [Show-PowerShellGalleryItem] Write-Debug "[$scriptName] - [functions] - [public] - [Show-PowerShellGalleryItem] - Importing" function Show-PowerShellGalleryItem { <# .SYNOPSIS List a package on the PowerShell Gallery. #> [CmdletBinding()] [Alias('List-PowerShellGalleryItem')] param () Write-Warning 'This cmdlet is not yet implemented.' } Write-Debug "[$scriptName] - [functions] - [public] - [Show-PowerShellGalleryItem] - Done" #endregion [functions] - [public] - [Show-PowerShellGalleryItem] Write-Debug "[$scriptName] - [functions] - [public] - Done" #endregion [functions] - [public] #region Member exporter $exports = @{ Alias = '*' Cmdlet = '' Function = @( 'Get-PSGalleryAPI' 'Hide-PowerShellGalleryItem' 'Show-PowerShellGalleryItem' ) } Export-ModuleMember @exports #endregion Member exporter |