Start-ADTProcess with wsl.exe --install --from-file returns success but doesn’t install distro in Intune deployment

I'm deploying a custom .wsl file (Ubuntu 24.04) using PSADT v4 through Intune. I’m using Start-ADTProcessAsUse to run the following WSL commands as SYSTEM:

Start-ADTProcessAsUser -FilePath "powershell.exe" -ArgumentList "-Command "wsl --install --from-file $Ubuntu2404File --no-launch"" -Wait

The .wsl file:

  • Is located in the $DirFiles folder and resolves correctly

The issue:

  • The command returns success (exit code 0)
  • But no distro is actually installed
  • wsl.exe --list shows no new entries
  • There are no error logs
  • Manually running the same command as a user works perfectly
  • Running wsl --install with --from-file under SYSTEM appears to silently skip or exit

Is this a limitation of wsl.exe --install --from-file under SYSTEM?
I've tried to run also Start-ADTProcess but it fails with exit code -1...

The function Start-ADTProcessAsUser is pretty much broken for all but the most simple of things. I’d wait for 4.1.0 or try a development build, which has only not been released due to lack of documentation updates.

Development builds can be obtained from here: Workflow runs · PSAppDeployToolkit/PSAppDeployToolkit · GitHub

1 Like

Hi,

When is the official 4.1.0 version supposed to be released? I believe some time ago you mentioned end of Q2. Is that still the case?
https://discourse.psappdeploytoolkit.com/t/start-adtprocessasuser-error-handling

Thx in advance

Pieter

Hi,
It’s been mentioned before - here is a couple of @mjr4077au’s most recent replies to similar earlier questions:

1 Like

After hours of trial and error trying to get the app deployed via Intune, I finally managed to get it working.

At some point, I took a step back and thought: “Well, if I can run the install command as a local user without admin rights, why not just install it that way using CMD?”
So that’s exactly what I did.

I’ll share the full script tomorrow, but just wanted to drop this insight in case it helps someone else.

1 Like

@George, I have just gone back to your original posting and may have realised what this issue could be…

If I put that code as Preformatted text (so it shows correctly on this forum)

Start-ADTProcessAsUser -FilePath “powershell.exe” -ArgumentList “-Command `"wsl --install --from-file $Ubuntu2404File --no-launch`”" -Wait

