[REQUEST] To have the ability to integrate PowerShell modules into mounted image

DeploymentAddict

New Member
Messages
6
Reaction score
1
Hi Team,

I love NTLite and how simple it makes the processing of Windows images.

One thing I cannot see across the forums (I have searched a lot and came up with nothing so far), is the ability or function of integrating PowerShell modules into the loaded image.

For example I'd like to take an existing WIM image we already use for deployment, and add a couple of PS Modules such as PSWindowsUpdate, Winget/PackageManagement.

Q1: Is it as easy as adding the exported PSModules into the relevant path(s) in a mounted image file structure?
Q2: does simply copying the Module folder there automatically import the module when booting the machine? I can't get my head around how pre-requisite or dependency modules would work.

If it was somehow possible to install PS Modules directly into the mounted image in the same way as other packages/components, it would mean, that after installing the image with these PS Modules bundled in, we could in theory hit Shift-F10 in a newly installed OOBE session and run PSWindowsUpdate to freshen the image and install any drivers that are appearing.

I hope the suggestion makes sense, and I hope that its technically feasible.

Look forward to the discussion.

Thanks,
 
While you can use Save-Module to install modules to any mounted folder, Windows won't allow you to use Update-Module since you didn't use Install-Module in the first place. Windows keeps a separate metadata store for remembering what it did.

The normal solutions are:
1. Use a sysprepped image, where your PS modules are already installed.

2. Dynamically install PS modules (presuming you have network access). NTLite defaults to running Post-Setup (Before logon) right after OOBE, but there's a legacy mode to run commands during specialize pass. This allows the modules to be present before you need them.

- Enable Unattended mode (but don't touch any settings unless you need them)
- From the Post-Setup toolbar, check the Unattended box.
- Add the PS commands:
Code:
powershell -C "Install-PackageProvider -Name NuGet -Force; Set-PSRepository PSGallery -InstallationPolicy Trusted"
powershell -C "Install-Module -Name PSWindowsUpdate,Microsoft.WinGet.Client -Scope AllUsers -Confirm:$false -Force"

1736975986470.png
 
After detailed testing, this workaround isn't successful because you're running as SYSTEM.

SYSTEM doesn't have a normal user context, so PS can't figure out how to save changes to the current user's profile. Therefore it fails to import modules. When you're running in OOBE as defaultuser0, it has a (temporary) user profile. But the point was to have PSWindowsUpdate ready before we got to OOBE, so you could run a manual update.

Summary:
1. While you can manually copy files to "C:\Program Files\WindowsPowerShell\Modules", PS won't manage installed module updates for you.
2. This will work in Post-Setup (After logon), because you're not running as SYSTEM.
 
After plenty of failed attempts, I finally gave up and tried your idea of saving the PS modules to the ISO.

1. Create a new directory on the ISO folder, "sources\$OEM$\$1\Program Files\WindowsPowerShell\Modules".

2. Open a PS window, run Save-Module to extract your modules to the same target folder.
Code:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Save-Module –Name PSWindowsUpdate –Path 'E:\path\to\ISO\sources\$OEM$\$1\Program Files\WindowsPowerShell\Modules'
Save-Module –Name Microsoft.Winget.Client –Path 'E:\path\to\ISO\sources\$OEM$\$1\Program Files\WindowsPowerShell\Modules'

Windows 11 x64-2025-02-08-00-39-11.png
This feels kinda weird...

3. From the Registry screen, import this reg file to update the Execution Policy.
Code:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
"ExecutionPolicy"="RemoteSigned"

4. PS modules are not automatically imported into any session or script, you have to explicitly import them as needed. Otherwise there would be a big performance issue since you would have to load every module in your search path(!)
 
Back
Top