Automating Bloatware Removal on Azure Virtual Desktop (AVD) VMs
When deploying Azure Virtual Desktop (AVD) environments, default Windows images often contain unnecessary pre-installed applications (bloatware) that can impact performance and user experience. To streamline the optimization process, I have created a PowerShell script that identifies all virtual machines (VMs) in an AVD Host Pool and executes a bloatware removal script on each VM.
In this blog, I will walk through the implementation of two key PowerShell scripts:
- IdentifyAVDVMs.ps1 – Finds all VMs inside a specified AVD Host Pool.
- RemoveBloatwareWin11.ps1 – Executes a cleanup process to remove unwanted applications from each VM.
Prerequisites
Before running the scripts, ensure you have the following:
- An active Azure subscription with an AVD deployment.
- PowerShell 7+ installed on your local machine.
- Azure PowerShell Module (Az module) installed (Install-Module -Name Az -Scope CurrentUser).
- Contributor or higher role assigned to manage the AVD environment.
Step 1: Identifying AVD VMs in a Host Pool
The script IdentifyAVDVMs.ps1 helps fetch all VMs associated with a given AVD Host Pool and executes the bloatware removal script on each machine.
Key Functionalities:
- Connects to Azure and retrieves the Host Pool details.
- Lists all Session Hosts (VMs) in the Host Pool.
- Runs the bloatware removal script on each VM.
Prerequisite:
- First authenticates to Azure using Connect-AzAccount.
- After that, sets the subscription context with Set-AzContext.
- Retrieves all AVD session hosts from the Host Pool using Get-AzWvdSessionHost.
- Loops through each VM and remotely executes the bloatware removal script via Invoke-Command.
GitHub Repository
I have published the complete code on my GitHub. You can access it here:
🔗 IdentifyAVDVMs.ps1
A screenshot of the script can be found here.
Step 2: Removing Bloatware from Windows 11 VMs
The RemoveBloatwareWin11.ps1 script removes unnecessary applications to optimize the AVD experience.
Key Functionalities:
- Uninstalls pre-installed apps like Xbox, OneNote, Skype, and others.
- Disables Microsoft Consumer Experiences to prevent reinstallation of bloatware.
- Cleans up temporary files and registry entries.
Script Breakdown (RemoveBloatwareWin11.ps1)
GitHub Repository
I have published the complete code on my GitHub. You can access it here:
🔗 RemoveBloatwareWin11.ps1
A screenshot of the script can be found here
Explanation:
- The script defines a list of bloatware applications and removes them using Remove-AppxPackage.
- It also removes provisioned apps using Remove-AppxProvisionedPackage.
- Disables Windows Consumer Features to prevent Microsoft from reinstalling the removed apps.
- Cleans up temporary files for additional optimization.
Step 3: Running the Scripts
1. Execute the VM Identification Script
Run IdentifyAVDVMs.ps1 on a machine with access to Azure:
.\IdentifyAVDVMs.ps1
Enter Azure credentials when prompted.
2. Verify the Cleanup Process
Once the script runs, you can check bloatware removal status by running:
Get-AppxPackage -AllUsers
Ensure unwanted applications are no longer listed.
Conclusion
This automation simplifies the process of removing bloatware across multiple AVD VMs. By integrating the IdentifyAVDVMs.ps1 script with RemoveBloatwareWin11.ps1, administrators can ensure their AVD environments remain clean, efficient, and optimized for users.
Do you have any suggestions or improvements? Let me know in the comments! 🚀