Enable PSGallery in a ConfigMgr Task Sequence While in WinPE
Receive notification right in your inbox whenever new content like this is released & sign up for our email list!
We’ll send you the latest updates, how-to’s, and solutions to empower you at every endpoint.
Have you ever wanted to install a PowerShell module into a Configuration Manager task sequence from the PowerShell Gallery while in Windows PE? Would you like to install HP’s Client Management Script Library (HPCMSL) to leverage it to update BIOS, set BIOS settings, or install other modules? I have, and it’s always been annoying to get the extra modules I needed into WinPE because “Install-Module” doesn’t work in WinPE (when pulling from the PowerShell Gallery). That’s why I am going to show you how to enable PSGallery in a ConfigMgr task sequence while in WinPE.
A while back, David Segura let me know he figured it out. The process was actually quite simple and he wrote a function to enable PSGallery on a boot image WIM file: Enable-PEWimPSGallery. This is a great method if you want to bake the ability right into your boot media. If you’re creating custom boot media for other applications other than a Configuration Manager task sequence, then leveraging David’s OSD module with the Enable-PEWimPSGallery function is the best way.
Enable PSGallery in a ConfigMgr Task Sequence Scripts
Sometimes you may not want to update your boot media or perhaps you don’t have rights to it, and you only want to add that ability on specific task sequences. That was my goal, so taking what David built and reading his docs, which provided the road map to add the ability, I created a script that would add the requirements needed and then download a module based on the module name. Then the script would install it, making it available in your task sequence.
I wrote two different scripts to accomplish the same goal. One for downloading the requirements from the PowerShell Gallery, and one for leveraging the requirements in a package you create in ConfigMgr. Essentially, one script grabs everything from the internet, and the other where you call the script from a package.
Here’s a quick overview of the requirements:
- Create a variable PowerShell script to leverage when running: $env:LOCALAPPDATA
- By default, this isn’t available in WinPE like it is in the full OS.
- PowerShell Module: PowerShellGet
- PowerShell Module: PackageManagement
Once you have created the PowerShell script, installed the modules, and set up in WinPE, then the command “Install-Module” will work and pull from the PowerShell Gallery.
You can find a technical overview and a demo of the scripts, alternative methods, along with a video demo, on our ConfigMgr-docs site.
Each script’s integration into the task sequence is quite simple. In the version that grabs everything from the internet, you simply paste the script contents into the Run PowerShell Script embedded script feature and supply the -ModuleName parameter.
The second script, which leverages the package, is nearly identical. The difference is that the package version of the script is in a package and you call the script from the package with the parameter.
Ready to Go
With that, you’re all set, you’ll now be able to enable PSGallery in a ConfigMgr task sequence while in WinPE to accommodate even more of your ideas. If you’re using PSGallery in WinPE, or a task sequence in general, please drop us a note on Twitter @gwblok @recastsoftware. I’d really like to hear how you’re leveraging it.