diff --git a/Vagrantfile b/Vagrantfile index f0e7d40..d073a52 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -48,8 +48,10 @@ Vagrant.configure(2) do |config| config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['provision-base.ps1', nexus_domain] config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['provision-chocolatey.ps1'] config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['provision-powershellget.ps1'] + config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['provision-psresourceget.ps1'] config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['use-chocolatey-repository.ps1', nexus_domain] - config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['use-powershell-repository.ps1', nexus_domain] + config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['use-powershell-repository-powershellget.ps1', nexus_domain] + config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['use-powershell-repository-psresourceget.ps1', nexus_domain] config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['use-npm-repository.ps1', nexus_domain] end diff --git a/provision/windows/provision-psresourceget.ps1 b/provision/windows/provision-psresourceget.ps1 new file mode 100644 index 0000000..eb25923 --- /dev/null +++ b/provision/windows/provision-psresourceget.ps1 @@ -0,0 +1,13 @@ +# install PSResourceGet (previously known as PowerShellGet 3.x). +# see https://learn.microsoft.com/en-us/powershell/gallery/powershellget/install-powershellget?view=powershellget-3.x +# see https://github.com/PowerShell/PSResourceGet + +# see https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet +# renovate: datasource=nuget:powershellgallery depName=Microsoft.PowerShell.PSResourceGet +$psResourceGetModuleVersion = '1.2.0' +Write-Host "Installing PSResourceGet $psResourceGetModuleVersion..." +Install-Module ` + -Repository PSGallery ` + -Name Microsoft.PowerShell.PSResourceGet ` + -RequiredVersion $psResourceGetModuleVersion ` + -Force diff --git a/provision/windows/use-powershell-repository.ps1 b/provision/windows/use-powershell-repository-powershellget.ps1 similarity index 100% rename from provision/windows/use-powershell-repository.ps1 rename to provision/windows/use-powershell-repository-powershellget.ps1 diff --git a/provision/windows/use-powershell-repository-psresourceget.ps1 b/provision/windows/use-powershell-repository-psresourceget.ps1 new file mode 100644 index 0000000..e65c354 --- /dev/null +++ b/provision/windows/use-powershell-repository-psresourceget.ps1 @@ -0,0 +1,66 @@ +param( + [string]$nexusDomain = 'nexus.example.com' +) + +Write-Host 'Default PSResourceGet repositories:' +Get-PSResourceRepository + +Write-Host "Unregistering the default PSResourceGet sources..." +Get-PSResourceRepository | Unregister-PSResourceRepository + +Write-Host 'Configuring PSResourceGet to only use the nexus server...' +Register-PSResourceRepository ` + -Name nexus ` + -Uri https://$nexusDomain/repository/powershell-hosted/index.json ` + -ApiVersion V3 ` + -Trusted + +Write-Host 'Current PSResourceGet repositories:' +Get-PSResourceRepository + +Write-Host 'Publishing the ExampleGreeter module into the nexus server...' +Set-Location $env:TEMP +mkdir ExamplePSResourceGreeter | Out-Null +Push-Location ExamplePSResourceGreeter +Set-Content ` + -Encoding Ascii ` + ExamplePSResourceGreeter.psm1 ` + @' +function Write-ExamplePSResourceGreeting([string]$name) { + "Hello $name!" +} +'@ +New-ModuleManifest ` + ExamplePSResourceGreeter.psd1 ` + -ModuleVersion '1.0.0' ` + -Author 'John Doe' ` + -Description 'The Classic Hello World' ` + -LicenseUri 'https://opensource.org/licenses/MIT' ` + -ProjectUri 'https://example.com/ExamplePSResourceGreeter' ` + -RootModule 'ExamplePSResourceGreeter.psm1' ` + -Tags ` + hello, + example ` + -FunctionsToExport ` + Write-ExamplePSResourceGreeting ` + -CmdletsToExport @() ` + -VariablesToExport @() ` + -AliasesToExport @() +Test-ModuleManifest ExamplePSResourceGreeter.psd1 +Publish-PSResource ` + -Repository nexus ` + -ApiKey (Get-Content c:\vagrant\shared\jenkins-nuget-api-key) ` + -Path . +Pop-Location + +Write-Host 'Installing and using the ExamplePSResourceGreeter module...' +Install-PSResource ExamplePSResourceGreeter +Get-PSResource ExamplePSResourceGreeter | Format-List +Get-Module ExamplePSResourceGreeter -ListAvailable | Format-List + +Write-Host 'Using the ExamplePSResourceGreeter module...' +Import-Module ExamplePSResourceGreeter +Write-ExamplePSResourceGreeting 'World' + +Write-Host 'Uninstalling the ExamplePSResourceGreeter module...' +Uninstall-PSResource ExamplePSResourceGreeter