It may be a pasting issue, but you appear to have both () and (") double quotes in use, Apologies if I’m preaching to someone that knows this already - Powershell does not know what to do with the 1st type, so you should always use the second.

One suggestion that might be worth trying is wrapping the variable $Ubuntu2404File within $() or an extra escaped pair of double quotes (`") as I’m unsure if your expanded variable $Ubuntu2404File contains spaces.
e.g.

Start-ADTProcessAsUser -FilePath "powershell.exe" -ArgumentList "-Command `"wsl --install --from-file `"$Ubuntu2404File`" --no-launch`"" -Wait

or

Start-ADTProcessAsUser -FilePath "powershell.exe" -ArgumentList "-Command `"wsl --install --from-file $($Ubuntu2404File) --no-launch`"" -Wait
1 Like

No problem at all! That was indeed a copy-paste issue. Thank you for pointing it out!

I will now provide the code below that saved my day and enabled me to deploy the application.

## <Perform Pre-Installation tasks here>
###CUSTOM##################################################################################################################
###########################################################################################################################
    #Enable WSL and Virtual Machine Platform if not already enabled
$wslState = (Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux).State
$vmPlatformState = (Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform).State
if ($wslState -eq "Enabled" -or $vmPlatformState -eq "Enabled") {
    Write-ADTLogEntry "WSL or VMP are already enabled." -Severity 1 -Source "WSL Setup"
} else {
    Write-ADTLogEntry "WSL and VMP are not enabled. Enabling WSL and Virtual Machine Platform..."
    #Start-ADTProcess -FilePath "powershell.exe" -ArgumentList "-WindowStyle Hidden -Command `"Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart; Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart`"" -Wait
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart
    Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
    Show-ADTInstallationRestartPrompt -CountdownSeconds 120
    Close-ADTSession -ExitCode 3010
}

## <Perform Installation tasks here>
###CUSTOM##################################################################################################################

#Variables
$UbuntuFileName = "Ubuntu2404-250130_x64.wsl"
$Ubuntu2404File = "C:\Temp\Ubuntu\$UbuntuFileName"
$ServiceUIPath = "$($adtSession.DirSupportFiles)\ServiceUI.exe"
$wslExe = "$env:SystemRoot\System32\wsl.exe"

#Copy the distro file to ProgramData location
Copy-ADTFile -Path "$($adtSession.DirFiles)\$UbuntuFileName" -Destination "C:\Temp\Ubuntu\"

#Temp file to capture WSL distro list (must run in user context)
$wslListFile = "$env:TEMP\wsl_list.txt"

#Build WSL list command that runs in user session and saves output to file
$wslListCommand = "wsl.exe -l --quiet > `"$wslListFile`""
$checkArguments = "/c $wslListCommand"

#Run the WSL list command as user (needed when script is run from SYSTEM like in Intune)
Start-ADTProcessAsUser -FilePath "cmd.exe" -ArgumentList $checkArguments -Wait -PassThru
Start-Sleep -Seconds 2  # Wait to ensure file is written

#Read installed distros
$existingDistros = Get-Content -Path $wslListFile -ErrorAction SilentlyContinue
$distributionName = "Ubuntu-24.04"

#Check if Ubuntu-24.04 is already installed
$alreadyInstalled = $existingDistros -contains $distributionName

if (-not $alreadyInstalled) {
    Write-ADTLogEntry "The distribution $distributionName is not installed. Proceeding with installation..."

    # Build WSL install command
    $wslCommand = 'wsl.exe --install --from-file "C:\Temp\Ubuntu\Ubuntu2404-250130_x64.wsl" --no-launch'
    $arguments = "/c $wslCommand"

    # Run install command as user
    Start-ADTProcessAsUser -FilePath "cmd.exe" -ArgumentList $arguments -Wait -PassThru
    Start-Sleep -Seconds 25
    Show-ADTInstallationPrompt -Title 'Ubuntu 24.04 Deployment Setup Manager' -Message 'Ubuntu-24.04 has been successfully installed.' -ButtonRightText 'OK' -Icon Information -NoWait
 }
else {
    Write-ADTLogEntry "The distribution $distributionName is already installed. Skipping installation."
    Show-ADTInstallationPrompt -Title 'Ubuntu 24.04 Deployment Setup Manager' -Message 'Ubuntu-24.04 is already installed.' -ButtonRightText 'OK' -Icon Information -NoWait
}

#Clean up temporary file
Remove-Item -Path $wslListFile -ErrorAction SilentlyContinue
Remove-ADTFolder -Path "C:\Temp\Ubuntu"

## <Perform Pre-Uninstallation tasks here>
#Check for Ubuntu distro and uninstall it.
     # Build WSL uninstall command 
    $wsluninstallCommand = "wsl.exe --unregister Ubuntu-24.04"
    $uninstallarguments = "/c $wsluninstallCommand"

    # Run uninstall command as user
    Start-ADTProcessAsUser -FilePath "cmd.exe" -ArgumentList $uninstallarguments -Wait -PassThru
    Start-Sleep -Seconds 5


## <Perform Uninstallation tasks here>
###CUSTOM##################################################################################################################
###########################################################################################################################
#Disable Windows Subsystem for Linux (WSL) and Virtual Machine Platform features. There are being turned off to remove WSL support and its virtualization dependencies.
$wslState = (Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux).State
$vmPlatformState = (Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform).State

if ($wslState -eq "Enabled" -or $vmPlatformState -eq "Enabled") {
    Write-ADTLogEntry "WSL or VMP are enabled. Disabling WSL and Virtual Machine Platform..." -Severity 1 -Source "WSL Uninstall Setup"
    #Start-ADTProcess -FilePath "powershell.exe" -ArgumentList "-WindowStyle Hidden -Command `"Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart; Disable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart`"" -Wait
    Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart
    Disable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
    Show-ADTInstallationRestartPrompt -CountdownSeconds 120
} else {
    Write-ADTLogEntry "WSL and VMP are not enabled."
}

later edit:
I realize that some variables are unnecessary. These variables don’t bother anyone though :).

Hi @George
Thanks for sharing - Would you mind editing your post and put three escape characters (`) before and after you code, it converts it to preformatted text ‘i.e. code’ as it makes it easier for others to read and the forums Markdown doesn’t convert you comments (i.e. lines starting with "# ") to bold :grin:

TIA

1 Like

Hello Adrian! Absolutely no problem at all. I’ve edited the post. I hope it’s all good now. Wishing you and everyone a great day!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.