Guide: Use winget on Post-Setup

slownumb

New Member
Hello folks!

I had to write this guide because this was a game changer for me. Maybe others will find useful as well.

If you search the forum on how to use winget on Post-Setup, you'll see that it has been a struggle so far.
This post really changed it for me. So this guide will be around it with minor changes.
All I've done is add to the script is a loop to test every 5 seconds if there is internet connection.
Since you need it to use winget, it will hang there while you are disconnected.
As soon as you (or your presets) connects you, it will get out of the loop and start installing.
Thank you Hammer of the Gods for the script and garlin for the MS Store Apps downloader also used here.

Unfortunatly I only tested it using Windows 11 23H2v2. I don't see why this wouldn't work with previous versions, but it would be good if anyone older versions share here if it worked or not.

Get this tool from garlin. Unpack it and run the .bat file. It will open this box.

IMG1.png

Select Microsoft.DesktopAppInstaller on the left and your arch (mine is x64) shown on the image and click Ok.
Soon you'll be prompted with this screen:

IMG2.png

Select the option on the image (ver. 2023.1215.611.0) and click Ok to start downloading it.
After the download finishes, the files will be stored on the folder you found the .bat file prior. Leave them for now.

Download the Winget.ps1 script attached to this post. Edit it on the notepad to change the last portion.
You'll have to search and provide your apps ID. To search, open the command prompt and type: winget search 'the app you want search', as shown below with firefox as an exemple.
IMG3.png

Copy the ID and paste on the script. For Firefox the download line will be like this: winget install -h -e --id Mozilla.Firefox.
Do this for every App you want to install on Post-Setup. If the search returns nothing, the package is not avaliable for download with winget (Blizzard Battle.Net app is not avaliable, as exemple)
For a true automated install, provide the following arguments on the first winget install line: --accept-package-agreements --accept-source-agreements
Save the script and leave it for now.

3.1 Open NTLite, mount your ISO and load your preset.

3.2 Updates tab

On the toolbar, click Add -> Package files.
IMG4.png

Navigate to where you downloaded DesktopAppInstaller and add these 3 files to NTLite as shown, making sure you don't mix the VCLibs files: the correct is the one with UWPDesktop on the filename:
Microsoft.DesktopAppInstaller_2023.1215.611.0_neutral_~_8wekyb3d8bbwe
Microsoft.VCLibs.140.00.UWPDesktop_14.0.32530.0_x64__8wekyb3d8bbwe
Microsoft.UI.Xaml.2.7_7.2208.15002.0_x64__8wekyb3d8bbwe
IMG5.png

After adding the files, the Updates tab will be like the picture below.
IMG6.png

3.3 Post-Setup tab

On the toolbar here, click on 'Task - User' and then Add -> File and add the script Winget.ps1 to it as shown below. No parameters are needed here.
IMG7.png

If you are on Wi-Fi, you have to connect to it as you land on the desktop. The script will hang while there is no connection.
You can force it to connect before the script is run and stated on this thread posts #2 and #10. Make sure to follow both posts for it to work properly.
If you choose have NTLite force the connection, your Post-Setup tab will be like this:
IMG8.png

And that's it. Apply the changes and process the image to create your ISO. Try it first on a VM, if everything is ok, install on your machine as desired.

Once Post-Setup starts to run the script, it will start downloading the apps you defined on it.
IMG9.png
This is on a VM, so the script didn't have to wait for internet. But I already tested this on my physical machine with Wi-Fi only and it worked like a charm.

Sorry for my bad writing, English is not my main language.
Edit: forgot to attach the script. Its there now.
 

Attachments

  • Winget.zip
    1.1 KB
Thanks for the easy guide but I might be missing something. It doesn't work for me and when I try to run the script manually after install, it says the execution policy doesn't allow it.
 
When executing the script on Post-Setup NTLite does bypass the execution policy.
To execute manually after the install, use the following command:

powershell -NoProfile -ExecutionPolicy Bypass Winget.ps1
 
I'm in the same position as bobbintb: there is no indication that the script runs in my test VM (no powershell window popup, the programs I try to install via winget don't install). When I try to manually run the script I get execution policy error. If I change the execution policy manually then the script runs, though I notice it still prompts for UAC during the elevation portion of the script. Did you perhaps change the UAC settings when setting up your image?
 
Commands executed by Post-Setup (Machine or User) run with elevated rights. But you running the same PS outside an Admin shell triggers the UAC prompt.
 
Ah, ok. Well, I started typing a longer post with my presets and the script to troubleshoot but I created another new image to run and it's working. No clue what I broke but must have been user error. Thanks for discussing.
 
I'll check everything again. How can I troubleshoot if it doesn't work with Post-Setup? Does it save something to Event Viewer?
 
I'll check everything again. How can I troubleshoot if it doesn't work with Post-Setup? Does it save something to Event Viewer?
The script doesn't save anything on event viewer that it have been designed to.

To troubleshoot, I would try to execute the script after the install is completed, using the bypass command. This way, when the scripts fails at least you can see which error it returned. On Post-Setup, the window closes too fast when it fails to read anything.

The most common error was the lack of internet, that's why I added the halt loop to check for connection every couple seconds. But on VM its usually not a problem.

Make it work outside Post-Setup first is crucial to make it work on Post-Setup.

Please, reach out with the error and preset if it doesn't work.
 
To troubleshoot, I would try to execute the script after the install is completed, using the bypass command. This way, when the scripts fails at least you can see which error it returned. On Post-Setup, the window closes too fast when it fails to read anything.
I did all that, that's what I'm saying. Anyway, I built the ISO again and it seems to work now for some reason. The only thing I think I changed was I removed Microsoft.VCLibs.140.00_14.0.33321.0_x64__8wekyb3d8bbwe.appx from the updates because it wasn't listed in the guide. Glad it's working now. Thanks.
 
Back
Top