< Back

Register-AzureArtifactsPSRepository

Sat Jan 11, 2020 10:10 am

NAME Register-AzureArtifactsPSRepository



SYNOPSIS

Registers a PSRepository to the given Azure Artifacts feed if one does not already exist.

Also installs the latest NuGet Package Provider and PowerShellGet module if necessary, which are required by other

cmdlets in the module.





SYNTAX

Register-AzureArtifactsPSRepository [-FeedUrl] <String> [-RepositoryName <String>] [-Credential <PSCredential>]

[-Scope <String>] [<CommonParameters>]





DESCRIPTION

Registers a PSRepository to the given Azure Artifacts feed if one does not already exist.

If a PSRepository to the provided feed already exists, it will return the existing PSRepository's name, rather

than creating a new one and using the RepositoryName parameter (if provided).



The cmdlet also installs the latest NuGet Package Provider and PowerShellGet module if necessary, which are

required by other cmdlets in the module.





PARAMETERS

-FeedUrl <String>



Required? true

Position? 1

Default value

Accept pipeline input? true (ByValue, ByPropertyName)

Accept wildcard characters? false



-RepositoryName <String>



Required? false

Position? named

Default value

Accept pipeline input? true (ByPropertyName)

Accept wildcard characters? false



-Credential <PSCredential>



Required? false

Position? named

Default value

Accept pipeline input? true (ByPropertyName)

Accept wildcard characters? false



-Scope <String>



Required? false

Position? named

Default value CurrentUser

Accept pipeline input? true (ByPropertyName)

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

FeedUrl: (Required) The URL of the Azure Artifacts PowerShell feed to register. e.g.

https://pkgs.dev.azure.com/YourOrganiza ... d/nuget/v2. Note: PowerShell does not yet support

the "/v3" endpoint, so use v2.



RepositoryName: The name to use for the PSRepository if one must be created. If not provided, one will be

generated. A PSRepository with the given name will only be created if one to the Feed URL does not already exist.



Credential: The credential to use to connect to the Azure Artifacts feed. This should be created from a personal

access token that has at least Read permissions to the Azure Artifacts feed. If not provided, the

VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable will be checked, as per

https://github.com/Microsoft/artifacts- ... -variables.



Scope: If the NuGet Package Provider or PowerShellGet module needs to be installed, this is the scope it will be

installed in. Allowed values are "AllUsers" and "CurrentUser". Default is "CurrentUser".





OUTPUTS

System.String

Returns the Name of the PSRepository that can be used to connect to the given Feed URL.





NOTES





If a Credential is not provided, it will attempt to retrieve a PAT from the environment variables, as per

https://github.com/Microsoft/artifacts- ... -variables



This function writes to the error, warning, and information streams in different scenarios, as well as may

throw exceptions for catastrophic errors.



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>```



[string] $repositoryName = Register-AzureArtifactsPSRepository -FeedUrl

https://pkgs.dev.azure.com/YourOrganiza ... d/nuget/v2 -RepositoryName 'MyAzureArtifacts'

```

Attempts to create a PSRepository to the given FeedUrl if one doesn't exist.

If one does not exist, one will be created with the name `MyAzureArtifacts`.

If one already exists, it will simply return the name of the existing PSRepository, rather than the provided one.

Since no Credential was provided, it will attempt to retrieve a PAT from the environmental variables.

The name of the PSRepository to the FeedUrl is returned.



```

[System.Security.SecureString] $securePersonalAccessToken = 'YourPatGoesHere' | ConvertTo-SecureString

-AsPlainText -Force

[System.Management.Automation.PSCredential] $Credential = New-Object System.Management.Automation.PSCredential

'Username@DoesNotMatter.com', $securePersonalAccessToken

[string] $feedUrl = 'https://pkgs.dev.azure.com/YourOrganiza ... d/nuget/v2'

[string] $repositoryName = Register-AzureArtifactsPSRepository -Credential $credential -FeedUrl $feedUrl

```

Attempts to create a PSRepository to the given FeedUrl if one doesn't exist, using the Credential provided.











RELATED LINKS