I am using Visual Studio Team Services (VSTS) hosted build agents in my build process. My builds mostly rely on the 'PowerShell' step that calls a script that I have in git. From within this script, I would like to manage PowerShell modules using PowerShellGet. For example, I would like to be able to install pscx simply by running
Install-Module -Name pscx
Unfortunately, hosted agents use PowerShell 4 and they don't have the PowerShellGet
module installed. As a result, the Install-Module
function is not available.
Anybody has any suggestion to use the PowerShellGet module on VSTS hosted agent? Note that since I don't have admin rights on this machine, I can't install the msi that installs PowerShellGet for PowerShell 4.
To be able to use PowerShellGet, two PowerShell modules are required:
These are available out of the box with PowerShell 5 or through the msi installer available on the PowerShell Gallery.
Instead of deploying these modules through the msi, you can simply add them to your git repository (ex: in a folder named
PsModules
). You will be able to get a hand on these modules on a machine that has either PS5 or the msi installed. They are usually in theC:\Program Files\WindowsPowerShell\Modules
folder.Then, add the
PsModules
folders to your PSModulePath environment variable. Starting from there, it is possible to use PowerShellGet as in the following: