Last active
August 21, 2018 12:37
-
-
Save adamrushuk/79c3a353e213d9b4c8d74c71b31a95a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Variables | |
$powershellGetVersion = '1.5.0.0' # DO NOT use the latest 1.6.0 version as there is issues with this process | |
$moduleFolderPath = 'C:\path\to\PowerShell\Module\FOLDER' # only target folder, NOT the .psm1 or .psd1 | |
$repositoryName = 'psmodules' | |
$feedUsername = 'NotChecked' | |
$PAT = 'abcdefghijklmnopqrstuv1234567890' # Enter your Personal Access Token | |
$packageSourceUrl = "https://ACCOUNTNAME.pkgs.visualstudio.com/_packaging/$repositoryName/nuget/v2" # Enter your VSTS AccountName (note: v2 Feed) | |
# This is downloaded during Step 3, but could also be "C:\Users\USERNAME\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe" | |
# if not running script as Administrator. | |
$nugetPath = 'C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe' | |
# Create credential | |
$password = ConvertTo-SecureString -String $PAT -AsPlainText -Force | |
$credential = New-Object System.Management.Automation.PSCredential ($feedUsername, $password) | |
# Step 1 | |
# Upgrade PowerShellGet | |
Install-Module PowerShellGet -RequiredVersion $powershellGetVersion -Force | |
Remove-Module PowerShellGet -Force | |
Import-Module PowerShellGet -RequiredVersion $powershellGetVersion -Force | |
# Step 2 | |
# Check NuGet is listed | |
Get-PackageProvider -Name 'NuGet' -ForceBootstrap | |
# Step 3 | |
# THIS WILL FAIL first time, so don't panic! | |
# Try to Publish a PowerShell module - this will prompt and download NuGet.exe, and fail publishing the module (we publish at the end) | |
$publishParams = @{ | |
Path = $moduleFolderPath | |
Repository = $repositoryName | |
NugetApiKey = 'VSTS' | |
Verbose = $true | |
} | |
Publish-Module @publishParams | |
# Step 4 | |
# Register NuGet Package Source | |
& $nugetPath Sources Add -Name $repositoryName -Source $packageSourceUrl -Username $feedUsername -Password $PAT | |
# Check new NuGet Source is registered | |
& $nugetPath Sources List | |
# Step 5 | |
# Register feed | |
$registerParams = @{ | |
Name = $repositoryName | |
SourceLocation = $packageSourceUrl | |
PublishLocation = $packageSourceUrl | |
InstallationPolicy = 'Trusted' | |
PackageManagementProvider = 'Nuget' | |
Credential = $credential | |
Verbose = $true | |
} | |
Register-PSRepository @registerParams | |
# Check new PowerShell Repository is registered | |
Get-PSRepository -Name $repositoryName | |
# Step 6 | |
# Publish PowerShell module (2nd time lucky!) | |
Publish-Module @publishParams |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment