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

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 :).