Connect-CustomPSRepository.ps1


<#PSScriptInfo
 
.VERSION 1.0
 
.GUID 26d77f0d-0f7c-4a80-b5ee-94b06550dbe3
 
.AUTHOR jodelac@Microsoft.com
 
.COMPANYNAME Microsoft Modern Applications Domain
 
.COPYRIGHT
 
.TAGS PSRepository ADO Azure DevOps
 
.LICENSEURI https://mit-license.org
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
.PRIVATEDATA
 
#>


<#
 
.DESCRIPTION
 Registers a custom PSRepository to your powershell user account sessions
 
 .PARAMETER repositoryUri
 (Required) The full url of the repository, this is the same as the NUGET feed URL. Just noticed that Powershell as of this push doesn't support NUGET V3 so you have to use the V2 of the API.
 
 .PARAMETER name
 (Required) The name you want to give to your gallery.
 
 .EXAMPLE
 
    PS > Connect-CustomPSRepository -repositoryUri https://api.nuget.org/v2/ -name NUGETGallery
 
#>
 
Param(
    [Parameter(Mandatory = $true)][uri]$repositoryUri,
    [Parameter(Mandatory = $true)][string]$name
)

$null = @(
Get-PSRepository -Name $name -ErrorAction SilentlyContinue

$uri = $repositoryUri.ToString() 
$repo = @{
Name = $name
SourceLocation = $uri
PublishLocation = $uri
InstallationPolicy = 'Trusted'
}

Register-PSRepository @repo -ErrorAction SilentlyContinue
)
exit 0