Deploying applications via Microsoft Intune can be streamlined using the IntuneWinAppUtil tool. To automate the conversion of existing PSADT (PowerShell App Deployment Toolkit) packages into IntuneWinApp packages, we can leverage this PowerShell script. This blog post will walk you through the process of setting up and running a PowerShell script that handles the automation, including clearing temporary files and freeing memory to avoid system resource issues.
Saving Repackaging Costs
By automating the Intune packaging process, organizations can significantly reduce the time and effort required for application deployment.
In this example, I was able to bulk convert approximately 500 GB of applications. To manually repackage each application, it would have taken months. This automation not only speeds up the deployment process but also helps in saving substantial repackaging costs associated with manual application packaging. Automation ensures consistency and reduces human error, leading to a more efficient and cost-effective deployment strategy.
Prerequisites
Before we dive into the script, ensure you have the following:
- PSADT packages organized in a specific directory structure.
- IntuneWinAppUtil executable.
- PowerShell environment set up with necessary permissions.
- Significant disk space to accommodate source and output files
Directory Structure assumptions
The script assumes the PSADT package folder structure as follows. For custom folder structures, please feel free to edit the code:
E:\PSADTPackageSource
├── ApplicationName1
│ ├── VersionNumber1
│ │ └── PSADT
│ └── VersionNumber2
│ └── PSADT
├── ApplicationName2
│ ├── VersionNumber1
│ │ └── PSADT
│ └── VersionNumber2
│ └── PSADT
E:\OUTPUT -- Folder to store Win32Apps
The Migration Script
The following PowerShell script automates the creation of IntuneWinApp packages from the PSADT packages:
Download the script from Github
# Define the base directories
$automationBaseDir = "E:\PSADTPackageSource"
$outputBaseDir = "E:\OUTPUT"
# Define the path to IntuneWinAppUtil executable
$intuneWinAppUtilPath = "E:\IntuneWinAppUtil\IntuneWinAppUtil.exe"
# Define colors for Write-Host output
$colors = @("Cyan", "Green", "Yellow", "Magenta", "Blue", "Red", "White")
# Function to clear temporary files
function Clear-TempFiles {
Write-Host "Clearing temporary files..." -ForegroundColor "Yellow"
Remove-Item -Path "$env:TEMP\*" -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item -Path "$env:LOCALAPPDATA\Temp\*" -Force -Recurse -ErrorAction SilentlyContinue
}
# Function to free memory
function Free-Memory {
Write-Host "Freeing memory..." -ForegroundColor "Yellow"
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
[System.GC]::Collect()
}
# Traverse the automation base directory
Get-ChildItem -Path $automationBaseDir -Directory | ForEach-Object {
$applicationNameDir = $_.FullName
$applicationName = $_.Name
$colorIndex = 0
Get-ChildItem -Path $applicationNameDir -Directory | ForEach-Object {
$versionNumberDir = $_.FullName
$versionNumber = $_.Name
$psadtFolder = "$versionNumberDir\PSADT"
if (Test-Path $psadtFolder) {
# Define the output directory for the IntuneWinApp package
$outputDir = "$outputBaseDir\$applicationName\$versionNumber\Win32App"
# Create the output directory if it doesn't exist
if (-not (Test-Path $outputDir)) {
New-Item -ItemType Directory -Path $outputDir -Force
}
# Define the source setup file (assuming the main PSADT script is Deploy-Application.exe)
$sourceSetupFile = "Deploy-Application.exe"
# Construct the command to run
$command = "`"$intuneWinAppUtilPath`" -c `"$psadtFolder`" -s `"$sourceSetupFile`" -o `"$outputDir`" -q"
Write-Host "Running command: $command" -ForegroundColor "Gray"
# Run the IntuneWinAppUtil command in a new PowerShell process
$powershellCommand = "Start-Process powershell -ArgumentList '-NoProfile -NoLogo -Command `"$command`"' -Wait -NoNewWindow"
Invoke-Expression $powershellCommand
# Clear temporary files and free memory
Clear-TempFiles
Free-Memory
# Print the folder processing information
Write-Host "Processed: $applicationName - $versionNumber" -ForegroundColor $colors[$colorIndex % $colors.Count]
# Increment the color index
$colorIndex++
}
}
}
Write-Host "Conversion process completed." -ForegroundColor "Green"
- Directory Setup: The script assumes a base directory
E:\PSADTPackageSourcewhere the PSADT packages are stored and an output directoryE:\OUTPUTfor the resulting IntuneWinApp packages. - Clearing Temporary Files: The
Clear-TempFilesfunction clears both the system TEMP directory and the user-specific AppData\Local\Temp directory. - Freeing Memory: The
Free-Memoryfunction triggers garbage collection to free up memory. - Processing Each Package: The script traverses the directory structure, processes each version of each application, runs the IntuneWinAppUtil command, and clears temporary files and memory after each package creation.
Running the Script
Save the script as a .ps1 file and run it in a PowerShell console with the necessary permissions. Ensure the IntuneWinAppUtil.exe path is correctly set in the script.
Automating the packaging of Intune applications using PowerShell and PSADT can significantly streamline the deployment process. By incorporating memory and temporary file management, this script ensures efficient and error-free execution, making it a powerful tool for IT administrators.
For more detailed documentation on PSADT and IntuneWinAppUtil, refer to the PSADT Documentation and IntuneWinAppUtil Guide.
















