PowerShellGallery.psm1
[CmdletBinding()] param() $scriptName = 'PowerShellGallery' Write-Verbose "[$scriptName] - Importing module" #region - From [functions] - [private] Write-Verbose "[$scriptName] - [functions] - [private] - Processing folder" #region - From [functions] - [private] - [Get-PSGalleryResource] Write-Verbose "[$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-Verbose "[$scriptName] - [functions] - [private] - [Get-PSGalleryResource] - Done" #endregion - From [functions] - [private] - [Get-PSGalleryResource] #region - From [functions] - [private] - [Update-PSGalleryResourceListing] Write-Verbose "[$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-Verbose "[$scriptName] - [functions] - [private] - [Update-PSGalleryResourceListing] - Done" #endregion - From [functions] - [private] - [Update-PSGalleryResourceListing] Write-Verbose "[$scriptName] - [functions] - [private] - Done" #endregion - From [functions] - [private] #region - From [functions] - [public] Write-Verbose "[$scriptName] - [functions] - [public] - Processing folder" #region - From [functions] - [public] - [Get-PSGalleryAPI] Write-Verbose "[$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-Verbose "[$scriptName] - [functions] - [public] - [Get-PSGalleryAPI] - Done" #endregion - From [functions] - [public] - [Get-PSGalleryAPI] #region - From [functions] - [public] - [Hide-PowerShellGalleryItem] Write-Verbose "[$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-Verbose "[$scriptName] - [functions] - [public] - [Hide-PowerShellGalleryItem] - Done" #endregion - From [functions] - [public] - [Hide-PowerShellGalleryItem] #region - From [functions] - [public] - [Show-PowerShellGalleryItem] Write-Verbose "[$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-Verbose "[$scriptName] - [functions] - [public] - [Show-PowerShellGalleryItem] - Done" #endregion - From [functions] - [public] - [Show-PowerShellGalleryItem] Write-Verbose "[$scriptName] - [functions] - [public] - Done" #endregion - From [functions] - [public] $exports = @{ Alias = '*' Cmdlet = '' Function = @( 'Get-PSGalleryAPI' 'Hide-PowerShellGalleryItem' 'Show-PowerShellGalleryItem' ) } Export-ModuleMember @exports |