Post-Setup Powershell script suddenly not executed

exelanz

Member
Hi all,

I have a weird issue. For some days now my post-setup powershell script (to install apps) is is not running (or failing at the start) anymore.

I have no clue what could have caused this. I unloaded/loaded images, did the ntlite config from scratch, but nothing helps.

Any idea or things I can/should check?

Many thanks in advance
 
There's several tricks.
1. Edit "\sources\$OEM$\$$\Setup\SetupFiles\SetupComplete.cmd", and append "> C:\log1.txt" on your script's line.

2. Edit your PS script, and insert debug statements.
Code:
"My script is running." | Out-File 'C:\log2.txt'
...
'My script is over here.' | Out-File 'C:\log2.txt' -Append
 
Ok after many tests, I have to conclude that the following code did not work anymore (install latest version of winget):

Code:
# Get latest download url

$ProgressPreference = 'SilentlyContinue'
$URL = "https://api.github.com/repos/microsoft/winget-cli/releases/latest"
$URL = (Invoke-WebRequest -Uri $URL).Content | ConvertFrom-Json |
        Select-Object -ExpandProperty "assets" |
        Where-Object "browser_download_url" -Match '.msixbundle' |
        Select-Object -ExpandProperty "browser_download_url"

# Download
Invoke-WebRequest -Uri $URL -OutFile "Setup.msix" -UseBasicParsing

# Install
Add-AppxPackage -Path "Setup.msix"

# Cleanup
Remove-Item "Setup.msix"

I did not spend time on debugging but it looks like "script execution" has changed to something "restrictive".

Now using the script from https://github.com/asheroto/winget-install/releases with parameter --Force and after this script the normal app install script.

Hope this helps future readers.
 
Last edited:
I always add this line before using Invoke-WebRequest:
Code:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Otherwise you're not guaranteed HTTPS handshaking always works on a random system. Also, you're not using absolute paths. Post-Setup (Machine) runs as SYSTEM, so it won't create a permission problem but it's still bad coding style.
 
(User) commands run with Admin rights, and NTLite executes every PS script with "-NoProfile -ExecutionPolicy Bypass".

Installing winget sucks. You can't install the latest Applnstaller without updating the pre-req VCLibs and UI.Xaml. There's often a race condition as WU updates all the Appx packages in the background, including the libraries. If you force download and install them as DependencyPackagePath items, then you avoid all that, and it works.

Except winget only works for an interactive user, and not as the Administrator or SYSTEM.

I prefer the original version of his script.
https://github.com/asheroto/winget-install/releases/download/1.0.0/winget-install.ps1
 
Back
Top