Full Code of zoicware/RemoveWindowsAI for AI

main b77719f2e67b cached
127 files
353.6 KB
136.8k tokens
1 requests
Download .txt
Showing preview only (382K chars total). Download the full file or copy to clipboard to get everything.
Repository: zoicware/RemoveWindowsAI
Branch: main
Commit: b77719f2e67b
Files: 127
Total size: 353.6 KB

Directory structure:
gitextract_6n8exeya/

├── .github/
│   ├── FUNDING.yml
│   └── ISSUE_TEMPLATE/
│       ├── bug_report.md
│       └── feature_request.md
├── ClassicApps/
│   ├── paint/
│   │   ├── Paint.reg
│   │   ├── mspaint.exe.mui
│   │   ├── mspaint.exe.mun
│   │   └── paint_lang_files/
│   │       ├── ar-SA/
│   │       │   └── mspaint.exe.mui
│   │       ├── bg-BG/
│   │       │   └── mspaint.exe.mui
│   │       ├── cs-CZ/
│   │       │   └── mspaint.exe.mui
│   │       ├── da-DK/
│   │       │   └── mspaint.exe.mui
│   │       ├── de-DE/
│   │       │   └── mspaint.exe.mui
│   │       ├── el-GR/
│   │       │   └── mspaint.exe.mui
│   │       ├── en-GB/
│   │       │   └── mspaint.exe.mui
│   │       ├── es-ES/
│   │       │   └── mspaint.exe.mui
│   │       ├── es-MX/
│   │       │   └── mspaint.exe.mui
│   │       ├── et-EE/
│   │       │   └── mspaint.exe.mui
│   │       ├── fi-FI/
│   │       │   └── mspaint.exe.mui
│   │       ├── fr-CA/
│   │       │   └── mspaint.exe.mui
│   │       ├── fr-FR/
│   │       │   └── mspaint.exe.mui
│   │       ├── he-IL/
│   │       │   └── mspaint.exe.mui
│   │       ├── hr-HR/
│   │       │   └── mspaint.exe.mui
│   │       ├── hu-HU/
│   │       │   └── mspaint.exe.mui
│   │       ├── it-IT/
│   │       │   └── mspaint.exe.mui
│   │       ├── ja-JP/
│   │       │   └── mspaint.exe.mui
│   │       ├── ko-KR/
│   │       │   └── mspaint.exe.mui
│   │       ├── lt-LT/
│   │       │   └── mspaint.exe.mui
│   │       ├── lv-LV/
│   │       │   └── mspaint.exe.mui
│   │       ├── nb-NO/
│   │       │   └── mspaint.exe.mui
│   │       ├── nl-NL/
│   │       │   └── mspaint.exe.mui
│   │       ├── pl-PL/
│   │       │   └── mspaint.exe.mui
│   │       ├── pt-BR/
│   │       │   └── mspaint.exe.mui
│   │       ├── pt-PT/
│   │       │   └── mspaint.exe.mui
│   │       ├── ro-RO/
│   │       │   └── mspaint.exe.mui
│   │       ├── ru-RU/
│   │       │   └── mspaint.exe.mui
│   │       ├── sk-SK/
│   │       │   └── mspaint.exe.mui
│   │       ├── sl-SI/
│   │       │   └── mspaint.exe.mui
│   │       ├── sr-Latn-RS/
│   │       │   └── mspaint.exe.mui
│   │       ├── sv-SE/
│   │       │   └── mspaint.exe.mui
│   │       ├── th-TH/
│   │       │   └── mspaint.exe.mui
│   │       ├── tr-TR/
│   │       │   └── mspaint.exe.mui
│   │       ├── uk-UA/
│   │       │   └── mspaint.exe.mui
│   │       ├── zh-CN/
│   │       │   └── mspaint.exe.mui
│   │       └── zh-TW/
│   │           └── mspaint.exe.mui
│   └── snipping/
│       ├── SnippingTool.exe.mui
│       └── snipping_lang_files/
│           ├── ar-SA/
│           │   └── SnippingTool.exe.mui
│           ├── bg-BG/
│           │   └── SnippingTool.exe.mui
│           ├── cs-CZ/
│           │   └── SnippingTool.exe.mui
│           ├── da-DK/
│           │   └── SnippingTool.exe.mui
│           ├── de-DE/
│           │   └── SnippingTool.exe.mui
│           ├── el-GR/
│           │   └── SnippingTool.exe.mui
│           ├── en-GB/
│           │   └── SnippingTool.exe.mui
│           ├── es-ES/
│           │   └── SnippingTool.exe.mui
│           ├── es-MX/
│           │   └── SnippingTool.exe.mui
│           ├── et-EE/
│           │   └── SnippingTool.exe.mui
│           ├── fi-FI/
│           │   └── SnippingTool.exe.mui
│           ├── fr-CA/
│           │   └── SnippingTool.exe.mui
│           ├── fr-FR/
│           │   └── SnippingTool.exe.mui
│           ├── he-IL/
│           │   └── SnippingTool.exe.mui
│           ├── hr-HR/
│           │   └── SnippingTool.exe.mui
│           ├── hu-HU/
│           │   └── SnippingTool.exe.mui
│           ├── it-IT/
│           │   └── SnippingTool.exe.mui
│           ├── ja-JP/
│           │   └── SnippingTool.exe.mui
│           ├── ko-KR/
│           │   └── SnippingTool.exe.mui
│           ├── lt-LT/
│           │   └── SnippingTool.exe.mui
│           ├── lv-LV/
│           │   └── SnippingTool.exe.mui
│           ├── nb-NO/
│           │   └── SnippingTool.exe.mui
│           ├── nl-NL/
│           │   └── SnippingTool.exe.mui
│           ├── pl-PL/
│           │   └── SnippingTool.exe.mui
│           ├── pt-BR/
│           │   └── SnippingTool.exe.mui
│           ├── pt-PT/
│           │   └── SnippingTool.exe.mui
│           ├── ro-RO/
│           │   └── SnippingTool.exe.mui
│           ├── ru-RU/
│           │   └── SnippingTool.exe.mui
│           ├── sk-SK/
│           │   └── SnippingTool.exe.mui
│           ├── sl-SI/
│           │   └── SnippingTool.exe.mui
│           ├── sr-Latn-RS/
│           │   └── SnippingTool.exe.mui
│           ├── sv-SE/
│           │   └── SnippingTool.exe.mui
│           ├── th-TH/
│           │   └── SnippingTool.exe.mui
│           ├── tr-TR/
│           │   └── SnippingTool.exe.mui
│           ├── uk-UA/
│           │   └── SnippingTool.exe.mui
│           ├── zh-CN/
│           │   └── SnippingTool.exe.mui
│           └── zh-TW/
│               └── SnippingTool.exe.mui
├── Documentation.md
├── LICENSE
├── OtherAIFeatures.md
├── README.md
├── RemoveAI-UpdateCleanup.ps1
├── RemoveWindowsAIPackage/
│   ├── amd64/
│   │   ├── ZoicwareRemoveWindowsAI-amd641.0.0.0.cab
│   │   ├── amd64_16bf9f5ddcdcc858358ce8a2a9f69f935b0e2c72_31bf3856ad364e35_38655.38527.65535.65535_none_9dea49e759204384.manifest
│   │   ├── amd64_1ac4efa52cc987e34206a4b499ef297c16f443f9_31bf3856ad364e35_38655.38527.65535.65535_none_d12a7b37e1ce0c63.manifest
│   │   ├── amd64_3e5f6992f365ae98da785153cb853cdd2b8d334d_31bf3856ad364e35_38655.38527.65535.65535_none_21a198b98b0eb5cb.manifest
│   │   ├── amd64_690413e3dcead26f87b3989953c5ed27bb12eb95_31bf3856ad364e35_38655.38527.65535.65535_none_2f5fa210a2da208e.manifest
│   │   ├── amd64_761f3629e488278caa4c7585c950f520404712cf_31bf3856ad364e35_38655.38527.65535.65535_none_fab6052e6768b003.manifest
│   │   ├── amd64_a1b65e8b129c7dfee79b5234097d94812770c52a_31bf3856ad364e35_38655.38527.65535.65535_none_427e504fcbfba8f2.manifest
│   │   ├── amd64_bf9f7f39101e056d32e46992b64d45da3774921c_31bf3856ad364e35_38655.38527.65535.65535_none_1b7aa6c634649ec5.manifest
│   │   ├── amd64_c93ca6c2cd59575fe45bad46f6152c80cc5ab492_31bf3856ad364e35_38655.38527.65535.65535_none_048f8255f6dd3270.manifest
│   │   ├── amd64_d18d700de06fc98ae558e2a73994193f028d6209_31bf3856ad364e35_38655.38527.65535.65535_none_99bf2484525af2f0.manifest
│   │   ├── amd64_microsoft-copilot-d..oyment-languagepack_31bf3856ad364e35_38655.38527.65535.65535_none_0fea620d27c4484e.manifest
│   │   ├── amd64_microsoft-copilot-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_26df2268220c2a52.manifest
│   │   ├── amd64_microsoft-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_58a35da8a335eb56.manifest
│   │   ├── amd64_microsoft-windows-s..ngshandlers-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_f88b80f068ad03a6.manifest
│   │   ├── amd64_userexperience-aix-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_cdba7e3535b8898d.manifest
│   │   ├── amd64_userexperience-aix_31bf3856ad364e35_38655.38527.65535.65535_none_293807153aa35c79.manifest
│   │   ├── amd64_userexperience-coreai-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_494247c8d14488ba.manifest
│   │   ├── amd64_userexperience-coreai_31bf3856ad364e35_38655.38527.65535.65535_none_851c3d913b2d96b4.manifest
│   │   ├── amd64_userexperience-recall_31bf3856ad364e35_38655.38527.65535.65535_none_d1d3458f41002cd0.manifest
│   │   └── update.cat
│   └── arm64/
│       ├── ZoicwareRemoveWindowsAI-arm641.0.0.0.cab
│       ├── arm64_072c8668ec63514fc98714c09cef5ffb61eac4d0_31bf3856ad364e35_38655.38527.65535.65535_none_fc8a4193bbbf8ce9.manifest
│       ├── arm64_19b4f2d2eb01fe86e2858f3356507a3743d63a96_31bf3856ad364e35_38655.38527.65535.65535_none_c3b6ebc0bc9bc32a.manifest
│       ├── arm64_2415624e03eaf74c3ed2718f0823e7ef1746afdd_31bf3856ad364e35_38655.38527.65535.65535_none_8ebe44a9559113a2.manifest
│       ├── arm64_37e84906b7c3ad6ec7fd0f73eb941da2bbd40170_31bf3856ad364e35_38655.38527.65535.65535_none_4755105c8785546a.manifest
│       ├── arm64_9977ad932a57937cbd5b595b7054ef37a6fa80d7_31bf3856ad364e35_38655.38527.65535.65535_none_176e9ba77eb5736f.manifest
│       ├── arm64_af04861f8804c4ce83a52310a455da3f912b468f_31bf3856ad364e35_38655.38527.65535.65535_none_9c9d75201debd11a.manifest
│       ├── arm64_b1c39ab687ddb87f21e0bef8191922a64760b277_31bf3856ad364e35_38655.38527.65535.65535_none_8c5f153cdaa8c371.manifest
│       ├── arm64_d555b631e519d0dcd7872958a590cb5e81441910_31bf3856ad364e35_38655.38527.65535.65535_none_ab9a0f7301cc9b81.manifest
│       ├── arm64_f9b5a2b834a34ab4b8fa8da477a953885907d528_31bf3856ad364e35_38655.38527.65535.65535_none_a9f36e0ec06d9f38.manifest
│       ├── arm64_microsoft-copilot-d..oyment-languagepack_31bf3856ad364e35_38655.38527.65535.65535_none_0fea6a4727c43cea.manifest
│       ├── arm64_microsoft-copilot-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_26df2aa2220c1eee.manifest
│       ├── arm64_microsoft-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_58a365e2a335dff2.manifest
│       ├── arm64_microsoft-windows-s..ngshandlers-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_f88b892a68acf842.manifest
│       ├── arm64_userexperience-aix-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_cdba866f35b87e29.manifest
│       ├── arm64_userexperience-aix_31bf3856ad364e35_38655.38527.65535.65535_none_29380f4f3aa35115.manifest
│       ├── arm64_userexperience-coreai-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_49425002d1447d56.manifest
│       ├── arm64_userexperience-coreai_31bf3856ad364e35_38655.38527.65535.65535_none_851c45cb3b2d8b50.manifest
│       ├── arm64_userexperience-recall_31bf3856ad364e35_38655.38527.65535.65535_none_d1d34dc94100216c.manifest
│       └── update.cat
└── RemoveWindowsAi.ps1

================================================
FILE CONTENTS
================================================

================================================
FILE: .github/FUNDING.yml
================================================
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: zoicware
thanks_dev: # Replace with a single thanks.dev username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']


================================================
FILE: .github/ISSUE_TEMPLATE/bug_report.md
================================================
---
name: Bug report
about: Create a report to help improve the script
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:


**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (open winver to see build):**
 - Windows Build: 

**Additional context**
Add any other context about the problem here.


================================================
FILE: .github/ISSUE_TEMPLATE/feature_request.md
================================================
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Additional context**
Add any other context or screenshots about the feature request here.


================================================
FILE: Documentation.md
================================================
## Remove Windows AI Documentation
---
### OS Support

- The script is created for any version of Windows 10 and Windows 11, Latest Stable Builds
- For best results use a Pro, Enterprise, Server, or Education version. I can not guarentee 100% removal on Home versions
  - If you are on a Home version and want to convert to Pro I recommend using massgrave: https://github.com/massgravel/Microsoft-Activation-Scripts
> [!NOTE]
> The script will work on Insider builds however, any new AI features added to Insider builds will not be added to the script till they are released in the latest stable build
>

---

### Code Review

- Given that Microsoft REALLY do not want users removing all AI features the script uses some advanced techniques in PowerShell

#### Run-Trusted Function

- This function leverages an exploit allowing code execution under the `TrustedInstaller.exe` service also known as `Windows Module Installer`
  - Various PowerShell commands will be ran hidden from the user allowing the script to remove items and packages that are locked via System Privileges
 
#### Registry Keys
- I have collected all registry keys regarding AI disablement, including Notepad, Paint, and Edge.
  - Some of these are Group Policies so if you see any AI feature settings greyed out with the message `Some Settings are Managed by Your Organization` this is why
 
#### Prevent Reinstall of AI Packages
- This option will install a custom Windows Update package to make Windows think that there is already a newer version of the AI package installed.
- Method from Atlas and Revi OS as they make use of these

#### Disable Copilot In IntegratedServicesRegionPolicySet
- This JSON file contains rules for deciding weither or not certain apps and settings are enabled based on your region
  - This is mainly used for the EEA [European Economic Area]
- The script finds all policies related to Copilot and sets the default state to disabled 


#### Appx Package Removal
- While the main Copilot package can be removed without any special tricks (Remove-AppxPackage) most AI packages are marked as `Non-Removeable` therefore, the script needs to use multiple exploits to remove these
 - The script creates a sub script in `%TEMP%` to be ran under the above mentioned function `Run-Trusted`
   - **Exploits Performed**
     
     - **End of Life**: one way to trick Windows into thinking a locked package can be removed is to add its Package Family Name to `HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\EndOfLife\USERSID`
       - To avoid Windows Update from failing these registry entries are removed once the package is confirmed uninstalled
     - **Deprovisioning**: this adds the Package Family Name to `HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Deprovisioned` this will prevent the package from being reinstalled by Windows Update
     - **Set-NonRemovableAppsPolicy**: this dism command will attempt to remove the `Non-Removeable` property mentioned above and needs to have system privileges to work
     - **Removing Inbox Apps**: some packages are marked as `InboxApps` this prevents the user from removing them however, when the package is removed from the `HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\InboxApplications` via Run-Trusted Windows will no longer recognize it as an Inbox App

#### Recall Optional Feature
- On most systems recall will be installed via an optional feature, the script will disable and remove this resulting in the State of: `DisabledWithPayloadRemoved`

#### Hidden AI CBS Packages
- Windows CBS [Component-Based Servicing] contains windows packages where some can be visible and removable via `get-windowspackage` and `remove-windowspackage` respectfully
  - Most packages are not visible to the dism command by default so a few tricks are needed to enable this and allow for removal
- The script will search for packages containing various AI keywords in `HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages`
  - To enable visualzation and allow for removal the `Visibility` key needs to be set to 1 and the subkeys `Owners` and `Updates` need to be removed
 
#### Removing AI Files and Folders
- The script will forcibly remove the Appx package install locations, remove Machine Learning Dlls, and hidden Copilot installers.
- Additionally, various other reg keys and files are removed to ensure a proper cleanup of AI features

#### Disable Rewrite In Notepad
- There is two methods of doing this, the first way is loading the settings.dat file from notepads appdata directory into registry and setting the `RewriteEnabled` key to false
- Later on Microsoft added a much simpler policy to disable this, the script does both methods to be sure its disabled 

#### Remove Recall Scheduled Task
- This will create another sub script in `%TEMP%` in order to run with system privileges
  - The script will agressively remove Recall's scheduled tasks by removing the files as well as the registry entries
 
#### Install Classic Apps
- This will allow you to replace/install the classic version of notepad, paint, photo viewer, and photos legacy (uwp store app)
  - Mspaint and Snipping Tool files found in the repo are extracted from Windows Server 2025 ISO as the desktop experience edition of server uses these classic apps


================================================
FILE: LICENSE
================================================
MIT License

Copyright (c) 2024 zoicware

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


================================================
FILE: OtherAIFeatures.md
================================================
## Other AI Features in Windows

- the following features cannot be disabled or removed via a script (unless further developments prove otherwise)

> [!NOTE]
> Some of these are Copilot+ PC features and can possibly be disabled via the script however, I do not have one of these systems to test with
> 

### OneDrive AI 

If you use OneDrive (not recommended) there is an AI feature to scan images for facial recognition, you can find this setting by going to `Settings > Privacy and permissions > Features > People Section`

<img width="540" height="380" alt="image" src="https://github.com/user-attachments/assets/5be01139-ded4-45f6-9692-c287d562d6ba" />


<img width="632" height="331" alt="image" src="https://github.com/user-attachments/assets/815f48f0-155f-4c57-a2e0-9fa879128205" />



### Windows Studio Effects

>[!NOTE]
> Recently, I added a method to disable AI voice effects for the mic
>
> Check to see if this is working on your system
>

If you have a Copilot+ PC (a CPU with a NPU) then you will have access to Windows Studio Effects.

These effects are AI powered features for the camera and mic.

- Make sure to check your camera and mic for these effects and disable:

<img width="648" height="568" alt="image" src="https://github.com/user-attachments/assets/7ba18488-7133-4926-b6fb-543ca737e27d" />


Here is a good guide from elevenfourms: https://www.elevenforum.com/t/enable-or-disable-windows-studio-effects-for-camera-in-windows-11.39828/






================================================
FILE: README.md
================================================
# Remove Windows Ai
## Why?
The current 25H2 build of Windows 11 and future builds will include increasingly more AI features and components. This script aims to remove ALL of these features to improve user experience, privacy and security. 

<img width="150" alt="AI-Explorer-icon" src="https://github.com/zoicware/RemoveWindowsAI/assets/118035521/33efb033-c935-416c-977d-777bb69a3737">


----------------------



### Script Features
 - **Disable Registry Keys** 
   - Disable Copilot
   - Disable Recall
   - Disable Input Insights and typing data harvesting 
   - Copilot in Edge
   - Image Creator in Paint
   - Remove AI Fabric Service
   - Disable AI Actions
   - Disable AI in Paint
   - Disable Voice Access
   - Disable AI Voice Effects
   - Disable AI in Settings Search
   - Disable Gaming Copilot
   - Disable Copilot in All Office Apps
 - **Prevent Reinstall of AI Packages**
   - Installs custom Windows Update package to prevent reinstall of AI packages in the CBS (Component-Based Servicing) store 
 - **Disable Copilot policies** 
   - Disables policies related to Copilot and Recall in IntegratedServicesRegionPolicySet.json
 - **Remove AI Appx Packages**
   - Removes all AI appx packages including `Nonremovable` packages and WindowsWorkload 
 - **Remove Recall Optional Feature**
 - **Remove AI Packages in CBS**
   - This will remove hidden and locked AI packages in the CBS (Component-Based Servicing) store 
 - **Remove AI Files**
   - This will do a full system cleanup removing all remaining AI installers, registry keys, and package files 
 - **Hide AI Components**
   - This will hide the settings page `AI Components` 
 - **Disable Rewrite AI Feature in Notepad**
 - **Remove Recall Tasks**
   - Forcibly removes all instances of Recall's scheduled tasks
  - **Update Cleanup Check**
     - Creates scheduled task to check if Windows has been updated and if it has, newly installed AI features will be removed

 - #### Install Classic Apps
   - These options will allow you to replace the modern AI infested apps with their classic version
   - **Options:** Replace Notepad, Paint, Snipping Tool, Photo Viewer, and Install Photos Legacy 
 
#### Manual AI Disabling
- Unfortunately, not all features and settings can be disabled via a script. This guide will show additional AI features to disable.
> **[Disable Other AI Features](https://github.com/zoicware/RemoveWindowsAI/blob/main/OtherAIFeatures.md)**
  
### Read the Script Docs Here
  > **[Documentation](https://github.com/zoicware/RemoveWindowsAI/blob/main/Documentation.md)**

  > [!WARNING]
  > Some third party anti-viruses will falsely detect the script as malicious, obviously this is a false positive and the anti-virus will need to be temporarily disabled or set the script as an exclusion.
  >
  > Due to the nature of making advanced changes to the system many debloat tools/scripts will be falsely detected as malware... if you are unsure about the script I always recommend testing any software in a virtual machine first

---


 ### How to Use
 
 #### Run From Powershell Console as Administrator
 ---

 > [!WARNING]
 > Running the script with PowerShell 7 is no longer supported and it WILL cause issues, to avoid this ensure you are running Windows PowerShell (5.1)
 >

 ### Launch with UI
 ```PowerShell
 & ([scriptblock]::Create((irm "https://raw.githubusercontent.com/zoicware/RemoveWindowsAI/main/RemoveWindowsAi.ps1")))
 ```
 ### Compact Command:
 ##### Link shortened using open source link shortener: https://kutt.it/
 ```PowerShell
 & ([scriptblock]::Create((irm 'https://kutt.it/RWAI')))
 ```



 <details>  
  <summary>Click to View UI</summary>
  <img width="586" height="693" alt="Capture2" src="https://github.com/user-attachments/assets/fa105ba5-c1dc-447c-ae2e-7ee373291042" />
  <img width="586" height="693" alt="Capture2" src="https://github.com/user-attachments/assets/8a446a23-7c47-468e-856b-1e783205c511" />
</details>  

&nbsp;

### Command Line Options

**Run in Non-Interactive Mode with All Options**
 ```PowerShell
 & ([scriptblock]::Create((irm "https://raw.githubusercontent.com/zoicware/RemoveWindowsAI/main/RemoveWindowsAi.ps1"))) -nonInteractive -AllOptions
 ```

--- 

**Run with Specific Options Example**
 ```PowerShell
 & ([scriptblock]::Create((irm "https://raw.githubusercontent.com/zoicware/RemoveWindowsAI/main/RemoveWindowsAi.ps1"))) -nonInteractive -Options DisableRegKeys,RemoveAppxPackages,DisableCopilotPolicies 
 ```

**All Possible Options:**
```
DisableRegKeys          
PreventAIPackageReinstall     
DisableCopilotPolicies       
RemoveAppxPackages        
RemoveRecallFeature 
RemoveCBSPackages         
RemoveAIFiles               
HideAIComponents            
DisableRewrite      
RemoveRecallTasks
UpdateCleanupCheck
```

**Run Install Classic Apps**
 ```PowerShell
 & ([scriptblock]::Create((irm "https://raw.githubusercontent.com/zoicware/RemoveWindowsAI/main/RemoveWindowsAi.ps1"))) -nonInteractive -InstallClassicApps photoviewer,mspaint,snippingtool,notepad  
 ```

**All Possible Options:**
```
photoviewer          
mspaint     
snippingtool       
notepad        
photoslegacy 
```


**Run with Backup Mode Enabled**

> [!NOTE]
> Backup Mode needs to be enabled to be able to fully revert
> 
 ```PowerShell
 & ([scriptblock]::Create((irm "https://raw.githubusercontent.com/zoicware/RemoveWindowsAI/main/RemoveWindowsAi.ps1"))) -nonInteractive -backupMode -AllOptions
 ```

---

**Revert Changes**

 ```PowerShell
 & ([scriptblock]::Create((irm "https://raw.githubusercontent.com/zoicware/RemoveWindowsAI/main/RemoveWindowsAi.ps1"))) -nonInteractive -revertMode -AllOptions
 ```

---

### Updates

Given that Microsoft are continually updating and adding new AI features this script will attempt to stay updated for the newest stable build.

You can view the newest updates to the script here:
https://github.com/zoicware/RemoveWindowsAI/commits/main/

 > [!NOTE]  
> Any feature added to an Insider build will not be added to this script till it's added to the latest stable release

 
> [!TIP]
> **Submitting an AI Feature**
>
> If you find an AI feature or registry key that is not currently removed or disabled by the script submit an issue with as much information as possible and I will add it to the script.


### Donation 

If you would like to support my work consider donating :)

[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/zoicware)


### Join The Discord

[![Discord](https://discordapp.com/api/guilds/1173717737017716777/widget.png?style=banner1)](https://discord.gg/VsC7XS5vgA)


### YT Guide
#### [How to Remove ALL Windows AI Features](https://youtu.be/j5_eEBWGHFw)



















================================================
FILE: RemoveAI-UpdateCleanup.ps1
================================================
function Run-Trusted([String]$command, $psversion) {

    function RunAsTI {
        param(
            [Parameter(Position = 0)]$cmd, 
            [Parameter(ValueFromRemainingArguments)]$xargs
        )

        $Ex = $xargs -contains '-Exit'
        $xargs = $xargs | Where-Object { $_ -ne '-Exit' }
        $wi = [Security.Principal.WindowsIdentity]::GetCurrent()
        $id = 'RunAsTI'
        $key = "Registry::HKU\$($wi.User.Value)\Volatile Environment"
        $arg = ''
        $rs = $false
        $csf = Get-PSCallStack | Where-Object { $_.ScriptName -and $_.ScriptName -like '*.ps1' } | Select-Object -l 1
        $cs = if ($csf) { $csf.ScriptName } else { $null }

        if (!$cmd) {
            if ((whoami /groups) -like '*S-1-16-16384*') { return }

            $rs = $true
            $arr = [Environment]::GetCommandLineArgs()
            $i = [array]::IndexOf($arr, '-File')
            if ($i -lt 0) { 
                $i = [array]::IndexOf($arr, '-f') 
            }

            if ($i -ge 0 -and ($i + 1) -lt $arr.Count) { 
                if (!$cs) { 
                    $cs = $arr[$i + 1] 
                } 

                if (($i + 2) -lt $arr.Count) { 
                    $arg = ($arr[($i + 2)..($arr.Count - 1)] | ForEach-Object { "`"$($_-replace'"','""')`"" }) -join ' ' 
                } 
            }
            else {
                $cp = if ($csf) { $csf.InvocationInfo.BoundParameters } else { Get-Variable PSBoundParameters -sc 1 -va -ea 0 } 

                $ca = if ($csf) { $csf.InvocationInfo.UnboundArguments } else { Get-Variable args -sc 1 -va -ea 0 }

                if ($null -eq $cp) { 
                    $cp = @{} 
                }
                if ($null -eq $ca) { 
                    $ca = @() 
                }

                $arg = (@($cp.GetEnumerator() | ForEach-Object { if (($_.Value -is [switch] -and $_.Value.IsPresent) -or ($_.Value -eq $true)) { "-$($_.Key)" }elseif ($_.Value -isnot [switch] -and $_.Value -ne $true -and $_.Value -ne $false) { "-$($_.Key) `"$($_.Value-replace'"','""')`"" } }) + @($ca | ForEach-Object { "`"$($_-replace'"','""')`"" })) -join ' '
            }

            if ($cs) { 
                $cmd = 'powershell'
                $arg = "-nop -ep bypass -f `"$cs`" $arg" 
            }
            else { 
                $cmd = 'powershell'
                $arg = '-nop -ep bypass' 
            }
        }
        elseif ($xargs) { 
            $arg = $xargs -join ' ' 
        } 

        $V = ''
        'cmd', 'arg', 'id', 'key' | ForEach-Object { $V += "`n`$$_='$($(Get-Variable $_ -val)-replace"'","''")';" }

        Set-ItemProperty $key $id $($V, @'
 $I=[int32];$M=$I.module.gettype("System.Runtime.Interop`Services.Mar`shal");$P=$I.module.gettype("System.Int`Ptr");$S=[string]
 $D=@();$T=@();$DM=[AppDomain]::CurrentDomain."DefineDynami`cAssembly"(1,1)."DefineDynami`cModule"(1);$Z=[uintptr]::size
 0..5|%{$D+=$DM."Defin`eType"("AveYo_$_",1179913,[ValueType])};$D+=[uintptr];4..6|%{$D+=$D[$_]."MakeByR`efType"()}
 $F='kernel','advapi','advapi',($S,$S,$I,$I,$I,$I,$I,$S,$D[7],$D[8]),([uintptr],$S,$I,$I,$D[9]),([uintptr],$S,$I,$I,[byte[]],$I)
 0..2|%{$9=$D[0]."DefinePInvok`eMethod"(('CreateProcess','RegOpenKeyEx','RegSetValueEx')[$_],$F[$_]+'32',8214,1,$S,$F[$_+3],1,4)}
 $DF=($P,$I,$P),($I,$I,$I,$I,$P,$D[1]),($I,$S,$S,$S,$I,$I,$I,$I,$I,$I,$I,$I,[int16],[int16],$P,$P,$P,$P),($D[3],$P),($P,$P,$I,$I)
 1..5|%{$k=$_;$n=1;$DF[$_-1]|%{$9=$D[$k]."Defin`eField"('f'+$n++,$_,6)}};0..5|%{$T+=$D[$_]."Creat`eType"()}
 0..5|%{nv "A$_" ([Activator]::CreateInstance($T[$_])) -fo};function F($1,$2){$T[0]."G`etMethod"($1).invoke(0,$2)}
 $TI=(whoami /groups)-like'*S-1-16-16384*';$As=0
 if(!$TI){'TrustedInstaller','lsass','winlogon'|%{if(!$As){$9=sc.exe start $_;$As=@(gps -name $_ -ea 0|%{$_})[0]}}
 function M($1,$2,$3){$M."G`etMethod"($1,[type[]]$2).invoke(0,$3)};$H=@();$Z,(4*$Z+16)|%{$H+=M "AllocHG`lobal" $I $_}
 M "WriteInt`Ptr" ($P,$P) ($H[0],$As.Handle);$A1.f1=131072;$A1.f2=$Z;$A1.f3=$H[0];$A2.f1=1;$A2.f2=1;$A2.f3=1;$A2.f4=1
 $A2.f6=$A1;$A3.f1=10*$Z+32;$A4.f1=$A3;$A4.f2=$H[1];M "StructureTo`Ptr" ($D[2],$P,[boolean]) (($A2-as$D[2]),$A4.f2,$false)
 $Run=@($null,"powershell -win hidden -nop -c iex `$env:R; # $id",0,0,0,0x0E080600,0,$null,($A4-as$T[4]),($A5-as$T[5]))
 F 'CreateProcess' $Run;return};$env:R='';rp $key $id -force;$priv=[diagnostics.process]."GetM`ember"('SetPrivilege',42)[0]
 'SeSecurityPrivilege','SeTakeOwnershipPrivilege','SeBackupPrivilege','SeRestorePrivilege'|%{$priv.Invoke($null,@("$_",2))}
 $HKU=[uintptr][uint32]2147483651;$NT='S-1-5-18';$reg=($HKU,$NT,8,2,($HKU-as$D[9]));F 'RegOpenKeyEx' $reg;$LNK=$reg[4]
 function L($1,$2,$3){sp 'HKLM\Software\Classes\AppID\{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}' 'RunAs' $3
  $b=[Text.Encoding]::Unicode.GetBytes("\Registry\User\$1");F 'RegSetValueEx' @($2,'SymbolicLinkValue',0,6,[byte[]]$b,$b.Length)}
 L ($key-split'\\')[1] $LNK '';$R=[diagnostics.process]::start($cmd,$arg);if($R){$R.WaitForExit()};L '.Default' $LNK 'Interactive User'
'@) -type 7

        $a = "-win hidden -nop -c `n$V `$env:R=(gi `$key -ea 0).getvalue(`$id)-join''; iex `$env:R"
        if ($Ex) { 
            $wshell = New-Object -ComObject WScript.Shell
            $exe = 'powershell.exe'
            $wshell.Run("$exe $a", 0, $false) >$null
        }
        else { 
            $wshell = New-Object -ComObject WScript.Shell
            $exe = 'powershell.exe'
            $wshell.Run("$exe $a", 0, $true) >$null # true to -wait
        } 

        # if ($rs -or $Ex) { exit }
    } 
    # lean & mean snippet by AveYo; refined by RapidOS [haslate]
    # zoicware change log:
    # changed start-process to wshell run to avoid the first powershell instance window from flashing


    $psexe = 'PowerShell.exe'

    #convert command to base64 to avoid errors with spaces
    $bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
    $base64Command = [Convert]::ToBase64String($bytes)


    try {
        Stop-Service -Name TrustedInstaller -Force -ErrorAction Stop -WarningAction Stop
    }
    catch {
        taskkill /im trustedinstaller.exe /f >$null
    }
    
    # trusted installer proc not found (128) or access denied (1)
    if ($LASTEXITCODE -eq 128 -or $LASTEXITCODE -eq 1) {
        RunAsTI $psexe "-win hidden -encodedcommand $base64Command"
        Start-Sleep 1
        return 
    }

    #get bin path to revert later
    $service = Get-CimInstance -ClassName Win32_Service -Filter "Name='TrustedInstaller'"
    $DefaultBinPath = $service.PathName
    #make sure path is valid and the correct location
    $trustedInstallerPath = "$env:SystemRoot\servicing\TrustedInstaller.exe"
    if ($DefaultBinPath -ne $trustedInstallerPath) {
        $DefaultBinPath = $trustedInstallerPath
    }
    #change bin to command
    sc.exe config TrustedInstaller binPath= "cmd.exe /c $psexe -encodedcommand $base64Command" | Out-Null
    #run the command
    sc.exe start TrustedInstaller | Out-Null
    #set bin back to default
    sc.exe config TrustedInstaller binpath= "`"$DefaultBinPath`"" | Out-Null
    try {
        Stop-Service -Name TrustedInstaller -Force -ErrorAction Stop -WarningAction Stop
    }
    catch {
        taskkill /im trustedinstaller.exe /f >$null
    }
    
}


$Global:tempDir = ([System.IO.Path]::GetTempPath())
$key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion')
$OSBuild = "$($key.GetValue('CurrentBuild')).$($key.GetValue('UBR'))"
$key.Close()
try {
    $key2 = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey('SOFTWARE\RemoveWindowsAI')
    $CurrentCachedBuild = "$($key2.GetValue('CachedBuild'))"
    $key2.Close()
}
catch {
    $CurrentCachedBuild = $null
}
$regValName = 'CachedBuild'
if ($CurrentCachedBuild -ne $OSBuild) {
    #update has occured because current cached build is not equal to current reported build
    #updated cached build
    Reg.exe add 'HKLM\SOFTWARE\RemoveWindowsAI' /v $regValName /d "$OSBuild" /t REG_SZ /f >$null

    #run through checks for reinstalled ai
    #===================================================================================================
    $code = @'
$aipackages = @(
    'MicrosoftWindows.Client.AIX'
    'MicrosoftWindows.Client.CoPilot'
    'Microsoft.Windows.Ai.Copilot.Provider'
    'Microsoft.Copilot'
    'Microsoft.MicrosoftOfficeHub'
    'MicrosoftWindows.Client.CoreAI'
    'Microsoft.Edge.GameAssist'
    'Microsoft.Office.ActionsServer'
    'aimgr'
    'Microsoft.WritingAssistant'
    'MicrosoftWindows.*.Voiess'
    'MicrosoftWindows.*.Speion'
    'MicrosoftWindows.*.Livtop'
    'MicrosoftWindows.*.InpApp'
    'MicrosoftWindows.*.Filons'
    'WindowsWorkload.Data.Analysis.Stx.*'
    'WindowsWorkload.Manager.*'
    'WindowsWorkload.PSOnnxRuntime.Stx.*'
    'WindowsWorkload.PSTokenizer.Stx.*'
    'WindowsWorkload.QueryBlockList.*'
    'WindowsWorkload.QueryProcessor.Data.*'
    'WindowsWorkload.QueryProcessor.Stx.*'
    'WindowsWorkload.SemanticText.Data.*'
    'WindowsWorkload.SemanticText.Stx.*'
    'WindowsWorkload.Data.ContentExtraction.Stx.*'
    'WindowsWorkload.ScrRegDetection.Data.*'
    'WindowsWorkload.ScrRegDetection.Stx.*'
    'WindowsWorkload.TextRecognition.Stx.*'
    'WindowsWorkload.Data.ImageSearch.Stx.*'
    'WindowsWorkload.ImageContentModeration.*'
    'WindowsWorkload.ImageContentModeration.Data.*'
    'WindowsWorkload.ImageSearch.Data.*'
    'WindowsWorkload.ImageSearch.Stx.*'
    'WindowsWorkload.ImageTextSearch.Data.*'
    'WindowsWorkload.PSOnnxRuntime.Stx.*'
    'WindowsWorkload.PSTokenizerShared.Data.*'
    'WindowsWorkload.PSTokenizerShared.Stx.*'
    'WindowsWorkload.ImageTextSearch.Stx.*'
)

$provisioned = get-appxprovisionedpackage -online 
$appxpackage = get-appxpackage -allusers
$store = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore'
$users = @('S-1-5-18'); if (test-path $store) { $users += $((Get-ChildItem $store -ea 0 | Where-Object { $_ -like '*S-1-5-21*' }).PSChildName) }

#use eol trick to uninstall some locked packages
foreach ($choice in $aipackages) {
    foreach ($appx in $($provisioned | Where-Object { $_.PackageName -like "*$choice*" })) {

        $PackageName = $appx.PackageName 
        $PackageFamilyName = ($appxpackage | Where-Object { $_.Name -eq $appx.DisplayName }).PackageFamilyName
        New-Item "$store\Deprovisioned\$PackageFamilyName" -force
     
        Set-NonRemovableAppsPolicy -Online -PackageFamilyName $PackageFamilyName -NonRemovable 0
        remove-appxprovisionedpackage -packagename $PackageName -online -allusers
    }
    foreach ($appx in $($appxpackage | Where-Object { $_.PackageFullName -like "*$choice*" })) {

        $PackageFullName = $appx.PackageFullName
        $PackageFamilyName = $appx.PackageFamilyName
        New-Item "$store\Deprovisioned\$PackageFamilyName" -force
        Set-NonRemovableAppsPolicy -Online -PackageFamilyName $PackageFamilyName -NonRemovable 0
       
        #remove inbox apps
        $inboxApp = "$store\InboxApplications\$PackageFullName"
        Remove-Item -Path $inboxApp -Force

        #get all installed user sids for package due to not all showing up in reg
        foreach ($user in $appx.PackageUserInformation) { 
            $sid = $user.UserSecurityID.SID
            New-Item "$store\EndOfLife\$sid\$PackageFullName" -force -verbose
            remove-appxpackage -package $PackageFullName -User $sid 
        } 
        remove-appxpackage -package $PackageFullName -allusers

        foreach ($sid in $users) { 
            New-Item "$store\EndOfLife\$sid\$PackageFullName" -force
        }  
    }
}
'@
    $packageRemovalPath = "$($tempDir)aiPackageRemoval.ps1"
    if (!(test-path $packageRemovalPath)) {
        New-Item $packageRemovalPath -Force | Out-Null
    }

    Set-Content -Path $packageRemovalPath -Value $code -Force 
    #allow removal script to run
    try {
        Set-ExecutionPolicy Unrestricted -Force -ErrorAction Stop
    }
    catch {
        #user has set powershell execution policy via group policy or via settings, to change it we need to update the registry 
        try {
            $Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell' -Name 'ExecutionPolicy' -ErrorAction Stop
            Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'EnableScripts' /t REG_DWORD /d '1' /f >$null
            Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
            $Global:executionPolicyUser = $false
            $Global:executionPolicyMachine = $false
            $Global:executionPolicyWow64 = $false
            $Global:executionPolicyUserPol = $false
        }
        catch {
            try {
                $Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKCU:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' -Name 'ExecutionPolicy' -ErrorAction Stop
                Reg.exe add 'HKCU\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
                $Global:executionPolicyUser = $true
                $Global:executionPolicyMachine = $false
                $Global:executionPolicyWow64 = $false
                $Global:executionPolicyUserPol = $false
            }
            catch {
                try {
                    $Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKLM:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' -Name 'ExecutionPolicy' -ErrorAction Stop
                    Reg.exe add 'HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
                    $Global:executionPolicyUser = $false
                    $Global:executionPolicyMachine = $true
                    $Global:executionPolicyWow64 = $false
                    $Global:executionPolicyUserPol = $false
                }
                catch {
                    try {
                        $Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' -Name 'ExecutionPolicy' -ErrorAction Stop
                        Reg.exe add 'HKLM\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
                        $Global:executionPolicyUser = $false
                        $Global:executionPolicyMachine = $false
                        $Global:executionPolicyWow64 = $true
                        $Global:executionPolicyUserPol = $false

                    }
                    catch {
                        $Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKCU:\SOFTWARE\Policies\Microsoft\Windows\PowerShell' -Name 'ExecutionPolicy' 
                        Reg.exe add 'HKCU\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'EnableScripts' /t REG_DWORD /d '1' /f >$null
                        Reg.exe add 'HKCU\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
                        $Global:executionPolicyUser = $false
                        $Global:executionPolicyMachine = $false
                        $Global:executionPolicyWow64 = $false
                        $Global:executionPolicyUserPol = $true
                    }
                        

                }
                    
            }
               
        }
            
           
    }

    $command = "&`"$($tempDir)aiPackageRemoval.ps1`""
    Run-Trusted -command $command

    #needed for separate powershell sessions
    $aipackages = @(
        # 'MicrosoftWindows.Client.Photon'
        'MicrosoftWindows.Client.AIX'
        'MicrosoftWindows.Client.CoPilot'
        'Microsoft.Windows.Ai.Copilot.Provider'
        'Microsoft.Copilot'
        'Microsoft.MicrosoftOfficeHub'
        'MicrosoftWindows.Client.CoreAI'
        'Microsoft.Edge.GameAssist'
        'Microsoft.Office.ActionsServer'
        'aimgr'
        'Microsoft.WritingAssistant'
        #ai component packages installed on copilot+ pcs
        'MicrosoftWindows.*.Voiess'
        'MicrosoftWindows.*.Speion'
        'MicrosoftWindows.*.Livtop'
        'MicrosoftWindows.*.InpApp'
        'MicrosoftWindows.*.Filons'
        'WindowsWorkload.Data.Analysis.Stx.*'
        'WindowsWorkload.Manager.*'
        'WindowsWorkload.PSOnnxRuntime.Stx.*'
        'WindowsWorkload.PSTokenizer.Stx.*'
        'WindowsWorkload.QueryBlockList.*'
        'WindowsWorkload.QueryProcessor.Data.*'
        'WindowsWorkload.QueryProcessor.Stx.*'
        'WindowsWorkload.SemanticText.Data.*'
        'WindowsWorkload.SemanticText.Stx.*'
        'WindowsWorkload.Data.ContentExtraction.Stx.*'
        'WindowsWorkload.ScrRegDetection.Data.*'
        'WindowsWorkload.ScrRegDetection.Stx.*'
        'WindowsWorkload.TextRecognition.Stx.*'
        'WindowsWorkload.Data.ImageSearch.Stx.*'
        'WindowsWorkload.ImageContentModeration.*'
        'WindowsWorkload.ImageContentModeration.Data.*'
        'WindowsWorkload.ImageSearch.Data.*'
        'WindowsWorkload.ImageSearch.Stx.*'
        'WindowsWorkload.ImageTextSearch.Data.*'
        'WindowsWorkload.PSOnnxRuntime.Stx.*'
        'WindowsWorkload.PSTokenizerShared.Data.*'
        'WindowsWorkload.PSTokenizerShared.Stx.*'
        'WindowsWorkload.ImageTextSearch.Stx.*'
    )

    #check packages removal
    #exit loop after 10 tries
    $attempts = 0
    do {
        Start-Sleep 1
        $packages = get-appxpackage -AllUsers | Where-Object { $aipackages -contains $_.Name }
        if ($packages) {
            $attempts++
            $command = "&`"$($tempDir)aiPackageRemoval.ps1`""
            Run-Trusted -command $command
        }
    
    }while ($packages -and $attempts -lt 10)


    #add registry keys even tho im pretty sure they dont get changed 
    #add maybe some file cleanup




    #set executionpolicy back to what it was
    if ($ogExecutionPolicy) {
        if ($Global:executionPolicyUser) {
            Reg.exe add 'HKCU\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d $ogExecutionPolicy /f >$null
        }
        elseif ($Global:executionPolicyMachine) {
            Reg.exe add 'HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d $ogExecutionPolicy /f >$null
        }
        elseif ($Global:executionPolicyWow64) {
            Reg.exe add 'HKLM\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d $ogExecutionPolicy /f >$null
        }
        elseif ($Global:executionPolicyUserPol) {
            Reg.exe add 'HKCU\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d $ogExecutionPolicy /f >$null
        }
        else {
            Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d $ogExecutionPolicy /f >$null
        }
    }
}

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_16bf9f5ddcdcc858358ce8a2a9f69f935b0e2c72_31bf3856ad364e35_38655.38527.65535.65535_none_9dea49e759204384.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="16bf9f5ddcdcc858358ce8a2a9f69f935b0e2c72" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="Microsoft-Copilot-Deployment-LanguagePack" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_1ac4efa52cc987e34206a4b499ef297c16f443f9_31bf3856ad364e35_38655.38527.65535.65535_none_d12a7b37e1ce0c63.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="1ac4efa52cc987e34206a4b499ef297c16f443f9" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="UserExperience-CoreAI" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_3e5f6992f365ae98da785153cb853cdd2b8d334d_31bf3856ad364e35_38655.38527.65535.65535_none_21a198b98b0eb5cb.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="3e5f6992f365ae98da785153cb853cdd2b8d334d" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="UserExperience-CoreAI-Deployment" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_690413e3dcead26f87b3989953c5ed27bb12eb95_31bf3856ad364e35_38655.38527.65535.65535_none_2f5fa210a2da208e.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="690413e3dcead26f87b3989953c5ed27bb12eb95" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="Microsoft-Windows-SystemSettings-SettingsHandlers-Copilot" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_761f3629e488278caa4c7585c950f520404712cf_31bf3856ad364e35_38655.38527.65535.65535_none_fab6052e6768b003.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="761f3629e488278caa4c7585c950f520404712cf" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="UserExperience-AIX-Deployment" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_a1b65e8b129c7dfee79b5234097d94812770c52a_31bf3856ad364e35_38655.38527.65535.65535_none_427e504fcbfba8f2.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="a1b65e8b129c7dfee79b5234097d94812770c52a" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="Microsoft-Copilot" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_bf9f7f39101e056d32e46992b64d45da3774921c_31bf3856ad364e35_38655.38527.65535.65535_none_1b7aa6c634649ec5.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="bf9f7f39101e056d32e46992b64d45da3774921c" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="UserExperience-AIX" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_c93ca6c2cd59575fe45bad46f6152c80cc5ab492_31bf3856ad364e35_38655.38527.65535.65535_none_048f8255f6dd3270.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="c93ca6c2cd59575fe45bad46f6152c80cc5ab492" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="UserExperience-Recall" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_d18d700de06fc98ae558e2a73994193f028d6209_31bf3856ad364e35_38655.38527.65535.65535_none_99bf2484525af2f0.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="d18d700de06fc98ae558e2a73994193f028d6209" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="Microsoft-Copilot-Deployment" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_microsoft-copilot-d..oyment-languagepack_31bf3856ad364e35_38655.38527.65535.65535_none_0fea620d27c4484e.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="Microsoft-Copilot-Deployment-LanguagePack" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_microsoft-copilot-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_26df2268220c2a52.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="Microsoft-Copilot-Deployment" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_microsoft-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_58a35da8a335eb56.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="Microsoft-Copilot" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_microsoft-windows-s..ngshandlers-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_f88b80f068ad03a6.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="Microsoft-Windows-SystemSettings-SettingsHandlers-Copilot" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_userexperience-aix-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_cdba7e3535b8898d.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="UserExperience-AIX-Deployment" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_userexperience-aix_31bf3856ad364e35_38655.38527.65535.65535_none_293807153aa35c79.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="UserExperience-AIX" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_userexperience-coreai-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_494247c8d14488ba.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="UserExperience-CoreAI-Deployment" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_userexperience-coreai_31bf3856ad364e35_38655.38527.65535.65535_none_851c3d913b2d96b4.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="UserExperience-CoreAI" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/amd64/amd64_userexperience-recall_31bf3856ad364e35_38655.38527.65535.65535_none_d1d3458f41002cd0.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="UserExperience-Recall" version="38655.38527.65535.65535" processorArchitecture="amd64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_072c8668ec63514fc98714c09cef5ffb61eac4d0_31bf3856ad364e35_38655.38527.65535.65535_none_fc8a4193bbbf8ce9.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="072c8668ec63514fc98714c09cef5ffb61eac4d0" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="UserExperience-CoreAI-Deployment" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_19b4f2d2eb01fe86e2858f3356507a3743d63a96_31bf3856ad364e35_38655.38527.65535.65535_none_c3b6ebc0bc9bc32a.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="19b4f2d2eb01fe86e2858f3356507a3743d63a96" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="Microsoft-Copilot" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_2415624e03eaf74c3ed2718f0823e7ef1746afdd_31bf3856ad364e35_38655.38527.65535.65535_none_8ebe44a9559113a2.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="2415624e03eaf74c3ed2718f0823e7ef1746afdd" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="UserExperience-CoreAI" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_37e84906b7c3ad6ec7fd0f73eb941da2bbd40170_31bf3856ad364e35_38655.38527.65535.65535_none_4755105c8785546a.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="37e84906b7c3ad6ec7fd0f73eb941da2bbd40170" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="Microsoft-Copilot-Deployment" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_9977ad932a57937cbd5b595b7054ef37a6fa80d7_31bf3856ad364e35_38655.38527.65535.65535_none_176e9ba77eb5736f.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="9977ad932a57937cbd5b595b7054ef37a6fa80d7" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="UserExperience-AIX-Deployment" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_af04861f8804c4ce83a52310a455da3f912b468f_31bf3856ad364e35_38655.38527.65535.65535_none_9c9d75201debd11a.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="af04861f8804c4ce83a52310a455da3f912b468f" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="UserExperience-Recall" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_b1c39ab687ddb87f21e0bef8191922a64760b277_31bf3856ad364e35_38655.38527.65535.65535_none_8c5f153cdaa8c371.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="b1c39ab687ddb87f21e0bef8191922a64760b277" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="Microsoft-Copilot-Deployment-LanguagePack" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_d555b631e519d0dcd7872958a590cb5e81441910_31bf3856ad364e35_38655.38527.65535.65535_none_ab9a0f7301cc9b81.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="d555b631e519d0dcd7872958a590cb5e81441910" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="Microsoft-Windows-SystemSettings-SettingsHandlers-Copilot" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_f9b5a2b834a34ab4b8fa8da477a953885907d528_31bf3856ad364e35_38655.38527.65535.65535_none_a9f36e0ec06d9f38.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="f9b5a2b834a34ab4b8fa8da477a953885907d528" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/><deployment xmlns="urn:schemas-microsoft-com:asm.v3"/><dependency discoverable="false"><dependentAssembly dependencyType="install"><assemblyIdentity name="UserExperience-AIX" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS"/></dependentAssembly></dependency></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_microsoft-copilot-d..oyment-languagepack_31bf3856ad364e35_38655.38527.65535.65535_none_0fea6a4727c43cea.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="Microsoft-Copilot-Deployment-LanguagePack" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_microsoft-copilot-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_26df2aa2220c1eee.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="Microsoft-Copilot-Deployment" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_microsoft-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_58a365e2a335dff2.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="Microsoft-Copilot" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_microsoft-windows-s..ngshandlers-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_f88b892a68acf842.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="Microsoft-Windows-SystemSettings-SettingsHandlers-Copilot" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_userexperience-aix-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_cdba866f35b87e29.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="UserExperience-AIX-Deployment" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_userexperience-aix_31bf3856ad364e35_38655.38527.65535.65535_none_29380f4f3aa35115.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="UserExperience-AIX" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_userexperience-coreai-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_49425002d1447d56.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="UserExperience-CoreAI-Deployment" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_userexperience-coreai_31bf3856ad364e35_38655.38527.65535.65535_none_851c45cb3b2d8b50.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="UserExperience-CoreAI" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAIPackage/arm64/arm64_userexperience-recall_31bf3856ad364e35_38655.38527.65535.65535_none_d1d34dc94100216c.manifest
================================================
<?xml version="1.0" encoding="utf-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0" copyright="Zoicware"><assemblyIdentity name="UserExperience-Recall" version="38655.38527.65535.65535" processorArchitecture="arm64" language="neutral" buildType="release" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /></assembly>

================================================
FILE: RemoveWindowsAi.ps1
================================================
param(
    [switch]$EnableLogging,
    [switch]$nonInteractive,
    [ValidateSet('DisableRegKeys',          
        'PreventAIPackageReinstall',     
        'DisableCopilotPolicies',       
        'RemoveAppxPackages',        
        'RemoveRecallFeature', 
        'RemoveCBSPackages',         
        'RemoveAIFiles',               
        'HideAIComponents',            
        'DisableRewrite',       
        'RemoveRecallTasks',
        'UpdateCleanupCheck')]
    [array]$Options,
    [switch]$AllOptions,
    [switch]$revertMode,
    [switch]$backupMode,
    [ValidateSet('photoviewer', 'mspaint', 'snippingtool', 'notepad', 'photoslegacy')]
    [array]$InstallClassicApps,
    [switch]$RunWinUpdateRepair
)

if ($nonInteractive) {
    if (!($AllOptions) -and (!$Options -or $Options.Count -eq 0) -and !($InstallClassicApps)) {
        throw 'Non-Interactive mode was supplied without any options... Please use -Options or -AllOptions when using Non-Interactive Mode'
        exit
    }
}


#get powershell version to ensure run-trusted doesnt enter an infinite loop
$version = $PSVersionTable.PSVersion
if ($version -like '7*') {
    $Global:psversion = 7
}
else {
    $Global:psversion = 5
}

if ($psversion -ge 7) {
    Write-Host 'ERROR: This script requires Windows PowerShell 5.1 (powershell.exe).' -ForegroundColor Red
    Write-Host "You are currently running PowerShell version $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)." -ForegroundColor Red
    Write-Host 'PowerShell 7+ (pwsh.exe) is not supported. Please run the script using the classic Windows PowerShell 5.1.' -ForegroundColor Red
    if (-not $nonInteractive) {
        try {
            Add-Type -AssemblyName System.Windows.Forms
            [System.Windows.Forms.MessageBox]::Show(
                "This script must be run in Windows PowerShell 5.1.`n`nCurrent version: $($PSVersionTable.PSVersion)`n`nPlease use powershell.exe instead of pwsh.exe.",
                'PowerShell Version Error',
                [System.Windows.Forms.MessageBoxButtons]::OK,
                [System.Windows.Forms.MessageBoxIcon]::Error
            ) | Out-Null
        }
        catch { }
    }
    exit 1
}

If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) {
    #leave out the trailing " to add supplied params first 
    $arglist = "-NoProfile -ExecutionPolicy Bypass -C `"& ([scriptblock]::Create((irm 'https://raw.githubusercontent.com/zoicware/RemoveWindowsAI/main/RemoveWindowsAi.ps1')))"
    #pass the correct params if supplied
    if ($nonInteractive) {
        $arglist = $arglist + ' -nonInteractive'

        if ($AllOptions) {
            $arglist = $arglist + ' -AllOptions'
        }

        if ($revertMode) {
            $arglist = $arglist + ' -revertMode'
        }

        if ($backupMode) {
            $arglist = $arglist + ' -backupMode'
        }


        if ($Options -and $Options.count -ne 0) {
            #if options and alloptions is supplied just do all options
            if ($AllOptions) {
                #double check arglist has all options (should already have it)
                if (!($arglist -like '*-AllOptions*')) {
                    $arglist = $arglist + ' -AllOptions'
                }
            }
            else {
                $arglist = $arglist + " -Options $Options"
            }
        }

        if ($InstallClassicApps -and $InstallClassicApps.Count -ne 0) {
            $arglist = $arglist + " -InstallClassicApps $InstallClassicApps"
        }
    }

    if ($EnableLogging) {
        $arglist = $arglist + ' -EnableLogging'
    }

    #add the trailing quote 
    $arglist = $arglist + '"'
    Start-Process PowerShell.exe -ArgumentList $arglist -Verb RunAs
    Exit	
}

Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms

function Run-Trusted([String]$command, $psversion) {

    function RunAsTI {
        param(
            [Parameter(Position = 0)]$cmd, 
            [Parameter(ValueFromRemainingArguments)]$xargs
        )

        $Ex = $xargs -contains '-Exit'
        $xargs = $xargs | Where-Object { $_ -ne '-Exit' }
        $wi = [Security.Principal.WindowsIdentity]::GetCurrent()
        $id = 'RunAsTI'
        $key = "Registry::HKU\$($wi.User.Value)\Volatile Environment"
        $arg = ''
        $rs = $false
        $csf = Get-PSCallStack | Where-Object { $_.ScriptName -and $_.ScriptName -like '*.ps1' } | Select-Object -l 1
        $cs = if ($csf) { $csf.ScriptName } else { $null }

        if (!$cmd) {
            if ((whoami /groups) -like '*S-1-16-16384*') { return }

            $rs = $true
            $arr = [Environment]::GetCommandLineArgs()
            $i = [array]::IndexOf($arr, '-File')
            if ($i -lt 0) { 
                $i = [array]::IndexOf($arr, '-f') 
            }

            if ($i -ge 0 -and ($i + 1) -lt $arr.Count) { 
                if (!$cs) { 
                    $cs = $arr[$i + 1] 
                } 

                if (($i + 2) -lt $arr.Count) { 
                    $arg = ($arr[($i + 2)..($arr.Count - 1)] | ForEach-Object { "`"$($_-replace'"','""')`"" }) -join ' ' 
                } 
            }
            else {
                $cp = if ($csf) { $csf.InvocationInfo.BoundParameters } else { Get-Variable PSBoundParameters -sc 1 -va -ea 0 } 

                $ca = if ($csf) { $csf.InvocationInfo.UnboundArguments } else { Get-Variable args -sc 1 -va -ea 0 }

                if ($null -eq $cp) { 
                    $cp = @{} 
                }
                if ($null -eq $ca) { 
                    $ca = @() 
                }

                $arg = (@($cp.GetEnumerator() | ForEach-Object { if (($_.Value -is [switch] -and $_.Value.IsPresent) -or ($_.Value -eq $true)) { "-$($_.Key)" }elseif ($_.Value -isnot [switch] -and $_.Value -ne $true -and $_.Value -ne $false) { "-$($_.Key) `"$($_.Value-replace'"','""')`"" } }) + @($ca | ForEach-Object { "`"$($_-replace'"','""')`"" })) -join ' '
            }

            if ($cs) { 
                $cmd = 'powershell'
                $arg = "-nop -ep bypass -f `"$cs`" $arg" 
            }
            else { 
                $cmd = 'powershell'
                $arg = '-nop -ep bypass' 
            }
        }
        elseif ($xargs) { 
            $arg = $xargs -join ' ' 
        } 

        $V = ''
        'cmd', 'arg', 'id', 'key' | ForEach-Object { $V += "`n`$$_='$($(Get-Variable $_ -val)-replace"'","''")';" }

        Set-ItemProperty $key $id $($V, @'
 $I=[int32];$M=$I.module.gettype("System.Runtime.Interop`Services.Mar`shal");$P=$I.module.gettype("System.Int`Ptr");$S=[string]
 $D=@();$T=@();$DM=[AppDomain]::CurrentDomain."DefineDynami`cAssembly"(1,1)."DefineDynami`cModule"(1);$Z=[uintptr]::size
 0..5|%{$D+=$DM."Defin`eType"("AveYo_$_",1179913,[ValueType])};$D+=[uintptr];4..6|%{$D+=$D[$_]."MakeByR`efType"()}
 $F='kernel','advapi','advapi',($S,$S,$I,$I,$I,$I,$I,$S,$D[7],$D[8]),([uintptr],$S,$I,$I,$D[9]),([uintptr],$S,$I,$I,[byte[]],$I)
 0..2|%{$9=$D[0]."DefinePInvok`eMethod"(('CreateProcess','RegOpenKeyEx','RegSetValueEx')[$_],$F[$_]+'32',8214,1,$S,$F[$_+3],1,4)}
 $DF=($P,$I,$P),($I,$I,$I,$I,$P,$D[1]),($I,$S,$S,$S,$I,$I,$I,$I,$I,$I,$I,$I,[int16],[int16],$P,$P,$P,$P),($D[3],$P),($P,$P,$I,$I)
 1..5|%{$k=$_;$n=1;$DF[$_-1]|%{$9=$D[$k]."Defin`eField"('f'+$n++,$_,6)}};0..5|%{$T+=$D[$_]."Creat`eType"()}
 0..5|%{nv "A$_" ([Activator]::CreateInstance($T[$_])) -fo};function F($1,$2){$T[0]."G`etMethod"($1).invoke(0,$2)}
 $TI=(whoami /groups)-like'*S-1-16-16384*';$As=0
 if(!$TI){'TrustedInstaller','lsass','winlogon'|%{if(!$As){$9=sc.exe start $_;$As=@(gps -name $_ -ea 0|%{$_})[0]}}
 function M($1,$2,$3){$M."G`etMethod"($1,[type[]]$2).invoke(0,$3)};$H=@();$Z,(4*$Z+16)|%{$H+=M "AllocHG`lobal" $I $_}
 M "WriteInt`Ptr" ($P,$P) ($H[0],$As.Handle);$A1.f1=131072;$A1.f2=$Z;$A1.f3=$H[0];$A2.f1=1;$A2.f2=1;$A2.f3=1;$A2.f4=1
 $A2.f6=$A1;$A3.f1=10*$Z+32;$A4.f1=$A3;$A4.f2=$H[1];M "StructureTo`Ptr" ($D[2],$P,[boolean]) (($A2-as$D[2]),$A4.f2,$false)
 $Run=@($null,"powershell -win hidden -nop -c iex `$env:R; # $id",0,0,0,0x0E080600,0,$null,($A4-as$T[4]),($A5-as$T[5]))
 F 'CreateProcess' $Run;return};$env:R='';rp $key $id -force;$priv=[diagnostics.process]."GetM`ember"('SetPrivilege',42)[0]
 'SeSecurityPrivilege','SeTakeOwnershipPrivilege','SeBackupPrivilege','SeRestorePrivilege'|%{$priv.Invoke($null,@("$_",2))}
 $HKU=[uintptr][uint32]2147483651;$NT='S-1-5-18';$reg=($HKU,$NT,8,2,($HKU-as$D[9]));F 'RegOpenKeyEx' $reg;$LNK=$reg[4]
 function L($1,$2,$3){sp 'HKLM\Software\Classes\AppID\{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}' 'RunAs' $3
  $b=[Text.Encoding]::Unicode.GetBytes("\Registry\User\$1");F 'RegSetValueEx' @($2,'SymbolicLinkValue',0,6,[byte[]]$b,$b.Length)}
 L ($key-split'\\')[1] $LNK '';$R=[diagnostics.process]::start($cmd,$arg);if($R){$R.WaitForExit()};L '.Default' $LNK 'Interactive User'
'@) -type 7

        $a = "-win hidden -nop -c `n$V `$env:R=(gi `$key -ea 0).getvalue(`$id)-join''; iex `$env:R"
        if ($Ex) { 
            $wshell = New-Object -ComObject WScript.Shell
            $exe = 'powershell.exe'
            $wshell.Run("$exe $a", 0, $false) >$null
        }
        else { 
            $wshell = New-Object -ComObject WScript.Shell
            $exe = 'powershell.exe'
            $wshell.Run("$exe $a", 0, $true) >$null # true to -wait
        } 

        # if ($rs -or $Ex) { exit }
    } 
    # lean & mean snippet by AveYo; refined by RapidOS [haslate]
    # zoicware change log:
    # changed start-process to wshell run to avoid the first powershell instance window from flashing


    $psexe = 'PowerShell.exe'

    #convert command to base64 to avoid errors with spaces
    $bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
    $base64Command = [Convert]::ToBase64String($bytes)


    try {
        Stop-Service -Name TrustedInstaller -Force -ErrorAction Stop -WarningAction Stop
    }
    catch {
        taskkill /im trustedinstaller.exe /f >$null
    }
    
    # trusted installer proc not found (128) or access denied (1)
    if ($LASTEXITCODE -eq 128 -or $LASTEXITCODE -eq 1) {
        Write-Status -msg 'Failed to stop TrustedInstaller.exe... Using fallback method!' -warningOutput
        RunAsTI $psexe "-win hidden -encodedcommand $base64Command"
        Start-Sleep 1
        return 
    }

    #get bin path to revert later
    $service = Get-CimInstance -ClassName Win32_Service -Filter "Name='TrustedInstaller'"
    $DefaultBinPath = $service.PathName
    #make sure path is valid and the correct location
    $trustedInstallerPath = "$env:SystemRoot\servicing\TrustedInstaller.exe"
    if ($DefaultBinPath -ne $trustedInstallerPath) {
        $DefaultBinPath = $trustedInstallerPath
    }
    #change bin to command
    sc.exe config TrustedInstaller binPath= "cmd.exe /c $psexe -encodedcommand $base64Command" | Out-Null
    #run the command
    sc.exe start TrustedInstaller | Out-Null
    #set bin back to default
    sc.exe config TrustedInstaller binpath= "`"$DefaultBinPath`"" | Out-Null
    try {
        Stop-Service -Name TrustedInstaller -Force -ErrorAction Stop -WarningAction Stop
    }
    catch {
        taskkill /im trustedinstaller.exe /f >$null
    }
    
}


function Write-Status {
    param(
        [string]$msg,
        [switch]$errorOutput,
        [switch]$warningOutput
    )
    if ($errorOutput) {
        Write-Host "[ ! ERROR ] $msg" -ForegroundColor Red
    }
    elseif ($warningOutput) {
        Write-Host "[ * WARNING ] $msg" -ForegroundColor Yellow
    }
    else {
        Write-Host "[ + ] $msg" -ForegroundColor Cyan
    }
   
    
}

#some users have messed with the system envrioment variables (for some reason) this breaks inline cmdlets like Reg.exe 
#to fix this we can ensure the enviroment variable for this powershell session is set properly
if ($env:PATH -notlike "*$env:SystemRoot\system32;*") {
    Write-Status -msg "System Envrioment Variable 'PATH' is corrupted! Fixing for script session..." -errorOutput
    $env:PATH = "$env:SystemRoot\system32;$env:SystemRoot;$env:SystemRoot\System32\Wbem;" + $env:PATH
}


#setup script
#=====================================================================================

Write-Host '~ ~ ~ Remove Windows AI by @zoicware ~ ~ ~' -ForegroundColor DarkCyan

if ($EnableLogging) {
    $date = (Get-Date).ToString('MM-dd-yyyy-HH:mm') -replace ':'
    $Global:logPath = "$env:USERPROFILE\RemoveWindowsAI$date.log"
    New-Item $logPath -Force | Out-Null
    Write-Status -msg "Starting Log at [$logPath]"
    #start and stop the transcript to get the header
    Start-Transcript -Path $logPath -IncludeInvocationHeader | Out-Null
    Stop-Transcript | Out-Null

    #create info object
    $Global:logInfo = [PSCustomObject]@{
        Line   = $null
        Result = $null
    }
}

if ($revertMode) {
    $Global:revert = 1
}
else {
    $Global:revert = 0
}

if ($backupMode) {
    $Global:backup = 1
}
else {
    $Global:backup = 0
}

$Global:tempDir = ([System.IO.Path]::GetTempPath())

#=====================================================================================

function Add-LogInfo {
    param(
        [string]$logPath,
        $info
    )

    $content = @"
    ====================================
    Line: $($info.Line)
    Result: $($info.Result)
"@

    Add-Content $logPath -Value $content | Out-Null
}


function Create-RestorePoint {
    param(
        [switch]$nonInteractive
    )

    #check vss service first
    $vssService = Get-Service -Name 'VSS' -ErrorAction SilentlyContinue
    if ($vssService -and $vssService.StartType -eq 'Disabled') {
        try {
            Write-Status -msg 'Enabling VSS Service...'
            Set-Service -Name 'VSS' -StartupType Manual -ErrorAction Stop
            Start-Service -Name 'VSS' -ErrorAction Stop
        }
        catch {
            Write-Status -msg 'Unable to Start VSS Service... Can not create restore point!' -errorOutput
            return
        }
        
    }
    #enable system protection to allow restore points
    $restoreEnabled = Get-ComputerRestorePoint -ErrorAction SilentlyContinue
    if (!$restoreEnabled) {
        Write-Status -msg 'Enabling Restore Points on System...'
        Enable-ComputerRestore -Drive "$env:SystemDrive\" 
    }

    
    if ($nonInteractive) {
        #allow restore point to be created even if one was just made
        $restoreFreqPath = 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\SystemRestore'
        $restoreFreqKey = 'SystemRestorePointCreationFrequency'
        $currentValue = (Get-ItemProperty -Path $restoreFreqPath -Name $restoreFreqKey -ErrorAction SilentlyContinue).$restoreFreqKey
        if ($currentValue -ne 0) {
            Set-ItemProperty -Path $restoreFreqPath -Name $restoreFreqKey -Value 0 -Force
        }

        $restorePointName = "RemoveWindowsAI-$(Get-Date -Format 'yyyy-MM-dd')"
        Write-Status -msg "Creating Restore Point: [$restorePointName]"
        Write-Status -msg 'This may take a moment...please wait'
        Checkpoint-Computer -Description $restorePointName -RestorePointType 'MODIFY_SETTINGS' 
    }
    else {
        Write-Status -msg 'Opening Restore Point Dialog...'
        try {
            $proc = Start-Process 'SystemPropertiesProtection.exe' -ErrorAction Stop -PassThru
        }
        catch {
            $proc = Start-Process 'C:\Windows\System32\control.exe' -ArgumentList 'sysdm.cpl ,4' -PassThru
        }
        #click configure on the window
        Start-Sleep 1
        Add-Type -AssemblyName System.Windows.Forms
        [System.Windows.Forms.SendKeys]::SendWait('%c') 
        Wait-Process -Id $proc.Id
    }

}

function Set-UwpAppRegistryEntry {
    # modified to work in windows powershell from https://github.com/agadiffe/WindowsMize/blob/fe78912ccb1c83d440bd2123f5e43a6156fab31a/src/modules/applications/settings/public/Set-UwpAppSetting.ps1
    <# 
    .SYNOPSIS
        Modifies UWP app registry entries in the settings.dat file.
    
    .EXAMPLE
        PS> $setting = [PSCustomObject]@{
                Name  = 'VideoAutoplay'
                Value = '0'
                Type  = '5f5e10b'
            }
        PS> $setting | Set-UwpAppRegistryEntry -FilePath $FilePath
    #>

    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory, ValueFromPipeline)]
        $InputObject,

        [Parameter(Mandatory)]
        [string] $FilePath
    )

    begin {
        $AppSettingsRegPath = 'HKEY_USERS\APP_SETTINGS'
        $RegContent = "Windows Registry Editor Version 5.00`n"

        reg.exe UNLOAD $AppSettingsRegPath 2>&1 | Out-Null

        $max = 30
        $attempts = 0
        $ProcessToStop = @(
            'AppActions'
            'SearchHost'
            'FESearchHost'
            'msedgewebview2'
            'TextInputHost'
            'VisualAssistExe'
            'WebExperienceHostApp'
            'WindowsMigration'
            'WindowsBackupClient'
            'SoftLandingTask'
            'DesktopStickerEditorWin32Exe'
            'CrossDeviceResume'
            'DiscoveryHubApp'
        )
        Stop-Process -Name $ProcessToStop -Force -ErrorAction SilentlyContinue 
        # do while is needed here because wait-process in this case is not working maybe cause its just a trash function lol
        # using microsofts own example found in the docs does not work 
        # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/wait-process?view=powershell-7.5#example-1-stop-a-process-and-wait

        # since we are trying multiple times while the processes are stopping this will work as soon as the file is freed 
        do {
            reg.exe LOAD $AppSettingsRegPath $FilePath *>$null
            $attempts++
        } while ($LASTEXITCODE -ne 0 -and $attempts -lt $max)
    
        if ($LASTEXITCODE -ne 0) {
            Write-Status -msg 'Unable to load settings.dat' -errorOutput
            return
        }
      
    }

    process {
        $Value = $InputObject.Value
        $Value = switch ($InputObject.Type) {
            '5f5e10b' { 
                # Single byte for boolean
                '{0:x2}' -f [byte][int]$Value
            }
            '5f5e10c' { 
                # Unicode string 
                $bytes = [System.Text.Encoding]::Unicode.GetBytes($Value + "`0")
                ($bytes | ForEach-Object { '{0:x2}' -f $_ }) -join ' ' 
            }
            '5f5e104' { 
                # Int32
                $bytes = [BitConverter]::GetBytes([int]$Value)
                ($bytes | ForEach-Object { '{0:x2}' -f $_ }) -join ' '
            }
            '5f5e105' { 
                # UInt32
                $bytes = [BitConverter]::GetBytes([uint32]$Value)
                ($bytes | ForEach-Object { '{0:x2}' -f $_ }) -join ' '
            }
            '5f5e106' { 
                # Int64
                $bytes = [BitConverter]::GetBytes([int64]$Value)
                ($bytes | ForEach-Object { '{0:x2}' -f $_ }) -join ' '
            }
        }

        $Value = $Value -replace '\s+', ','
    
        # create timestamp for remaining bytes
        $timestampBytes = [BitConverter]::GetBytes([int64](Get-Date).ToFileTime())
        $Timestamp = ($timestampBytes | ForEach-Object { '{0:x2}' -f $_ }) -join ','
    
        # build registry content
        if ($InputObject.Path) {
            $RegKey = $InputObject.Path
        }
        else {
            $RegKey = 'LocalState'
        }
        $RegContent += "`n[$AppSettingsRegPath\$RegKey]
        ""$($InputObject.Name)""=hex($($InputObject.Type)):$Value,$Timestamp`n" -replace '(?m)^ *'
    }

    end {
        $SettingRegFilePath = "$($tempDir)uwp_app_settings.reg"
        $RegContent | Out-File -FilePath $SettingRegFilePath

        reg.exe IMPORT $SettingRegFilePath 2>&1 | Out-Null
        reg.exe UNLOAD $AppSettingsRegPath | Out-Null

        Remove-Item -Path $SettingRegFilePath
    }
}

function Disable-Registry-Keys {
    #maybe add params for particular parts

    #disable ai registry keys
    Write-Status -msg "$(@('Disabling', 'Enabling')[$revert]) Copilot and Recall..."
    <#
    #new keys related to windows ai schedled task 
    #npu check 
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsAI\LastConfiguration' /v 'HardwareCompatibility' /t REG_DWORD /d '0' /f 
    #dont know
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsAI\LastConfiguration' /v 'ITManaged' /t REG_DWORD /d '0' /f
    #enabled by windows ai schedled task 
    #set to 1 in the us 
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsAI\LastConfiguration' /v 'AllowedInRegion' /t REG_DWORD /d '0' /f
    #enabled by windows ai schelded task 
    # policy enabled = 1 when recall is enabled in group policy 
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsAI\LastConfiguration' /v 'PolicyConfigured' /t REG_DWORD /d '0' /f
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsAI\LastConfiguration' /v 'PolicyEnabled' /t REG_DWORD /d '0' /f
    #dont know
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsAI\LastConfiguration' /v 'FTDisabledState' /t REG_DWORD /d '0' /f
    #prob the npu check failing
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsAI\LastConfiguration' /v 'MeetsAdditionalDriverRequirements' /t REG_DWORD /d '0' /f
    #sucess from last run 
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsAI\LastConfiguration' /v 'LastOperationKind' /t REG_DWORD /d '2' /f
    #doesnt install recall for me so 0
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsAI\LastConfiguration' /v 'AttemptedInstallCount' /t REG_DWORD /d '0' /f
    #windows build
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsAI\LastConfiguration' /v 'LastBuild' /t REG_DWORD /d '7171' /f
    #5 for no good reason
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsAI\LastConfiguration' /v 'MaxInstallAttemptsAllowed' /t REG_DWORD /d '5' /f
    #>
    if (!$revert) {
        #removing it does not get remade on restart so we will just remove it for now 
        Reg.exe delete 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsAI\LastConfiguration' /f *>$null

        Reg.exe delete 'HKCU\Software\Microsoft\Windows\Shell\Copilot' /v 'CopilotLogonTelemetryTime' /f *>$null
        Reg.exe delete 'HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData\Microsoft.Copilot_8wekyb3d8bbwe\Copilot.StartupTaskId' /f *>$null
        Reg.exe delete 'HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData\Microsoft.MicrosoftOfficeHub_8wekyb3d8bbwe\WebViewHostStartupId' /f *>$null
        Reg.exe delete 'HKCU\Software\Microsoft\Copilot' /v 'WakeApp' /f *>$null
    }
    
    #set for local machine and current user to be sure
    $hives = @('HKLM', 'HKCU')
    foreach ($hive in $hives) {
        Reg.exe add "$hive\SOFTWARE\Policies\Microsoft\Windows\WindowsCopilot" /v 'TurnOffWindowsCopilot' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add "$hive\SOFTWARE\Policies\Microsoft\Windows\WindowsAI" /v 'DisableAIDataAnalysis' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add "$hive\SOFTWARE\Policies\Microsoft\Windows\WindowsAI" /v 'AllowRecallEnablement' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add "$hive\SOFTWARE\Policies\Microsoft\Windows\WindowsAI" /v 'DisableClickToDo' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add "$hive\SOFTWARE\Policies\Microsoft\Windows\WindowsAI" /v 'TurnOffSavingSnapshots' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add "$hive\SOFTWARE\Policies\Microsoft\Windows\WindowsAI" /v 'DisableSettingsAgent' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add "$hive\SOFTWARE\Policies\Microsoft\Windows\WindowsAI" /v 'DisableAgentConnectors' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add "$hive\SOFTWARE\Policies\Microsoft\Windows\WindowsAI" /v 'DisableAgentWorkspaces' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add "$hive\SOFTWARE\Policies\Microsoft\Windows\WindowsAI" /v 'DisableRemoteAgentConnectors' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        #only for insiders using enterprise or education as of right now (12/23/25)
        #Reg.exe add "$hive\SOFTWARE\Policies\Microsoft\Windows\WindowsAI" /v 'DisableRecallDataProviders' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add "$hive\SOFTWARE\Microsoft\Windows\Shell\Copilot\BingChat" /v 'IsUserEligible' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add "$hive\SOFTWARE\Microsoft\Windows\Shell\Copilot" /v 'IsCopilotAvailable' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add "$hive\SOFTWARE\Microsoft\Windows\Shell\Copilot" /v 'CopilotDisabledReason' /t REG_SZ /d @('FeatureIsDisabled', ' ')[$revert] /f *>$null
    }
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\microphone\Microsoft.Copilot_8wekyb3d8bbwe' /v 'Value' /t REG_SZ /d @('Deny', 'Prompt')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\microphone\Microsoft.MicrosoftOfficeHub_8wekyb3d8bbwe' /v 'Value' /t REG_SZ /d @('Deny', 'Prompt')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\systemAIModels' /v 'Value' /t REG_SZ /d @('Deny', 'Prompt')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\Capabilities\systemAIModels' /v 'RecordUsageData' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Speech_OneCore\Settings\VoiceActivation\UserPreferenceForAllApps' /v 'AgentActivationEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' /v 'ShowCopilotButton' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\input\Settings' /v 'InsightsEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows\Shell\ClickToDo' /v 'DisableClickToDo' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    #remove copilot from search
    Write-Status -msg "$(@('Disabling', 'Enabling')[$revert]) Copilot In Windows Search..."
    Reg.exe add 'HKCU\SOFTWARE\Policies\Microsoft\Windows\Explorer' /v 'DisableSearchBoxSuggestions' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    #disable copilot in edge
    Write-Status -msg "$(@('Disabling', 'Enabling')[$revert]) Copilot In Edge..."
    #keeping depreciated policies incase user has older versions of edge
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Edge' /v 'CopilotCDPPageContext' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null #depreciated shows Unknown policy in edge://policy
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Edge' /v 'CopilotPageContext' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Edge' /v 'HubsSidebarEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Edge' /v 'EdgeEntraCopilotPageContext' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Edge' /v 'Microsoft365CopilotChatIconEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null #depreciated shows Unknown policy in edge://policy
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Edge' /v 'EdgeHistoryAISearchEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Edge' /v 'ComposeInlineEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Edge' /v 'GenAILocalFoundationalModelSettings' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Edge' /v 'BuiltInAIAPIsEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Edge' /v 'AIGenThemesEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Edge' /v 'DevToolsGenAiSettings' /t REG_DWORD /d @('2', '1')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Edge' /v 'ShareBrowsingHistoryWithCopilotSearchAllowed' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    #disable edge copilot mode 
    # "enabled_labs_experiments":["edge-copilot-mode@2"]
    # view flags at edge://flags
    taskkill.exe /im msedge.exe /f *>$null
    $config = "$env:LOCALAPPDATA\Microsoft\Edge\User Data\Local State"
    if (Test-Path $config) {
        #powershell core bug where json that has empty strings will error
        try {
            $jsonContent = (Get-Content $config).Replace('""', '"_empty"') | ConvertFrom-Json -ErrorAction Stop
            $fail = $false
        }
        catch {
            Write-Status -msg 'Unable to set Edge flags to disable Copilot due to a different langauge being used' -errorOutput 
            Write-Status -msg 'You can manually disable the Copilot flags at [edge://flags] in the browser' -errorOutput 
            $fail = $true
        }
        
        if (!$fail) {
            try {
                if (($jsonContent.browser | Get-Member -MemberType NoteProperty enabled_labs_experiments -ErrorAction Stop) -eq $null) {
                    $jsonContent.browser | Add-Member -MemberType NoteProperty -Name enabled_labs_experiments -Value @()
                }
                $flags = @(
                    'edge-copilot-mode@2', 
                    'edge-ntp-composer@2', #disables the copilot search in new tab page 
                    'edge-compose@2' #disables the ai writing help 
                )
                if ($revert) {
                    $jsonContent.browser.enabled_labs_experiments = $jsonContent.browser.enabled_labs_experiments | Where-Object { $_ -notin $flags }
                }
                else {
                    foreach ($flag in $flags) {
                        if ($jsonContent.browser.enabled_labs_experiments -notcontains $flag) {
                            $jsonContent.browser.enabled_labs_experiments += $flag
                        }
                    }
                }
        
                $newContent = $jsonContent | ConvertTo-Json -Compress -Depth 10 
                #add back the empty strings 
                $newContent = $newContent.replace('"_empty"', '""')
                Set-Content $config -Value $newContent -Encoding UTF8 -Force
            }
            catch {
                Write-Status -msg 'Edge Browser has never been opened on this machine unable to set flags...' -errorOutput 
                Write-Status -msg 'Open Edge once and run this tweak again' -errorOutput 
            }
        }
        
    }
   
    #disable office ai with group policy
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\ai\training\general' /v 'disabletraining' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\ai\training\specific\adaptivefloatie' /v 'disabletrainingofadaptivefloatie' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    #disable connected experiences in office should prevent copilot from working 
    Reg.exe add 'HKCU\Software\Policies\Microsoft\office\16.0\common\privacy' /v 'controllerconnectedservicesenabled' /t REG_DWORD /d @('2', '1')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Policies\Microsoft\office\16.0\common\privacy' /v 'usercontentdisabled' /t REG_DWORD /d @('2', '1')[$revert] /f *>$null
    #disable copilot buttons in word
    #Reg.exe add 'HKCU\Software\Policies\Microsoft\office\16.0\word\disabledcmdbaritemslist' /v 'TCID1' /t REG_SZ /d '47229' /f
    #Reg.exe add 'HKCU\Software\Policies\Microsoft\office\16.0\word\disabledcmdbaritemslist' /v 'TCID2' /t REG_SZ /d '43223' /f
    #Reg.exe add 'HKCU\Software\Policies\Microsoft\office\16.0\word\disabledcmdbaritemslist' /v 'TCID3' /t REG_SZ /d '34872' /f
    #Reg.exe add 'HKCU\Software\Policies\Microsoft\office\16.0\word\disabledcmdbaritemslist' /v 'TCID4' /t REG_SZ /d '42552' /f
    #disable copilot in word
    Reg.exe add 'HKCU\Software\Microsoft\Office\16.0\Word\Options' /v 'EnableCopilot' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    #disable copilot in excel
    Reg.exe add 'HKCU\Software\Microsoft\Office\16.0\Excel\Options' /v 'EnableCopilot' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    #disable copilot in onenote
    Reg.exe add 'HKCU\Software\Microsoft\Office\16.0\OneNote\Options\Copilot' /v 'CopilotEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Office\16.0\OneNote\Options\Copilot' /v 'CopilotNotebooksEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Office\16.0\OneNote\Options\Copilot' /v 'CopilotSkittleEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    #disable office ai content safety
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\ai\contentsafety\general' /v 'disablecontentsafety' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\ai\contentsafety\specific\alternativetext' /v 'disablecontentsafety' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\ai\contentsafety\specific\imagequestionandanswering' /v 'disablecontentsafety' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\ai\contentsafety\specific\promptassistance' /v 'disablecontentsafety' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\ai\contentsafety\specific\rewrite' /v 'disablecontentsafety' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\ai\contentsafety\specific\summarization' /v 'disablecontentsafety' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\ai\contentsafety\specific\summarizationwithreferences' /v 'disablecontentsafety' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\ai\contentsafety\specific\texttotable' /v 'disablecontentsafety' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    #disable additional keys
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings' /v 'AutoOpenCopilotLargeScreens' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\generativeAI' /v 'Value' /t REG_SZ /d @('Deny', 'Allow')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\systemAIModels' /v 'Value' /t REG_SZ /d @('Deny', 'Allow')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy' /v 'LetAppsAccessGenerativeAI' /t REG_DWORD /d @('2', '1')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy' /v 'LetAppsAccessSystemAIModels' /t REG_DWORD /d @('2', '1')[$revert] /f *>$null
    Reg.exe add 'HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsCopilot' /v 'AllowCopilotRuntime' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband\AuxilliaryPins' /v 'CopilotPWAPin' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband\AuxilliaryPins' /v 'RecallPin' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    #disable copilot background app access 
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications\Microsoft.Copilot_8wekyb3d8bbwe' /v 'DisabledByUser' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications\Microsoft.Copilot_8wekyb3d8bbwe' /v 'Disabled' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications\Microsoft.Copilot_8wekyb3d8bbwe' /v 'SleepDisabled' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications\Microsoft.MicrosoftOfficeHub_8wekyb3d8bbwe' /v 'DisabledByUser' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications\Microsoft.MicrosoftOfficeHub_8wekyb3d8bbwe' /v 'Disabled' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications\Microsoft.MicrosoftOfficeHub_8wekyb3d8bbwe' /v 'SleepDisabled' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    #disable for all users
    $sids = (Get-ChildItem 'registry::HKEY_USERS').Name | Where-Object { $_ -like 'HKEY_USERS\S-1-5-21*' -and $_ -notlike '*Classes*' } 
    foreach ($sid in $sids) {
        Reg.exe add "$sid\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband\AuxilliaryPins" /v 'CopilotPWAPin' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add "$sid\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband\AuxilliaryPins" /v 'RecallPin' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    }
    #disable ai actions
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\1853569164' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\4098520719' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\929719951' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    #enable new feature to hide ai actions in context menu when none are avaliable 
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\1646260367' /v 'EnabledState' /t REG_DWORD /d @('2', '0')[$revert] /f *>$null
    #disable additional ai velocity ids found from: https://github.com/phantomofearth/windows-velocity-feature-lists
    #keep in mind these may or may not do anything depending on the windows build 
    #disable copilot nudges
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\1546588812' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\203105932' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\2381287564' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\3189581453' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\3552646797' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    #disable copilot in taskbar and systray
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\3389499533' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\4027803789' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\450471565' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    #enable removing ai componets (not sure what this does yet)
    #Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\2931206798' /v 'EnabledState' /t REG_DWORD /d '2' /f
    #Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\3098978958' /v 'EnabledState' /t REG_DWORD /d '2' /f
    #Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\3233196686' /v 'EnabledState' /t REG_DWORD /d '2' /f
    #disable core ai / click to do with feature management 
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\2283032206' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\FeatureManagement\Overrides\8\502943886' /v 'EnabledState' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    #disable ask copilot (taskbar search)
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' /v 'TaskbarCompanion' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    #this branded key is blocked by the user choice driver too bad ms was very lazy and hardcoded a list of exe's not allowed to edit this key
    #workaround for any key blocked by user choice driver: rename reg.exe to something else
    Copy-Item (Get-Command reg.exe).Source .\reg1.exe -Force -ErrorAction SilentlyContinue
    & .\reg1.exe add 'HKCU\Software\Microsoft\Windows\Shell\BrandedKey' /v 'BrandedKeyChoiceType' /t REG_SZ /d @('Search', 'App')[$revert] /f *>$null
    & .\reg1.exe add 'HKCU\Software\Microsoft\Windows\Shell\BrandedKey' /v 'AppAumid' /t REG_SZ /d @(' ', 'Microsoft.Copilot_8wekyb3d8bbwe!App')[$revert] /f *>$null
    Reg.exe add 'HKCU\SOFTWARE\Policies\Microsoft\Windows\CopilotKey' /v 'SetCopilotHardwareKey' /t REG_SZ /d @(' ', 'Microsoft.Copilot_8wekyb3d8bbwe!App')[$revert] /f *>$null
    Remove-Item .\reg1.exe -Force -ErrorAction SilentlyContinue
    #disable recall customized homepage 
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\SettingSync\WindowsSettingHandlers' /v 'A9HomeContentEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    #disable typing data harvesting for ai training 
    Reg.exe add 'HKCU\Software\Microsoft\InputPersonalization' /v 'RestrictImplicitInkCollection' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\InputPersonalization' /v 'RestrictImplicitTextCollection' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\InputPersonalization\TrainedDataStore' /v 'HarvestContacts' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\CPSS\Store\InkingAndTypingPersonalization' /v 'Value' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
    #hide copilot ads in settings home page 
    Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\CloudContent' /v 'DisableConsumerAccountStateContent' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    #disable office hub startup
    Reg.exe add 'HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData\Microsoft.MicrosoftOfficeHub_8wekyb3d8bbwe\WebViewHostStartupId' /v 'State' /t REG_DWORD /d @('1', '2')[$revert] /f *>$null
    #disable ai image creator in paint
    Write-Status -msg "$(@('Disabling', 'Enabling')[$revert]) Image Creator In Paint..."
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Paint' /v 'DisableImageCreator' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Paint' /v 'DisableCocreator' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Paint' /v 'DisableGenerativeFill' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Paint' /v 'DisableGenerativeErase' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Paint' /v 'DisableRemoveBackground' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
    # disable experimental agentic features
    # Reg.exe add "HKLM\SYSTEM\CurrentControlSet\Services\IsoEnvBroker" /v "Enabled" /t REG_DWORD /d "0" /f
    # Reg.exe add "HKLM\SYSTEM\ControlSet001\Services\IsoEnvBroker" /v "Enabled" /t REG_DWORD /d "0" /f
    # leaving commented since its still only in preview builds

    #apply reg keys for default user to disable for any new users created
    #unload just incase
    [GC]::Collect()
    reg.exe unload 'HKU\DefaultUser' *>$null
    try {
        reg.exe load 'HKU\DefaultUser' "$env:SystemDrive\Users\Default\NTUSER.DAT" >$null
        $hiveloaded = $true
    }
    catch {
        Write-Status -msg 'Unable to Load Default User Hive...' -errorOutput 
        $hiveloaded = $false
    }

    if ($hiveloaded) {
        Write-Status -msg "$(@('Disabling', 'Enabling')[$revert]) AI for new users..." 
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Policies\Microsoft\Windows\WindowsCopilot' /v 'TurnOffWindowsCopilot' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Policies\Microsoft\Windows\WindowsAI' /v 'DisableAIDataAnalysis' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Policies\Microsoft\Windows\WindowsAI' /v 'AllowRecallEnablement' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Policies\Microsoft\Windows\WindowsAI' /v 'DisableClickToDo' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Policies\Microsoft\Windows\WindowsAI' /v 'TurnOffSavingSnapshots' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Policies\Microsoft\Windows\WindowsAI' /v 'DisableSettingsAgent' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Policies\Microsoft\Windows\WindowsAI' /v 'DisableAgentConnectors' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Policies\Microsoft\Windows\WindowsAI' /v 'DisableAgentWorkspaces' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Policies\Microsoft\Windows\WindowsAI' /v 'DisableRemoteAgentConnectors' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Microsoft\Windows\Shell\Copilot\BingChat' /v 'IsUserEligible' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Microsoft\Windows\Shell\Copilot' /v 'IsCopilotAvailable' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Microsoft\Windows\Shell\Copilot' /v 'CopilotDisabledReason' /t REG_SZ /d @('FeatureIsDisabled', ' ')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\microphone\Microsoft.Copilot_8wekyb3d8bbwe' /v 'Value' /t REG_SZ /d @('Deny', 'Prompt')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\Speech_OneCore\Settings\VoiceActivation\UserPreferenceForAllApps' /v 'AgentActivationEnabled' /t REG_DWORD /d @('0', '1')[$revert]  /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' /v 'ShowCopilotButton' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\input\Settings' /v 'InsightsEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\Windows\Shell\ClickToDo' /v 'DisableClickToDo' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Policies\Microsoft\Windows\Explorer' /v 'DisableSearchBoxSuggestions' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsCopilot' /v 'AllowCopilotRuntime' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband\AuxilliaryPins' /v 'CopilotPWAPin' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband\AuxilliaryPins' /v 'RecallPin' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' /v 'TaskbarCompanion' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\Windows\Shell\BrandedKey' /v 'BrandedKeyChoiceType' /t REG_SZ /d @('Search', 'App')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\Windows\Shell\BrandedKey' /v 'AppAumid' /t REG_SZ /d @(' ', 'Microsoft.Copilot_8wekyb3d8bbwe!App')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\SOFTWARE\Policies\Microsoft\Windows\CopilotKey' /v 'SetCopilotHardwareKey' /t REG_SZ /d @(' ', 'Microsoft.Copilot_8wekyb3d8bbwe!App')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\SettingSync\WindowsSettingHandlers' /v 'A9HomeContentEnabled' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\InputPersonalization' /v 'RestrictImplicitInkCollection' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\InputPersonalization' /v 'RestrictImplicitTextCollection' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\InputPersonalization\TrainedDataStore' /v 'HarvestContacts' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        Reg.exe add 'HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\CPSS\Store\InkingAndTypingPersonalization' /v 'Value' /t REG_DWORD /d @('0', '1')[$revert] /f *>$null
        if ($revert) {
            Reg.exe delete 'HKU\DefaultUser\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked' /v '{CB3B0003-8088-4EDE-8769-8B354AB2FF8C}' /f *>$null
        }
        else {
            Reg.exe add 'HKU\DefaultUser\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked' /v '{CB3B0003-8088-4EDE-8769-8B354AB2FF8C}' /t REG_SZ /d 'Ask Copilot' /f *>$null
        }

        reg.exe unload 'HKU\DefaultUser' *>$null
    }

    #disable ask copilot in context menu
    if ($revert) {
        Reg.exe delete 'HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked' /v '{CB3B0003-8088-4EDE-8769-8B354AB2FF8C}' /f *>$null
    }
    else {
        Reg.exe add 'HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked' /v '{CB3B0003-8088-4EDE-8769-8B354AB2FF8C}' /t REG_SZ /d 'Ask Copilot' /f *>$null
    }
    #Reg.exe add 'HKLM\SYSTEM\CurrentControlSet\Services\WSAIFabricSvc' /v 'Start' /t REG_DWORD /d @('4', '2')[$revert] /f *>$null
    try {
        Stop-Service -Name WSAIFabricSvc -Force -ErrorAction Stop
    }
    catch {
        #ignore error when svc is already removed
    }
    
    $backupPath = "$env:USERPROFILE\RemoveWindowsAI\Backup"
    $backupFileWSAI = 'WSAIFabricSvc.reg'
    $backupFileAAR = 'AARSVC.reg'
    if ($revert) {
        if (Test-Path "$backupPath\$backupFileWSAI") {
            Reg.exe import "$backupPath\$backupFileWSAI" *>$null
            sc.exe create WSAIFabricSvc binPath= "$env:windir\System32\svchost.exe -k WSAIFabricSvcGroup -p" *>$null
        }
        else {
            Write-Status -msg "Path Not Found: $backupPath\$backupFileWSAI" -errorOutput 
        }
        
    }
    else {
        if ($backup) {
            Write-Status -msg 'Backing up WSAIFabricSvc...'
            #export the service to a reg file before removing it 
            if (!(Test-Path $backupPath)) {
                New-Item $backupPath -Force -ItemType Directory | Out-Null
            }
            #this will hang if the service has already been exported
            # if (!(Test-Path "$backupPath\$backupFileWSAI")) {
            Reg.exe export 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WSAIFabricSvc' "$backupPath\$backupFileWSAI" /y | Out-Null #add overwrite file /y switch
            # }
        }
        Write-Status -msg 'Removing WSAIFabricSvc...'
        #delete the service
        sc.exe delete WSAIFabricSvc *>$null
    }
    if (!$revert) {
        #remove conversational agent service (used to be used for cortana, prob going to be updated for new ai agents and copilot)
        try {
            $aarSVCName = (Get-Service -ErrorAction SilentlyContinue | Where-Object { $_.name -like '*aarsvc*' }).Name
        }
        catch {
            #aarsvc already removed
        }
        

        if ($aarSVCName) {
            if ($backup) {
                Write-Status -msg 'Backing up Agent Activation Runtime Service...'
                #export the service to a reg file before removing it 
                if (!(Test-Path $backupPath)) {
                    New-Item $backupPath -Force -ItemType Directory | Out-Null
                }
                #this will hang if the service has already been exported
                # if (!(Test-Path "$backupPath\$backupFileAAR")) {
                Reg.exe export 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\AarSvc' "$backupPath\$backupFileAAR" /y | Out-Null
                # }
            }
            Write-Status -msg 'Removing Agent Activation Runtime Service...'
            #delete the service
            try {
                Stop-Service -Name $aarSVCName -Force -ErrorAction Stop
            }
            catch {
                try {
                    Stop-Service -Name AarSvc -Force -ErrorAction Stop
                }
                catch {
                    #neither are running
                }
                
            }
            
            sc.exe delete AarSvc *>$null
        }
    }
    else {
        Write-Status 'Restoring Agent Activation Runtime Service...'

        if (Test-Path "$backupPath\$backupFileAAR") {
            Reg.exe import "$backupPath\$backupFileAAR" *>$null
            sc.exe create AarSvc binPath= "$env:windir\system32\svchost.exe -k AarSvcGroup -p" *>$null
        }
        else {
            Write-Status -msg "Path Not Found: $backupPath\$backupFileAAR" -errorOutput 
        }
    }
  


    #block copilot from communicating with server
    if ($revert) {
        if ((Test-Path "$backupPath\HKCR_Copilot.reg") -or (Test-Path "$backupPath\HKCU_Copilot.reg")) {
            Reg.exe import "$backupPath\HKCR_Copilot.reg" *>$null
            Reg.exe import "$backupPath\HKCU_Copilot.reg" *>$null
        }
        else {
            Write-Status -msg "Unable to Find HKCR_Copilot.reg or HKCU_Copilot.reg in [$backupPath]" -errorOutput 
        }
    }
    else {
        if ($backup) {
            #backup .copilot file extension
            Reg.exe export 'HKEY_CLASSES_ROOT\.copilot' "$backupPath\HKCR_Copilot.reg" /y *>$null
            Reg.exe export 'HKEY_CURRENT_USER\Software\Classes\.copilot' "$backupPath\HKCU_Copilot.reg" /y *>$null
        }
        Write-Status -msg 'Removing .copilot File Extension...' 
        Reg.exe delete 'HKCU\Software\Classes\.copilot' /f *>$null
        Reg.exe delete 'HKCR\.copilot' /f *>$null
    }

    #disabling and removing voice access, recently added ai powered
    Reg.exe add 'HKCU\Software\Microsoft\VoiceAccess' /v 'RunningState' /t REG_DWORD /d @('0', '1')[$revert] /f >$null
    Reg.exe add 'HKCU\Software\Microsoft\VoiceAccess' /v 'TextCorrection' /t REG_DWORD /d @('1', '2')[$revert] /f >$null
    Reg.exe add 'HKCU\Software\Microsoft\Windows NT\CurrentVersion\AccessibilityTemp' /v @('0', '1')[$revert] /t REG_DWORD /d '0' /f >$null
    $startMenu = "$env:appdata\Microsoft\Windows\Start Menu\Programs\Accessibility"
    $voiceExe = "$env:windir\System32\voiceaccess.exe"
    if ($backup) {
        Write-Status -msg 'Backing up Voice Access...'
        if (!(Test-Path $backupPath)) {
            New-Item $backupPath -Force -ItemType Directory | Out-Null
        }
        Copy-Item $voiceExe -Destination $backupPath -Force -ErrorAction SilentlyContinue | Out-Null
        Copy-Item "$startMenu\VoiceAccess.lnk" -Destination $backupPath -Force -ErrorAction SilentlyContinue | Out-Null
    }
    
    if ($revert) {
        if ((Test-Path "$backupPath\VoiceAccess.exe") -and (Test-Path "$backupPath\VoiceAccess.lnk")) {
            Write-Status -msg 'Restoring Voice Access...'
            Move-Item "$backupPath\VoiceAccess.exe" -Destination "$env:windir\System32" -Force | Out-Null
            Move-Item "$backupPath\VoiceAccess.lnk" -Destination $startMenu -Force | Out-Null
        }
        else {
            Write-Status -msg 'Voice Access Backup NOT Found!' -errorOutput 
        }
    }
    else {
        Write-Status -msg 'Removing Voice Access...'
        $command = "Remove-item -path $env:windir\System32\voiceaccess.exe -force"
        Run-Trusted -command $command -psversion $psversion
        Start-Sleep 1
        Remove-Item "$startMenu\VoiceAccess.lnk" -Force -ErrorAction SilentlyContinue
    }

    
    $root = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture'
    $allFX = (Get-ChildItem $root -Recurse).Name | Where-Object { $_ -like '*FxProperties' }
    #search the fx props for VocalEffectPack and add {1da5d803-d492-4edd-8c23-e0c0ffee7f0e},5 = 1
    foreach ($fxPath in $allFX) {
        $keys = Get-ItemProperty "registry::$fxPath"
        foreach ($key in $keys) {
            if ($key | Get-Member -MemberType NoteProperty | Where-Object { $_.Name -like '{*},*' } | Where-Object { $_.Definition -like '*#VocaEffectPack*' }) {
                Write-Status -msg "$(@('Disabling','Enabling')[$revert]) AI Voice Effects..."
                $regPath = Convert-Path $key.PSPath
                if ($revert) {
                    #enable
                    $command = "Reg.exe delete '$regPath' /v '{1da5d803-d492-4edd-8c23-e0c0ffee7f0e},5' /f"
                    Run-Trusted -command $command -psversion $psversion
                }
                else {
                    #disable
                    $command = "Reg.exe add '$regPath' /v '{1da5d803-d492-4edd-8c23-e0c0ffee7f0e},5' /t REG_DWORD /d '1' /f"
                    Run-Trusted -command $command -psversion $psversion
                }
                
            }
        }
    }

    #disable gaming copilot 
    #found from: https://github.com/meetrevision/playbook/issues/197
    #not sure this really does anything in my testing gaming copilot still appears 
    <#
    if ($revert) {
        $command = "reg delete 'HKLM\SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId\Microsoft.Xbox.GamingAI.Companion.Host.GamingCompanionHostOptions' /f"
        Run-Trusted -command $command -psversion $psversion
    }
    else {
        $command = "reg add 'HKLM\SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId\Microsoft.Xbox.GamingAI.Companion.Host.GamingCompanionHostOptions' /v 'ActivationType' /t REG_DWORD /d 0 /f;
    reg add 'HKLM\SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId\Microsoft.Xbox.GamingAI.Companion.Host.GamingCompanionHostOptions' /v 'Server' /t REG_SZ /d `" `" /f
    "
        Run-Trusted -command $command -psversion $psversion
    }
    #>
    
    if (!$revert) {
        #better method by setting the gaming copilot widget to false in the xbox overlay settings json file
        #to make this actually work gamebar service needs to be restarted 
        $overlaySettingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.XboxGamingOverlay_8wekyb3d8bbwe\LocalState\profileDataSettings.txt"
        if (Test-Path $overlaySettingsPath) {
            Write-Status -msg 'Disabling Gaming Copilot...'
            Get-Process '*gamebar*' -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue 
            try {
                $content = Get-Content $overlaySettingsPath -Raw -ErrorAction Stop
                $jsonObj = ConvertFrom-Json $content -ErrorAction Stop

                $hasGamingCopilot = $jsonObj.profile.settingsStorage | Get-Member -MemberType NoteProperty | Where-Object { $_.Name -like '*GamingCompanionWidget*' }
                if ($hasGamingCopilot) {
                    #get all the properties for gaming copilot (there can be different ones for some users so we cant just hardcode this)
                    #set all found properties to false besides suppressFirstFavorite
                    $props = $jsonObj.profile.settingsStorage.$($hasGamingCopilot.Name) | Get-Member -MemberType NoteProperty
                    foreach ($prop in $props) {
                        if ($prop.Name -eq 'suppressFirstFavorite') {
                            #this prop needs to be true to hide from favorites
                            $jsonObj.profile.settingsStorage.$($hasGamingCopilot.Name).$($prop.Name) = $true
                        }
                        elseif ($prop.Name -eq 'suppressFirstLaunch') {
                            $jsonObj.profile.settingsStorage.$($hasGamingCopilot.Name).$($prop.Name) = $true
                        }
                        else {
                            $jsonObj.profile.settingsStorage.$($hasGamingCopilot.Name).$($prop.Name) = $false
                        }
                    }
                    #this prop isnt added to the json till the user views settings in gamebar so add the prop and set to false
                    #hide gaming copilot from widgets menu
                    $jsonObj.profile.settingsStorage.$($hasGamingCopilot.Name) | Add-Member -NotePropertyName 'homeMenuVisibleUser' -NotePropertyValue $false -Force
                    
                    $newContent = ConvertTo-Json $jsonObj -Depth 10 -Compress #compress here to match og formatting for this file
                    Set-Content $overlaySettingsPath -Value $newContent -Force
                }
                else {
                    Write-Status -msg 'GamingCompanionWidget NOT Found in profileDataSettings.txt! Skipping...' -errorOutput
                }
            }
            catch {
                Write-Error $_
                Write-Status -msg 'Unable to Disable Gaming Copilot!' -errorOutput
            }
        }
    }
    

    #remove windows ai dll contracts 
    $command = "
    Reg delete 'HKLM\SOFTWARE\Microsoft\WindowsRuntime\WellKnownContracts' /v 'Windows.AI.Actions.ActionsContract' /f
    Reg delete 'HKLM\SOFTWARE\Microsoft\WindowsRuntime\WellKnownContracts' /v 'Windows.AI.Agents.AgentsContract' /f
    Reg delete 'HKLM\SOFTWARE\Microsoft\WindowsRuntime\WellKnownContracts' /v 'Windows.AI.MachineLearning.MachineLearningContract' /f 
    Reg delete 'HKLM\SOFTWARE\Microsoft\WindowsRuntime\WellKnownContracts' /v 'Windows.AI.MachineLearning.Preview.MachineLearningPreviewContract' /f
    "
    Run-Trusted -command $command -psversion $psversion

    #disable ai setting in uwp photos app
    $uwpPhotosSettings = "$env:LOCALAPPDATA\Packages\Microsoft.Windows.Photos_8wekyb3d8bbwe\Settings\settings.dat"
    if (Test-Path $uwpPhotosSettings) {
        [GC]::Collect()
        reg.exe unload 'HKU\TEMP' *>$null
        taskkill /im photos.exe /f *>$null
        reg.exe load HKU\TEMP $uwpPhotosSettings >$null
        if (!$revert) {
            $regContent = @'
Windows Registry Editor Version 5.00

[HKEY_USERS\TEMP\LocalState] 
"ImageCategorizationConsentDismissed"=hex(5f5e10c):74,00,72,00,75,00,65,00,00,\
  00,4c,a0,89,0c,f7,2e,dc,01
"ImageCategorizationConsent"=hex(5f5e10c):66,00,61,00,6c,00,73,00,65,00,00,00,\
  6c,c4,53,ae,c5,51,dc,01
'@
        }
        else {
            $regContent = @'
Windows Registry Editor Version 5.00

[HKEY_USERS\TEMP\LocalState]
"ImageCategorizationConsentDismissed"=hex(5f5e10c):74,00,72,00,75,00,65,00,00,\
  00,4c,a0,89,0c,f7,2e,dc,01
"ImageCategorizationConsent"=hex(5f5e10c):74,00,72,00,75,00,65,00,00,00,79,e7,\
  fe,c5,c4,51,dc,01
'@
        }
       
        
        New-Item "$($tempDir)DisableAIPhotos.reg" -Value $regContent -Force | Out-Null
        regedit.exe /s "$($tempDir)DisableAIPhotos.reg"
        Start-Sleep 1
        reg unload HKU\TEMP >$null
        Remove-Item "$($tempDir)DisableAIPhotos.reg" -Force -ErrorAction SilentlyContinue
    }

    #disable app actions
    #method credit : https://github.com/agadiffe/WindowsMize
    $settingsDat = "$env:LOCALAPPDATA\Packages\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\Settings\settings.dat"

    if (Test-Path $settingsDat) {
        Write-Status -msg "$(@('Disabling','Enabling')[$revert]) App Actions..."

        $apps = @(
            'Microsoft.MicrosoftOfficeHub_8wekyb3d8bbwe' 
            'Microsoft.Office.ActionsServer_8wekyb3d8bbwe' 
            'MSTeams_8wekyb3d8bbwe' 
            'Microsoft.Paint_8wekyb3d8bbwe' 
            'Microsoft.Windows.Photos_8wekyb3d8bbwe'
            'MicrosoftWindows.Client.CBS_cw5n1h2txyewy' #describe image (system)
        )
     
        foreach ($app in $apps) {
            $setting = [PSCustomObject]@{
                Name  = $app
                Path  = 'LocalState\DisabledApps'
                Value = @('1', '0')[$revert] # 1 = disable    0 = enable
                Type  = '5f5e10b'
            }
            
            $setting | Set-UwpAppRegistryEntry -FilePath $settingsDat
        }
     
    }
    

    #force policy changes
    Write-Status -msg 'Applying Registry Changes...'
    gpupdate /force /wait:0 >$null

}



function Install-NOAIPackage {
    
    if (!$revert) {
        $package = Get-WindowsPackage -Online | Where-Object { $_.PackageName -like '*zoicware*' }
        if (!$package) {
            #check cpu arch
            $arm = ((Get-CimInstance -Class Win32_ComputerSystem).SystemType -match 'ARM64') -or ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64')
            $arch = if ($arm) { 'arm64' } else { 'amd64' }
            #add cert to registry
            $certRegPath = 'HKLM:\Software\Microsoft\SystemCertificates\ROOT\Certificates\8A334AA8052DD244A647306A76B8178FA215F344'
            if (!(Test-Path "$certRegPath")) {
                New-Item -Path $certRegPath -Force | Out-Null
            }

            #check if script is being ran locally 
            if ((Test-Path "$PSScriptRoot\RemoveWindowsAIPackage\amd64") -and (Test-Path "$PSScriptRoot\RemoveWindowsAIPackage\arm64")) {
                Write-Status -msg 'RemoveWindowsAI Packages Found Locally...'

                Write-Status -msg 'Installing RemoveWindowsAI Package...'
                try {
                    Add-WindowsPackage -Online -PackagePath "$PSScriptRoot\RemoveWindowsAIPackage\$arch\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -NoRestart -IgnoreCheck -ErrorAction Stop >$null
                }
                catch {
                    #user is using powershell 7 use dism command as fallback
                    dism.exe /Online /Add-Package /PackagePath:"$PSScriptRoot\RemoveWindowsAIPackage\$arch\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" /NoRestart /IgnoreCheck >$null
                }
           
            }
            else {
                Write-Status -msg 'Downloading RemoveWindowsAI Package From Github...'
                $ProgressPreference = 'SilentlyContinue'
                try {
                    Invoke-WebRequest -Uri "https://github.com/zoicware/RemoveWindowsAI/raw/refs/heads/main/RemoveWindowsAIPackage/$arch/ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -OutFile "$($tempDir)ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -UseBasicParsing -ErrorAction Stop
                }
                catch {
                    Write-Status -msg "Unable to Download Package at: https://github.com/zoicware/RemoveWindowsAI/raw/refs/heads/main/RemoveWindowsAIPackage/$arch/ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -errorOutput
                    return
                }

                Write-Status -msg 'Installing RemoveWindowsAI Package...'
                try {
                    Add-WindowsPackage -Online -PackagePath "$($tempDir)ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -NoRestart -IgnoreCheck -ErrorAction Stop >$null
                }
                catch {
                    dism.exe /Online /Add-Package /PackagePath:"$($tempDir)ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" /NoRestart /IgnoreCheck >$null
                }
            }
        }
        else {
            Write-Status -msg 'Update package already installed...'
        }
        
        Write-Status -msg 'Checking update package install status...'
        $package = Get-WindowsPackage -Online | Where-Object { $_.PackageName -like '*zoicware*' }
        if ($package.PackageState -eq 'InstallPending') {
            Write-Status -msg 'Package installed incorrectly... Uninstalling!' -errorOutput
            try {
                Remove-WindowsPackage -Online -PackageName $package.PackageName -NoRestart -ErrorAction Stop
            }
            catch {
                dism.exe /Online /remove-package /PackageName:$($package.PackageName) /NoRestart
            }
            #remove reg install location 
            $regPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages'
            Get-ChildItem $regPath | ForEach-Object {
                $value = try { Get-ItemProperty "registry::$($_.Name)" -ErrorAction Stop } catch { $null }
                if ($value -and $value.PSPath -like '*zoicware*') {
                    Remove-Item -Path $value.PSPath -Recurse -Force
                }
            }
        }
    }
    else {
        
        $package = Get-WindowsPackage -Online | Where-Object { $_.PackageName -like '*zoicware*' }
        if ($package) {
            Write-Status 'Removing Custom Windows Update Package...' 
            try {
                Remove-WindowsPackage -Online -PackageName $package.PackageName -NoRestart -ErrorAction Stop
            }
            catch {
                dism.exe /Online /remove-package /PackageName:$($package.PackageName) /NoRestart
            }
            #remove reg install location 
            $regPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages'
            Get-ChildItem $regPath | ForEach-Object {
                $value = try { Get-ItemProperty "registry::$($_.Name)" -ErrorAction Stop } catch { $null }
                if ($value -and $value.PSPath -like '*zoicware*') {
                    Remove-Item -Path $value.PSPath -Recurse -Force
                }
            }
            
        }
        else {
            Write-Status 'Unable to Find Update Package...' -errorOutput 
        }
        
    }

}

    
    
function Disable-Copilot-Policies {
    #disable copilot policies in region policy json
    $JSONPath = "$env:windir\System32\IntegratedServicesRegionPolicySet.json"
    if (Test-Path $JSONPath) {
        Write-Host "$(@('Disabling','Enabling')[$revert]) CoPilot Policies in " -NoNewline -ForegroundColor Cyan
        Write-Host "[$JSONPath]" -ForegroundColor Yellow

        #takeownership
        takeown /f $JSONPath *>$null
        icacls $JSONPath /grant *S-1-5-32-544:F /t *>$null

        #edit the content
        $jsonContent = Get-Content $JSONPath | ConvertFrom-Json
        try {
            $copilotPolicies = $jsonContent.policies | Where-Object { $_.'$comment' -like '*CoPilot*' }
            foreach ($policies in $copilotPolicies) {
                $policies.defaultState = @('disabled', 'enabled')[$revert]
            }
            $recallPolicies = $jsonContent.policies | Where-Object { $_.'$comment' -like '*A9*' -or $_.'$comment' -like '*Manage Recall*' -or $_.'$comment' -like '*Settings Agent*' }
            foreach ($recallPolicy in $recallPolicies) {
                if ($recallPolicy.'$comment' -like '*A9*') {
                    $recallPolicy.defaultState = @('enabled', 'disabled')[$revert]
                }
                elseif ($recallPolicy.'$comment' -like '*Manage Recall*') {
                    $recallPolicy.defaultState = @('disabled', 'enabled')[$revert]
                }
                elseif ($recallPolicy.'$comment' -like '*Settings Agent*') {
                    $recallPolicy.defaultState = @('enabled', 'disabled')[$revert]
                }
            }
            $newJSONContent = $jsonContent | ConvertTo-Json -Depth 100
            Set-Content $JSONPath -Value $newJSONContent -Force
            $total = ($copilotPolicies.count) + ($recallPolicies.count)
            Write-Status -msg "$total CoPilot Policies $(@('Disabled','Enabled')[$revert])"
        }
        catch {
            Write-Status -msg 'CoPilot Not Found in IntegratedServicesRegionPolicySet' -errorOutput 
        }

    
    }

    #additional json path for visual assist 
    $visualAssistPath = "$env:windir\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\VisualAssist\VisualAssistActions.json"
    if (Test-Path $visualAssistPath) {
        Write-Status -msg "$(@('Disabling','Enabling')[$revert]) Generative AI in Visual Assist..."

        takeown /f $visualAssistPath *>$null
        icacls $visualAssistPath /grant *S-1-5-32-544:F /t *>$null

        $jsoncontent = Get-Content $visualAssistPath | ConvertFrom-Json
        $jsonContent.actions | Add-Member -MemberType NoteProperty -Name usesGenerativeAI -Value @($false, $true)[$revert] -force
        $newJSONContent = $jsonContent | ConvertTo-Json -Depth 100
        Set-Content $visualAssistPath -Value $newJSONContent -Force
    }
    
}

#function from: https://github.com/Andrew-J-Larson/OS-Scripts/blob/main/Windows/Wrapper-Functions/Download-AppxPackage-Function.ps1
function Download-AppxPackage {
    param(
        # there has to be an alternative, as sometimes the API fails on PackageFamilyName
        [string]$PackageFamilyName,
        [string]$ProductId,
        [string]$outputDir
    )
    if (-Not ($PackageFamilyName -Or $ProductId)) {
        # can't do anything without at least one
        Write-Error 'Missing either PackageFamilyName or ProductId.'
        return $null
    }
      
    try {
        $UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome # needed as sometimes the API will block things when it knows requests are coming from PowerShell
    }
    catch {
        $UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'
    }
      
    $DownloadedFiles = @()
    $errored = $false
    $allFilesDownloaded = $true
      
    $apiUrl = 'https://store.rg-adguard.net/api/GetFiles'
    $versionRing = 'Retail'
      
    $architecture = switch ($env:PROCESSOR_ARCHITECTURE) {
        'x86' { 'x86' }
        { @('x64', 'amd64') -contains $_ } { 'x64' }
        'arm' { 'arm' }
        'arm64' { 'arm64' }
        default { 'neutral' } # should never get here
    }
      
    if (Test-Path $outputDir -PathType Container) {
        New-Item -Path "$outputDir\$PackageFamilyName" -ItemType Directory -Force | Out-Null
        $downloadFolder = "$outputDir\$PackageFamilyName"
    }
    else {
        
        $downloadFolder = Join-Path $tempDir $PackageFamilyName
        if (!(Test-Path $downloadFolder -PathType Container)) {
            New-Item $downloadFolder -ItemType Directory -Force | Out-Null
        }
    }
        
    $body = @{
        type = if ($ProductId) { 'ProductId' } else { 'PackageFamilyName' }
        url  = if ($ProductId) { $ProductId } else { $PackageFamilyName }
        ring = $versionRing
        lang = 'en-US'
    }

    $headers = @{
        'User-Agent'       = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'
        'Accept'           = 'application/json, text/javascript, */*; q=0.01'
        'Content-Type'     = 'application/x-www-form-urlencoded; charset=UTF-8'
        'X-Requested-With' = 'XMLHttpRequest'
        'Origin'           = 'https://store.rg-adguard.net'
        'Referer'          = 'https://store.rg-adguard.net/'
    }
      
    # required due to the api being protected behind Cloudflare now
    if (-Not $apiWebSession) {
        $global:apiWebSession = $null
        $apiHostname = (($apiUrl.split('/'))[0..2]) -Join '/'
        Invoke-WebRequest -Uri $apiHostname -UserAgent $UserAgent -SessionVariable $apiWebSession -UseBasicParsing 
    }
      
    $raw = $null
    try {
        $raw = Invoke-RestMethod -Method Post -Uri $apiUrl -Headers $headers -Body $body -WebSession $apiWebSession
    }
    catch {
        $errorMsg = 'An error occurred: ' + $_
        Write-Host $errorMsg
        $errored = $true
        return $false
    }
      
    # hashtable of packages by $name
    #  > values = hashtables of packages by $version
    #    > values = arrays of packages as objects (containing: url, filename, name, version, arch, publisherId, type)
    [Collections.Generic.Dictionary[string, Collections.Generic.Dictionary[string, array]]] $packageList = @{}
    # populate $packageList
    $patternUrlAndText = '<tr style.*<a href=\"(?<url>.*)"\s.*>(?<text>.*\.(app|msi)x.*)<\/a>'
    $raw | Select-String $patternUrlAndText -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object {
        $url = ($_.Groups['url']).Value
        $text = ($_.Groups['text']).Value
        $textSplitUnderscore = $text.split('_')
        $name = $textSplitUnderscore.split('_')[0]
        $version = $textSplitUnderscore.split('_')[1]
        $arch = ($textSplitUnderscore.split('_')[2]).ToLower()
        $publisherId = ($textSplitUnderscore.split('_')[4]).split('.')[0]
        $textSplitPeriod = $text.split('.')
        $type = ($textSplitPeriod[$textSplitPeriod.length - 1]).ToLower()
      
        # create $name hash key hashtable, if it doesn't already exist
        if (!($packageList.keys -match ('^' + [Regex]::escape($name) + '$'))) {
            $packageList["$name"] = @{}
        }
        # create $version hash key array, if it doesn't already exist
        if (!(($packageList["$name"]).keys -match ('^' + [Regex]::escape($version) + '$'))) {
            ($packageList["$name"])["$version"] = @()
        }
       
        # add package to the array in the hashtable
        ($packageList["$name"])["$version"] += @{
            url         = $url
            filename    = $text
            name        = $name
            version     = $version
            arch        = $arch
            publisherId = $publisherId
            type        = $type
        }
    }
      
    # an array of packages as objects, meant to only contain one of each $name
    $latestPackages = @()
    # grabs the most updated package for $name and puts it into $latestPackages
    $packageList.GetEnumerator() | ForEach-Object { ($_.value).GetEnumerator() | Select-Object -Last 1 } | ForEach-Object {
        $packagesByType = $_.value
        $msixbundle = ($packagesByType | Where-Object { $_.type -match '^msixbundle$' })
        $appxbundle = ($packagesByType | Where-Object { $_.type -match '^appxbundle$' })
        $msix = ($packagesByType | Where-Object { ($_.type -match '^msix$') -And ($_.arch -match ('^' + [Regex]::Escape($architecture) + '$')) })
        $appx = ($packagesByType | Where-Object { ($_.type -match '^appx$') -And ($_.arch -match ('^' + [Regex]::Escape($architecture) + '$')) })
        if ($msixbundle) { $latestPackages += $msixbundle }
        elseif ($appxbundle) { $latestPackages += $appxbundle }
        elseif ($msix) { $latestPackages += $msix }
        elseif ($appx) { $latestPackages += $appx }
    }
      
    # download packages
    $latestPackages | ForEach-Object {
        $url = $_.url
        $filename = $_.filename
        # TODO: may need to include detection in the future of expired package download URLs..... in the case that downloads take over 10 minutes to complete
      
        $downloadFile = Join-Path $downloadFolder $filename
      
        # If file already exists, ask to replace it
        if (Test-Path $downloadFile) {
            Write-Host "`"${filename}`" already exists at `"${downloadFile}`"."
            $confirmation = ''
            while (!(($confirmation -eq 'Y') -Or ($confirmation -eq 'N'))) {
                $confirmation = Read-Host "`nWould you like to re-download and overwrite the file at `"${downloadFile}`" (Y/N)?"
                $confirmation = $confirmation.ToUpper()
            }
            if ($confirmation -eq 'Y') {
                Remove-Item -Path $downloadFile -Force
            }
            else {
                $DownloadedFiles += $downloadFile
            }
        }
      
        if (!(Test-Path $downloadFile)) {
            # Write-Host "Attempting download of `"${filename}`" to `"${downloadFile}`" . . ."
            $fileDownloaded = $null
            $PreviousProgressPreference = $ProgressPreference
            $ProgressPreference = 'SilentlyContinue' # avoids slow download when using Invoke-WebRequest
            try {
                Invoke-WebRequest -Uri $url -OutFile $downloadFile
                $fileDownloaded = $?
            }
            catch {
                $ProgressPreference = $PreviousProgressPreference # return ProgressPreference back to normal
                $errorMsg = 'An error occurred: ' + $_
                Write-Host $errorMsg
                $errored = $true
                break $false
            }
            $ProgressPreference = $PreviousProgressPreference # return ProgressPreference back to normal
            if ($fileDownloaded) { $DownloadedFiles += $downloadFile }
            else { $allFilesDownloaded = $false }
        }
    }
      
    if ($errored) { Write-Host 'Completed with some errors.' }
    if (-Not $allFilesDownloaded) { Write-Host 'Warning: Not all packages could be downloaded.' }
    return $DownloadedFiles
}


function Remove-AI-Appx-Packages {

    if ($revert) {

        #download appx packages from store
        $appxBackup = "$env:USERPROFILE\RemoveWindowsAI\Backup\AppxBackup"
        if (Test-Path $appxBackup) {
            $familyNames = Get-Content "$appxBackup\PackageFamilyNames.txt"
            foreach ($package in $familyNames) {
                Write-Status -msg "Attempting to Download $package..."
                $downloadedFiles = Download-AppxPackage -PackageFamilyName $package -outputDir $appxBackup
                $bundle = $downloadedFiles | Where-Object { $_ -match '\.appxbundle$' -or $_ -match '\.msixbundle$' } | Select-Object -First 1
                if ($bundle) {
                    Write-Status -msg "Installing $package..."
                    Add-AppPackage $bundle
                }
            }

            #cleanup
            Remove-Item "$appxBackup\*" -Recurse -Force -ErrorAction SilentlyContinue
        }
        else {
            Write-Status -msg 'Unable to Find AppxBackup in User Directory!' -errorOutput 
        }

    }
    else {

        #to make this part faster make a txt file in temp with chunck of removal 
        #code and then just run that from run 
        #trusted function due to the design of having it hidden from the user
        
        $packageRemovalPath = "$($tempDir)aiPackageRemoval.ps1"
        if (!(test-path $packageRemovalPath)) {
            New-Item $packageRemovalPath -Force | Out-Null
        }

        #needed for separate powershell sessions
        $aipackages = @(
            # 'MicrosoftWindows.Client.Photon'
            'MicrosoftWindows.Client.AIX'
            'MicrosoftWindows.Client.CoPilot'
            'Microsoft.Windows.Ai.Copilot.Provider'
            'Microsoft.Copilot'
            'Microsoft.MicrosoftOfficeHub'
            'MicrosoftWindows.Client.CoreAI'
            'Microsoft.Edge.GameAssist'
            'Microsoft.Office.ActionsServer'
            'aimgr'
            'Microsoft.WritingAssistant'
            #ai component packages installed on copilot+ pcs
            'MicrosoftWindows.*.Voiess'
            'MicrosoftWindows.*.Speion'
            'MicrosoftWindows.*.Livtop'
            'MicrosoftWindows.*.InpApp'
            'MicrosoftWindows.*.Filons'
            'WindowsWorkload.Data.Analysis.Stx.*'
            'WindowsWorkload.Manager.*'
            'WindowsWorkload.PSOnnxRuntime.Stx.*'
            'WindowsWorkload.PSTokenizer.Stx.*'
            'WindowsWorkload.QueryBlockList.*'
            'WindowsWorkload.QueryProcessor.Data.*'
            'WindowsWorkload.QueryProcessor.Stx.*'
            'WindowsWorkload.SemanticText.Data.*'
            'WindowsWorkload.SemanticText.Stx.*'
            'WindowsWorkload.Data.ContentExtraction.Stx.*'
            'WindowsWorkload.ScrRegDetection.Data.*'
            'WindowsWorkload.ScrRegDetection.Stx.*'
            'WindowsWorkload.TextRecognition.Stx.*'
            'WindowsWorkload.Data.ImageSearch.Stx.*'
            'WindowsWorkload.ImageContentModeration.*'
            'WindowsWorkload.ImageContentModeration.Data.*'
            'WindowsWorkload.ImageSearch.Data.*'
            'WindowsWorkload.ImageSearch.Stx.*'
            'WindowsWorkload.ImageTextSearch.Data.*'
            'WindowsWorkload.PSOnnxRuntime.Stx.*'
            'WindowsWorkload.PSTokenizerShared.Data.*'
            'WindowsWorkload.PSTokenizerShared.Stx.*'
            'WindowsWorkload.ImageTextSearch.Stx.*'
        )

        if ($backup) {

            #create file with package family names for reverting
            $appxBackup = "$env:USERPROFILE\RemoveWindowsAI\Backup\AppxBackup"
            if (!(Test-Path $appxBackup)) {
                New-Item $appxBackup -ItemType Directory -Force | Out-Null
            }

            $backuppath = New-Item $appxBackup -Name 'PackageFamilyNames.txt' -ItemType File -Force

            $familyNames = get-appxpackage -allusers | Where-Object { $aipackages -contains $_.Name } 
            foreach ($familyName in $familyNames) {
                Add-Content -Path $backuppath.FullName -Value $familyName.PackageFamilyName 
            }

        }

        $code = @'
$aipackages = @(
    'MicrosoftWindows.Client.AIX'
    'MicrosoftWindows.Client.CoPilot'
    'Microsoft.Windows.Ai.Copilot.Provider'
    'Microsoft.Copilot'
    'Microsoft.MicrosoftOfficeHub'
    'MicrosoftWindows.Client.CoreAI'
    'Microsoft.Edge.GameAssist'
    'Microsoft.Office.ActionsServer'
    'aimgr'
    'Microsoft.WritingAssistant'
    'MicrosoftWindows.*.Voiess'
    'MicrosoftWindows.*.Speion'
    'MicrosoftWindows.*.Livtop'
    'MicrosoftWindows.*.InpApp'
    'MicrosoftWindows.*.Filons'
    'WindowsWorkload.Data.Analysis.Stx.*'
    'WindowsWorkload.Manager.*'
    'WindowsWorkload.PSOnnxRuntime.Stx.*'
    'WindowsWorkload.PSTokenizer.Stx.*'
    'WindowsWorkload.QueryBlockList.*'
    'WindowsWorkload.QueryProcessor.Data.*'
    'WindowsWorkload.QueryProcessor.Stx.*'
    'WindowsWorkload.SemanticText.Data.*'
    'WindowsWorkload.SemanticText.Stx.*'
    'WindowsWorkload.Data.ContentExtraction.Stx.*'
    'WindowsWorkload.ScrRegDetection.Data.*'
    'WindowsWorkload.ScrRegDetection.Stx.*'
    'WindowsWorkload.TextRecognition.Stx.*'
    'WindowsWorkload.Data.ImageSearch.Stx.*'
    'WindowsWorkload.ImageContentModeration.*'
    'WindowsWorkload.ImageContentModeration.Data.*'
    'WindowsWorkload.ImageSearch.Data.*'
    'WindowsWorkload.ImageSearch.Stx.*'
    'WindowsWorkload.ImageSearch.Stx.*'
    'WindowsWorkload.ImageTextSearch.Data.*'
    'WindowsWorkload.PSOnnxRuntime.Stx.*'
    'WindowsWorkload.PSTokenizerShared.Data.*'
    'WindowsWorkload.PSTokenizerShared.Stx.*'
    'WindowsWorkload.ImageTextSearch.Stx.*'
    'WindowsWorkload.ImageTextSearch.Stx.*'
)

$provisioned = get-appxprovisionedpackage -online 
$appxpackage = get-appxpackage -allusers
$store = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore'
$users = @('S-1-5-18'); if (test-path $store) { $users += $((Get-ChildItem $store -ea 0 | Where-Object { $_ -like '*S-1-5-21*' }).PSChildName) }

#use eol trick to uninstall some locked packages
foreach ($choice in $aipackages) {
    foreach ($appx in $($provisioned | Where-Object { $_.PackageName -like "*$choice*" })) {

        $PackageName = $appx.PackageName 
        $PackageFamilyName = ($appxpackage | Where-Object { $_.Name -eq $appx.DisplayName }).PackageFamilyName
        New-Item "$store\Deprovisioned\$PackageFamilyName" -force
     
        Set-NonRemovableAppsPolicy -Online -PackageFamilyName $PackageFamilyName -NonRemovable 0
        remove-appxprovisionedpackage -packagename $PackageName -online -allusers
    }
    foreach ($appx in $($appxpackage | Where-Object { $_.PackageFullName -like "*$choice*" })) {

        $PackageFullName = $appx.PackageFullName
        $PackageFamilyName = $appx.PackageFamilyName
        New-Item "$store\Deprovisioned\$PackageFamilyName" -force
        Set-NonRemovableAppsPolicy -Online -PackageFamilyName $PackageFamilyName -NonRemovable 0
       
        #remove inbox apps
        $inboxApp = "$store\InboxApplications\$PackageFullName"
        Remove-Item -Path $inboxApp -Force

        #get all installed user sids for package due to not all showing up in reg
        foreach ($user in $appx.PackageUserInformation) { 
            $sid = $user.UserSecurityID.SID
            New-Item "$store\EndOfLife\$sid\$PackageFullName" -force -verbose
            remove-appxpackage -package $PackageFullName -User $sid 
        } 
        remove-appxpackage -package $PackageFullName -allusers

        foreach ($sid in $users) { 
            New-Item "$store\EndOfLife\$sid\$PackageFullName" -force
        }  
    }
}
'@
        Set-Content -Path $packageRemovalPath -Value $code -Force 
        #allow removal script to run
        try {
            Set-ExecutionPolicy Unrestricted -Force -ErrorAction Stop
        }
        catch {
            #user has set powershell execution policy via group policy or via settings, to change it we need to update the registry 
            try {
                $Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell' -Name 'ExecutionPolicy' -ErrorAction Stop
                Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'EnableScripts' /t REG_DWORD /d '1' /f >$null
                Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
                $Global:executionPolicyUser = $false
                $Global:executionPolicyMachine = $false
                $Global:executionPolicyWow64 = $false
                $Global:executionPolicyUserPol = $false
            }
            catch {
                try {
                    $Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKCU:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' -Name 'ExecutionPolicy' -ErrorAction Stop
                    Reg.exe add 'HKCU\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
                    $Global:executionPolicyUser = $true
                    $Global:executionPolicyMachine = $false
                    $Global:executionPolicyWow64 = $false
                    $Global:executionPolicyUserPol = $false
                }
                catch {
                    try {
                        $Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKLM:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' -Name 'ExecutionPolicy' -ErrorAction Stop
                        Reg.exe add 'HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
                        $Global:executionPolicyUser = $false
                        $Global:executionPolicyMachine = $true
                        $Global:executionPolicyWow64 = $false
                        $Global:executionPolicyUserPol = $false
                    }
                    catch {
                        try {
                            $Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' -Name 'ExecutionPolicy' -ErrorAction Stop
                            Reg.exe add 'HKLM\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
                            $Global:executionPolicyUser = $false
                            $Global:executionPolicyMachine = $false
                            $Global:executionPolicyWow64 = $true
                            $Global:executionPolicyUserPol = $false

                        }
                        catch {
                            $Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKCU:\SOFTWARE\Policies\Microsoft\Windows\PowerShell' -Name 'ExecutionPolicy' 
                            Reg.exe add 'HKCU\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'EnableScripts' /t REG_DWORD /d '1' /f >$null
                            Reg.exe add 'HKCU\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
                            $Global:executionPolicyUser = $false
                            $Global:executionPolicyMachine = $false
                            $Global:executionPolicyWow64 = $false
                            $Global:executionPolicyUserPol = $true
                        }
                        

                    }
                    
                }
               
            }
            
           
        }


        Write-Status -msg 'Removing AI Appx Packages...'
        $command = "&`"$($tempDir)aiPackageRemoval.ps1`""
        Run-Trusted -command $command -psversion $psversion

        #check packages removal
        #exit loop after 10 tries
        $attempts = 0
        do {
            Start-Sleep 1
            $packages = get-appxpackage -AllUsers | Where-Object { $aipackages -contains $_.Name }
            if ($packages) {
                $attempts++
                if ($EnableLogging) {
                    $Global:logInfo.Line = "Attempting to Remove Appx Packages, Attempt: $attempts"
                    $Global:logInfo.Result = "Found Packages: $packages"
                    Add-LogInfo -logPath $logPath -info $Global:logInfo
                }
                $command = "&`"$($tempDir)aiPackageRemoval.ps1`""
                Run-Trusted -command $command -psversion $psversion
            }
    
        }while ($packages -and $attempts -lt 10)

        if ($EnableLogging) {
            if ($attempts -ge 10) {
                Write-Status -msg 'Packages Removal Failed...' -errorOutput 
                $Global:logInfo.Line = 'Removing Appx Packages'
                $Global:logInfo.Result = "Removal Failed, Reached Max Attempts (10)... Leftover Packages: $packages"
                Add-LogInfo -logPath $logPath -info $Global:logInfo
            }
            else {
                Write-Status -msg 'Packages Removed Sucessfully...'
                $Global:logInfo.Line = 'Removing Appx Packages'
                $Global:logInfo.Result = 'Removal Success'
                Add-LogInfo -logPath $logPath -info $Global:logInfo
            }
        }
        else {
            if ($attempts -ge 10) {
                Write-Status -msg 'Packages Removal Failed...' -errorOutput 
                Write-Status -msg 'Use the Enable Logging Switch to Get More Info...'
            }
            else {
                Write-Status -msg 'Packages Removed Sucessfully...'
            }
        
        }

        #tell windows copilot pwa is already installed
        Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoInstalledPWAs' /v 'CopilotPWAPreinstallCompleted' /t REG_DWORD /d '1' /f *>$null
        Reg.exe add 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoInstalledPWAs' /v 'Microsoft.Copilot_8wekyb3d8bbwe' /t REG_DWORD /d '1' /f *>$null
        #incase the user is on 25h2 and is using education or enterprise (required for this policy to work)
        #uninstalls copilot with group policy (will ensure it doesnt get reinstalled)
        Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\Appx\RemoveDefaultMicrosoftStorePackages' /v 'Enabled' /t REG_DWORD /d '1' /f *>$null
        Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\Appx\RemoveDefaultMicrosoftStorePackages\Microsoft.Copilot_8wekyb3d8bbwe' /v 'RemovePackage' /t REG_DWORD /d '1' /f *>$null
        Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\Appx\RemoveDefaultMicrosoftStorePackages\Microsoft.MicrosoftOfficeHub_8wekyb3d8bbwe' /v 'RemovePackage' /t REG_DWORD /d '1' /f *>$null

        ## undo eol unblock trick to prevent latest cumulative update (LCU) failing 
        #  $eolPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\EndOfLife'
        #  $eolKeys = (Get-ChildItem $eolPath).Name
        #  foreach ($path in $eolKeys) {
        #      Remove-Item "registry::$path" -Recurse -Force -ErrorAction SilentlyContinue
        #  }
    }

}

function Remove-Recall-Optional-Feature {
    if (!$revert) {
        #doesnt seem to work just gets stuck (does anyone really want this shit lol)
        #Enable-WindowsOptionalFeature -Online -FeatureName 'Recall' -All -NoRestart
        #remove recall optional feature 
        Write-Status -msg 'Removing Recall Optional Feature...'
        try {
            $state = (Get-WindowsOptionalFeature -Online -FeatureName 'Recall' -ErrorAction Stop).State
            if ($state -and $state -ne 'DisabledWithPayloadRemoved') {
                $ProgressPreference = 'SilentlyContinue'
                try {
                    Disable-WindowsOptionalFeature -Online -FeatureName 'Recall' -Remove -NoRestart -ErrorAction Stop *>$null
                }
                catch {
                    #incase get-windowsoptionalfeature works but disable doesnt 
                    dism.exe /Online /Disable-Feature /FeatureName:Recall /Remove /NoRestart /Quiet
                }
            }
        }
        catch {
            #if get-windowsoptionalfeature errors fallback to dism
            $dismOutput = dism.exe /Online /Get-FeatureInfo /FeatureName:Recall
    
            if ($LASTEXITCODE -eq 0) {
                $isDisabledWithPayloadRemoved = $dismOutput | Select-String -Pattern 'State\s*:\s*Disabled with Payload Removed'
        
                if (!$isDisabledWithPayloadRemoved) {
                    dism.exe /Online /Disable-Feature /FeatureName:Recall /Remove /NoRestart /Quiet
                }
            }
        }
    }
}

# not restoring for now shouldnt cause any issues (also may not even be possible to restore)
function Remove-AI-CBS-Packages {
    if (!$revert) {
        #additional hidden packages
        Write-Status -msg 'Removing Additional Hidden AI Packages...'
        #unhide the packages from dism, remove owners subkey for removal 
        $regPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages'
        $ProgressPreference = 'SilentlyContinue'
        Get-ChildItem $regPath | ForEach-Object {
            $value = try { Get-ItemPropertyValue "registry::$($_.Name)" -Name Visibility -ErrorAction Stop } catch { $null }
    
            if ($value -ne $null) {
                if ($value -eq 2 -and $_.PSChildName -like '*AIX*' -or $_.PSChildName -like '*Recall*' -or $_.PSChildName -like '*Copilot*' -or $_.PSChildName -like '*CoreAI*') {
                    Set-ItemProperty "registry::$($_.Name)" -Name Visibility -Value 1 -Force
                    New-ItemProperty "registry::$($_.Name)" -Name DefVis -PropertyType DWord -Value 2 -Force | Out-Null
                    Remove-Item "registry::$($_.Name)\Owners" -Force -ErrorAction SilentlyContinue
                    Remove-Item "registry::$($_.Name)\Updates" -Force -ErrorAction SilentlyContinue
                    try {
                        Remove-WindowsPackage -Online -PackageName $_.PSChildName -NoRestart -ErrorAction Stop *>$null
                        $paths = Get-ChildItem "$env:windir\servicing\Packages" -Filter "*$($_.PSChildName)*" -ErrorAction SilentlyContinue 
                        foreach ($path in $paths) {
                            if ($path) {
                                Remove-Item $path.FullName -Force -ErrorAction SilentlyContinue
                            }
                        }
                        
                    }
                    catch {
                        #fallback to dism when user is using powershell 7
                        dism.exe /Online /Remove-Package /PackageName:$($_.PSChildName) /NoRestart /Quiet
                        $paths = Get-ChildItem "$env:windir\servicing\Packages" -Filter "*$($_.PSChildName)*" -ErrorAction SilentlyContinue 
                        foreach ($path in $paths) {
                            if ($path) {
                                Remove-Item $path.FullName -Force -ErrorAction SilentlyContinue
                            }
                        }                    
                    }
        
                }
            }
            
        }
    }
}


function Remove-AI-Files {
    #prob add params here for each file removal 


    if ($revert) {
        if (Test-Path "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles") {
            Write-Status -msg 'Restoring Appx Package Files...'
            $paths = Get-Content "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\backupPaths.txt"
            foreach ($path in $paths) {
                $fileName = Split-Path $path -Leaf
                $dest = Split-Path $path -Parent
                try {
                    Move-Item -Path "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\$fileName" -Destination $dest -Force -ErrorAction Stop
                }
                catch {
                    $command = "Move-Item -Path `"$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\$fileName`" -Destination `"$dest`" -Force"
                    Run-Trusted -command $command -psversion $psversion
                    Start-Sleep 1
                }
            }

            if (Test-Path "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\OfficeAI") {
                Write-Status -msg 'Restoring Office AI Files...'
                Move-Item "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\OfficeAI\x64\AI" -Destination "$env:ProgramFiles\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\Office16" -Force 
                Move-Item "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\OfficeAI\x86\AI" -Destination "$env:ProgramFiles\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\Office16" -Force 
                Move-Item "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\OfficeAI\RootAI\AI" -Destination "$env:ProgramFiles\Microsoft Office\root\Office16" -Force 
                Move-Item "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\OfficeAI\ActionsServer\ActionsServer" -Destination "$env:ProgramFiles\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\Office16" -Force 
                Get-ChildItem "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\OfficeAI" -Filter '*.msix' | ForEach-Object {
                    Move-Item $_.FullName -Destination "$env:ProgramFiles\Microsoft Office\root\Integration\Addons" -Force
                }
            }

            Write-Status -msg 'Restoring AI URIs...'
            $regs = Get-ChildItem "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\URIHandlers"
            foreach ($reg in $regs) {
                Reg.exe import $reg.FullName *>$null
            }
           
            Write-Status -msg 'Files Restored... You May Need to Repair the Apps Using the Microsoft Store'
        }
        else {
            Write-Status -msg 'Unable to Find Backup Files!' -errorOutput 
        }
       
        <#
        if (Test-Path "$env:USERPROFILE\RemoveWindowsAI\Backup\CompStorage"){
            Get-ChildItem "$env:USERPROFILE\RemoveWindowsAI\Backup\CompStorage" -Filter "*.reg"
        }else{
            Write-Status -msg 'Unable to Find Component Storage Backup!' -errorOutput 
        }
        #>
    }
    else {

        $aipackages = @(
            # 'MicrosoftWindows.Client.Photon'
            'MicrosoftWindows.Client.AIX'
            'MicrosoftWindows.Client.CoPilot'
            'Microsoft.Windows.Ai.Copilot.Provider'
            'Microsoft.Copilot'
            'Microsoft.MicrosoftOfficeHub'
            'MicrosoftWindows.Client.CoreAI'
            'Microsoft.Edge.GameAssist'
            'Microsoft.Office.ActionsServer'
            'aimgr'
            'Microsoft.WritingAssistant'
            #ai component packages installed on copilot+ pcs
            'WindowsWorkload'
            'Voiess'
            'Speion'
            'Livtop'
            'InpApp'
            'Filons'
        )

        Write-Status -msg 'Removing Appx Package Files...'
        Write-Status -msg 'This could take a while on some systems, please be patient!' -warningOutput
        #-----------------------------------------------------------------------remove files
        $appsPath = "$env:SystemRoot\SystemApps"
        if (!(Test-Path $appsPath)) {
            $appsPath = "$env:windir\SystemApps"
        }
        $appsPath2 = "$env:ProgramFiles\WindowsApps"
    
        $appsPath3 = "$env:ProgramData\Microsoft\Windows\AppRepository"
    
        $appsPath4 = "$env:SystemRoot\servicing\Packages"
        if (!(Test-Path $appsPath4)) {
            $appsPath4 = "$env:windir\servicing\Packages"
        }
    
        $appsPath5 = "$env:SystemRoot\System32\CatRoot"
        if (!(Test-Path $appsPath5)) {
            $appsPath5 = "$env:windir\System32\CatRoot"
        }

        $appsPath6 = "$env:SystemRoot\SystemApps\SxS"
        if (!(Test-Path $appsPath6)) {
            $appsPath6 = "$env:windir\SystemApps\SxS"
        }

        $paths = @(
            $appsPath,
            $appsPath2,
            $appsPath3,
            $appsPath6
        )

        $jobs = foreach ($path in $paths) {
            $rs = [powershell]::Create().AddScript({
                    param($path)
                    (Get-ChildItem -Path $path -Directory -Force -ErrorAction SilentlyContinue).FullName  
                }).AddParameter('path', $path)
    
            [pscustomobject]@{
                Runspace = $rs
                Handle   = $rs.BeginInvoke()
            }
        }

        $fullPaths = foreach ($job in $jobs) {
            $job.Runspace.EndInvoke($job.Handle)
            $job.Runspace.Dispose()
        }


        $packagesPath = @()
        foreach ($package in $aipackages) {
            foreach ($path in $fullPaths) {
                if ($path -like "*$package*") {
                    $packagesPath += $path
                }
            }
        }

        $paths = @($appsPath4, $appsPath5)
        $jobs = foreach ($path in $paths) {
            $rs = [powershell]::Create().AddScript({
                    param($path)
                    (Get-ChildItem -Path $path -Directory -Force -ErrorAction SilentlyContinue | 
                    Where-Object { $_.FullName -like '*UserExperience-AIX*' -or 
                        $_.FullName -like '*Copilot*' -or 
                        $_.FullName -like '*UserExperience-Recall*' -or 
                        $_.FullName -like '*CoreAI*' 
                    }).FullName
                }).AddParameter('path', $path)
    
            [pscustomobject]@{
                Runspace = $rs
                Handle   = $rs.BeginInvoke()
            }
        }

        $packagesPath += foreach ($job in $jobs) {
            $job.Runspace.EndInvoke($job.Handle)
            $job.Runspace.Dispose()
        }


        #add app actions mcp host
        $paths = @(
            "$env:LOCALAPPDATA\Microsoft\WindowsApps\ActionsMcpHost.exe"
            "$env:SystemRoot\System32\config\systemprofile\AppData\Local\Microsoft\WindowsApps\ActionsMcpHost.exe"
            "$env:SystemRoot\System32\config\systemprofile\AppData\Local\Microsoft\WindowsApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\ActionsMcpHost.exe"
            "$env:LOCALAPPDATA\Microsoft\WindowsApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\ActionsMcpHost.exe"
        )

        foreach ($path in $paths) {
            if (Test-Path $path) {
                $packagesPath += $path
            }
        }

        foreach ($packageName in $aipackages) {
            $path = Get-ChildItem "$env:LOCALAPPDATA\Packages" -Filter "*$packageName*" 
            if ($path) {
                $packagesPath += $path.FullName
            }
            
        }

    
        if ($backup) {
            Write-Status -msg 'Backing Up AI Files...'
            $backupDir = "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles"
            if (!(Test-Path $backupDir)) {
                New-Item $backupDir -Force -ItemType Directory | Out-Null
            }
        }

        foreach ($Path in $packagesPath) {
            #only remove dlls from photon to prevent startmenu from breaking
            # if ($path -like '*Photon*') {
            #     $command = "`$dlls = (Get-ChildItem -Path $Path -Filter *.dll).FullName; foreach(`$dll in `$dlls){Remove-item ""`$dll"" -force}"
            #     Run-Trusted -command $command -psversion $psversion
            #     Start-Sleep 1
            # }
            # else {

            if ($backup) {
                $backupFiles = "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\backupPaths.txt"
                if (!(Test-Path $backupFiles -PathType Leaf)) {
                    New-Item $backupFiles -Force -ItemType File | Out-Null
                }
                try {
                    Copy-Item -Path $Path -Destination $backupDir -Force -Recurse -ErrorAction Stop
                    Add-Content -Path $backupFiles -Value $Path
                }
                catch {
                    #ignore any errors
                }
            }
            $command = "Remove-item ""$Path"" -force -recurse"
            Run-Trusted -command $command -psversion $psversion
           
        }

        #remove machine learning dlls
        $paths = @(
            "$env:SystemRoot\System32\Windows.AI.MachineLearning.dll"
            "$env:SystemRoot\SysWOW64\Windows.AI.MachineLearning.dll"
            "$env:SystemRoot\System32\Windows.AI.MachineLearning.Preview.dll"
            "$env:SystemRoot\SysWOW64\Windows.AI.MachineLearning.Preview.dll"
            "$env:SystemRoot\System32\SettingsHandlers_Copilot.dll"
            "$env:SystemRoot\System32\SettingsHandlers_A9.dll"
        )
        foreach ($path in $paths) {
            if (Test-Path $path) {
                takeown /f $path *>$null
                icacls $path /grant *S-1-5-32-544:F /t *>$null
                try {
                    Remove-Item -Path $path -Force -ErrorAction Stop
                }
                catch {
                    #takeown didnt work remove file with system priv
                    $command = "Remove-Item -Path $path -Force"
                    Run-Trusted -command $command -psversion $psversion
                }
            }
        }
    
        Write-Status -msg 'Removing Hidden Copilot Installers...'
        #remove package installers in edge dir
        #installs Microsoft.Windows.Ai.Copilot.Provider
        $dir = "${env:ProgramFiles(x86)}\Microsoft"
        $folders = @(
            'Edge',
            'EdgeCore',
            'EdgeWebView'
        )
        foreach ($folder in $folders) {
            if ($folder -eq 'EdgeCore') {
                #edge core doesnt have application folder
                $fullPath = (Get-ChildItem -Path "$dir\$folder\*.*.*.*\copilot_provider_msix" -ErrorAction SilentlyContinue).FullName
            
            }
            else {
                $fullPath = (Get-ChildItem -Path "$dir\$folder\Application\*.*.*.*\copilot_provider_msix" -ErrorAction SilentlyContinue).FullName
            }
            if ($fullPath -ne $null) { Remove-Item -Path $fullPath -Recurse -Force -ErrorAction SilentlyContinue }
        }
    

        #remove copilot update in edge update dir
        $dir = "${env:ProgramFiles(x86)}\Microsoft\EdgeUpdate"
        if (Test-Path $dir) {
            $paths = Get-ChildItem $dir -Recurse -Filter '*CopilotUpdate.exe*' 
            foreach ($path in $paths) {
                if (Test-Path $path.FullName) {
                    Remove-Item $path.FullName -Force
                }
            }
        }

        $dir = "${env:ProgramFiles(x86)}\Microsoft"
        if (Test-Path $dir) {
            $paths = Get-ChildItem $dir -Recurse -Filter '*Copilot_setup*' 
            foreach ($path in $paths) {
                if (Test-Path $path.FullName) {
                    Remove-Item $path.FullName -Force
                }
            }
        }

        Reg.exe delete 'HKLM\SOFTWARE\Microsoft\EdgeUpdate' /v 'CopilotUpdatePath' /f *>$null
        Reg.exe delete 'HKLM\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate' /v 'CopilotUpdatePath' /f *>$null
    
        #remove additional installers
        $inboxapps = 'C:\Windows\InboxApps'
        $installers = Get-ChildItem -Path $inboxapps -Filter '*Copilot*'
        foreach ($installer in $installers) {
            takeown /f $installer.FullName *>$null
            icacls $installer.FullName /grant *S-1-5-32-544:F /t *>$null
            try {
                Remove-Item -Path $installer.FullName -Force -ErrorAction Stop
            }
            catch {
                #takeown didnt work remove file with system priv
                $command = "Remove-Item -Path $($installer.FullName) -Force"
                Run-Trusted -command $command -psversion $psversion
            }
        
        }
    
    
        #remove ai from outlook/office
        $aiPaths = @(
            "$env:ProgramFiles\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\Office16\AI",
            "$env:ProgramFiles\Microsoft Office\root\vfs\ProgramFilesCommonX86\Microsoft Shared\Office16\AI",
            "$env:ProgramFiles\Microsoft Office\root\Office16\AI",
            "$env:ProgramFiles\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\Office16\ActionsServer",
            "$env:ProgramFiles\Microsoft Office\root\Integration\Addons\aimgr.msix",
            "$env:ProgramFiles\Microsoft Office\root\Integration\Addons\WritingAssistant.msix",
            "$env:ProgramFiles\Microsoft Office\root\Integration\Addons\ActionsServer.msix"
        )
    
        foreach ($path in $aiPaths) {
            if (Test-Path $path -ErrorAction SilentlyContinue) {
                if ($backup) {
                    Write-Status -msg 'Backing Up Office AI Files...'
                    $backupDir = "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\OfficeAI"
                    if (!(Test-Path $backupDir)) {
                        New-Item $backupDir -Force -ItemType Directory | Out-Null
                    }

                    if ($path -eq "$env:ProgramFiles\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\Office16\AI") {
                        $backupDir = "$backupDir\x64"
                        New-Item $backupDir -Force -ItemType Directory | Out-Null
                    }
                    elseif ($path -eq "$env:ProgramFiles\Microsoft Office\root\vfs\ProgramFilesCommonX86\Microsoft Shared\Office16\AI") {
                        $backupDir = "$backupDir\x86"
                        New-Item $backupDir -Force -ItemType Directory | Out-Null
                    }
                    elseif ($path -eq "$env:ProgramFiles\Microsoft Office\root\Office16\AI") {
                        $backupDir = "$backupDir\RootAI"
                        New-Item $backupDir -Force -ItemType Directory | Out-Null
                    }
                    elseif ($path -eq "$env:ProgramFiles\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\Office16\ActionsServer") {
                        $backupDir = "$backupDir\ActionsServer"
                        New-Item $backupDir -Force -ItemType Directory | Out-Null
                    }
                    else {
                        $backupDir = "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\OfficeAI"
                    }
                    Copy-Item -Path $path -Destination $backupDir -Force -Recurse -ErrorAction SilentlyContinue
                }
                try {
                    Remove-Item $path -Recurse -Force -ErrorAction Stop
                }
                catch {
                    $command = "Remove-Item $path -Recurse -Force"
                    Run-Trusted -command $command -psversion $psversion
                    Start-Sleep 1
                }
                
            }
        }

        #remove any screenshots from recall
        Write-Status -msg 'Removing Any Screenshots By Recall...'
        Remove-Item -Path "$env:LOCALAPPDATA\CoreAIPlatform*" -Force -Recurse -ErrorAction SilentlyContinue
        if ($env:OneDrive) {
            Remove-Item -Path "$env:OneDrive\Microsoft Copilot Chat Files" -Force -Recurse -ErrorAction SilentlyContinue
        }
       
        #remove ai uri handlers
        Write-Status -msg 'Removing AI URI Handlers...'
        $uris = @(
            'registry::HKEY_CLASSES_ROOT\ms-office-ai'
            'registry::HKEY_CLASSES_ROOT\ms-copilot'
            'registry::HKEY_CLASSES_ROOT\ms-clicktodo'
        )

        foreach ($uri in $uris) {
            if ($backup) {
                if (Test-Path $uri) {
                    $backupDir = "$env:USERPROFILE\RemoveWindowsAI\Backup\AIFiles\URIHandlers"
                    if (!(Test-Path $backupDir)) {
                        New-Item $backupDir -Force -ItemType Directory | Out-Null
                    }
                    $regExportPath = "$backupDir\$($uri -replace 'registry::HKEY_CLASSES_ROOT\\', '').reg"
                    Reg.exe export ($uri -replace 'registry::', '') $regExportPath /y *>$null
                }
            }
            Remove-Item $uri -Recurse -Force -ErrorAction SilentlyContinue
        }

        #prefire copilot nudges package by deleting the registry keys 
        Write-Status -msg 'Removing Copilot Nudges Registry Keys...'
        $keys = @(
            'registry::HKCR\Extensions\ContractId\Windows.BackgroundTasks\PackageId\MicrosoftWindows.Client.Core_*.*.*.*_x64__cw5n1h2txyewy\ActivatableClassId\Global.CopilotNudges.AppX*.wwa',
            'registry::HKCR\Extensions\ContractId\Windows.Launch\PackageId\MicrosoftWindows.Client.Core_*.*.*.*_x64__cw5n1h2txyewy\ActivatableClassId\Global.CopilotNudges.wwa',
            'registry::HKCR\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\MicrosoftWindows.Client.Core_*.*.*.*_x64__cw5n1h2txyewy\Applications\MicrosoftWindows.Client.Core_cw5n1h2txyewy!Global.CopilotNudges',
            'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\MicrosoftWindows.Client.Core_*.*.*.*_x64__cw5n1h2txyewy\Applications\MicrosoftWindows.Client.Core_cw5n1h2txyewy!Global.CopilotNudges',
            'HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications\Backup\MicrosoftWindows.Client.Core_cw5n1h2txyewy!Global.CopilotNudges',
            'HKLM:\SOFTWARE\Classes\Extensions\ContractId\Windows.BackgroundTasks\PackageId\MicrosoftWindows.Client.Core_*.*.*.*_x64__cw5n1h2txyewy\ActivatableClassId\Global.CopilotNudges.AppX*.wwa',
            'HKLM:\SOFTWARE\Classes\Extensions\ContractId\Windows.BackgroundTasks\PackageId\MicrosoftWindows.Client.Core_*.*.*.*_x64__cw5n1h2txyewy\ActivatableClassId\Global.CopilotNudges.AppX*.mca',
            'HKLM:\SOFTWARE\Classes\Extensions\ContractId\Windows.Launch\PackageId\MicrosoftWindows.Client.Core_*.*.*.*_x64__cw5n1h2txyewy\ActivatableClassId\Global.CopilotNudges.wwa'
        )
        #get full paths and remove
        $fullkey = @()
        foreach ($key in $keys) {
            try {
                $fullKey = Get-Item -Path $key -ErrorAction Stop
                if ($null -eq $fullkey) { continue }
                if ($fullkey.Length -gt 1) {
                    foreach ($multikey in $fullkey) {
                        $command = "Remove-Item -Path `"registry::$multikey`" -Force -Recurse"
                        Run-Trusted -command $command -psversion $psversion
                        Start-Sleep 1
                        #remove any regular admin that have trusted installer bug
                        Remove-Item -Path "registry::$multikey" -Force -Recurse -ErrorAction SilentlyContinue
                    }
                }
                else {
                    $command = "Remove-Item -Path `"registry::$fullKey`" -Force -Recurse"
                    Run-Trusted -command $command -psversion $psversion
                    Start-Sleep 1
                    #remove any regular admin that have trusted installer bug
                    Remove-Item -Path "registry::$fullKey" -Force -Recurse -ErrorAction SilentlyContinue
                }
         
            }
            catch {
                continue
            }
        }

        #remove ai app checks in updates (not sure if this does anything)
        $command = "Reg.exe delete 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell\Update\Packages\MicrosoftWindows.Client.CoreAI_cw5n1h2txyewy' /f"
        Run-Trusted -command $command -psversion $psversion
        Reg.exe delete 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell\Update\Packages\Components' /v 'AIX' /f *>$null
        Reg.exe delete 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell\Update\Packages\Components' /v 'CopilotNudges' /f *>$null
        Reg.exe delete 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell\Update\Packages\Components' /v 'AIContext' /f *>$null

        reg.exe delete 'HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\ActionsMcpHost.exe' /f *>$null
        reg.exe delete 'HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\ActionsMcpHost.exe' /f *>$null

        #remove app actions files 
        #these will get remade when updating
        taskkill.exe /im AppActions.exe /f *>$null
        taskkill.exe /im VisualAssist.exe /f *>$null
        $paths = @(
            "$env:windir\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\ActionUI"
            "$env:windir\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\VisualAssist"
            "$env:windir\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\AppActions.exe"
            "$env:windir\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\AppActions.dll"
            "$env:windir\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\VisualAssistExe.exe"
            "$env:windir\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\VisualAssistExe.dll"
        )

        Write-Status -msg 'Removing App Actions Files...'
        foreach ($path in $paths) {
            if (Test-Path $path) {
                if ((Get-Item $path).PSIsContainer) {
                    takeown /f "$path" /r /d Y *>$null
                    icacls "$path" /grant *S-1-5-32-544:F /t *>$null
                    Remove-Item "$path" -Force -Recurse -ErrorAction SilentlyContinue
                }
                else {
                    takeown /f "$path" *>$null
                    icacls "$path" /grant *S-1-5-32-544:F /t *>$null
                    Remove-Item "$path" -Force -ErrorAction SilentlyContinue
                }
            }
        }
        

        Write-Status -msg 'Removing AI From Component Store (WinSxS)...'
        Write-Status -msg 'This could take a while on some systems, please be patient!' -warningOutput
        #additional dirs and reg keys
        $aiKeyWords = @(
            'AIX',
            'Copilot',
            'Recall',
            'CoreAI',
            'aimgr'
        )
        $regLocations = @(
            'registry::HKCR\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Storage',
            'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Storage',
            'registry::HKCR\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages',
            'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages',
            'registry::HKCR\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData',
            'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData',
            'registry::HKCR\PackagedCom\Package',
            'HKCU:\Software\Classes\PackagedCom\Package',
            'HKCU:\Software\RegisteredApplications',
            'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide\Winners'
        )
        $dirs = @(
            'C:\Windows\WinSxS',
            'C:\Windows\System32\CatRoot'
        )
        
        New-Item "$($tempDir)PathsToDelete.txt" -ItemType File -Force | Out-Null
        foreach ($keyword in $aiKeyWords) {
            foreach ($location in $regLocations) {
                Get-ChildItem $location -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -like "*$keyword*" } | ForEach-Object {
                    try {
                        Remove-Item $_.PSPath -Recurse -Force -ErrorAction Stop
                    }
                    catch {
                        #ignore when path is null
                    }
                    
                }
            }

        }

        $jobs = foreach ($dir in $dirs) {
            $rs = [powershell]::Create().AddScript({
                    param($dir, $aiKeyWords)
                    (Get-ChildItem $dir -Recurse -Directory -ErrorAction SilentlyContinue | Where-Object { 
                        $_.FullName -like "*$($aiKeyWords[0])*" -or 
                        $_.FullName -like "*$($aiKeyWords[1])*" -or 
                        $_.FullName -like "*$($aiKeyWords[2])*" -or
                        $_.FullName -like "*$($aiKeyWords[3])*" -or
                        $_.FullName -like "*$($aiKeyWords[4])*"
                    }).FullName
                }).AddParameter('dir', $dir).AddParameter('aiKeyWords', $aiKeyWords)
    
            [pscustomobject]@{
                Runspace = $rs
                Handle   = $rs.BeginInvoke()
            }
        }

        $pathsToDelete = foreach ($job in $jobs) {
            $job.Runspace.EndInvoke($job.Handle)
            $job.Runspace.Dispose()
        }

        Set-Content "$($tempDir)PathsToDelete.txt" -Value $pathsToDelete -Force | Out-Null

        $command = "Get-Content `"$($tempDir)PathsToDelete.txt`"  | ForEach-Object { Remove-Item `$_ -Force -Recurse -EA 0 }"
        Run-Trusted -command $command -psversion $psversion
        Start-Sleep 1
    }

    #TEST:
    # remove ai components from component storage
    # this will prevent sfc from trying to repair files removed 
    # but seems to prevent windows update from working
    <#
    $compPath = "$env:systemroot\System32\config\COMPONENTS"

    reg.exe query 'HKLM\COMPONENTS' /ve *>$null
    if ($LASTEXITCODE -ne 0) {
        reg.exe load 'HKLM\COMPONENTS' $compPath >$null
    }

    if ($LASTEXITCODE -ne 0) {
        Write-Status -msg "Unable to Load $compPath" -errorOutput
    }
    else {
        $paths = Get-ChildItem 'registry::HKLM\COMPONENTS\DerivedData\Components' | Where-Object { $_.PSChildName -like '*copilot*' -or
            $_.PSChildName -like '*userexperience-aix*' -or
            $_.PSChildName -like '*userexperience-recall*' -or
            $_.PSChildName -like '*userexperience-coreai*' } 

        if ($paths) {
            Write-Status -msg 'Removing AI Components Found in Component Storage...'
            #backup by default for now
            $backupPath = "$env:USERPROFILE\RemoveWindowsAI\Backup\CompStorage"
            if (!(Test-Path $backupPath)) {
                New-Item $backupPath -ItemType Directory | Out-Null
            }

            foreach ($path in $paths) {
                reg.exe export $path.Name "$backupPath\$($path.PSChildName).reg" /y >$null
                reg.exe delete $path.Name /f
            }
            
        }
        else {
            Write-Status -msg 'No Ai Components Found in Component Storage'
        }

    }
    #>
}


function Hide-AI-Components {
    #hide ai components in immersive settings
    Write-Status -msg "$(@('Hiding','Unhiding')[$revert]) Ai Components in Settings..."

    $existingSettings = try { Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer' -Name 'SettingsPageVisibility' -ErrorAction SilentlyContinue }catch {}
    #early return if the user has already customized this with showonly rather than hide, in this event ill assume the user has knowledge of this key and aicomponents is likely not shown anyway
    if ($existingSettings -like '*showonly*') {
        Write-Status 'SettingsPageVisibility contains "showonly"...Skipping!' -errorOutput
        return 
    }
    
    if ($revert) {
        #if the key is not just hide ai components then just remove it and retain the rest
        if ($existingSettings -ne 'hide:aicomponents;appactions;') {
            #in the event that this is just aicomponents but multiple times newkey will just be hide: which is valid
            $newKey = $existingSettings -replace 'aicomponents;appactions;', ''
            Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer' /v 'SettingsPageVisibility' /t REG_SZ /d $newKey /f >$null
        }
        else {
            Reg.exe delete 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer' /v 'SettingsPageVisibility' /f >$null
        }
    }
    else {
        if ($existingSettings -and $existingSettings -notlike '*aicomponents;*') {
           
            if (!($existingSettings.endswith(';'))) {
                #doesnt have trailing ; so need to add it 
                $newval = $existingSettings + ';aicomponents;appactions;'
            }
            else {
                $newval = $existingSettings + 'aicomponents;appactions;
Download .txt
gitextract_6n8exeya/

├── .github/
│   ├── FUNDING.yml
│   └── ISSUE_TEMPLATE/
│       ├── bug_report.md
│       └── feature_request.md
├── ClassicApps/
│   ├── paint/
│   │   ├── Paint.reg
│   │   ├── mspaint.exe.mui
│   │   ├── mspaint.exe.mun
│   │   └── paint_lang_files/
│   │       ├── ar-SA/
│   │       │   └── mspaint.exe.mui
│   │       ├── bg-BG/
│   │       │   └── mspaint.exe.mui
│   │       ├── cs-CZ/
│   │       │   └── mspaint.exe.mui
│   │       ├── da-DK/
│   │       │   └── mspaint.exe.mui
│   │       ├── de-DE/
│   │       │   └── mspaint.exe.mui
│   │       ├── el-GR/
│   │       │   └── mspaint.exe.mui
│   │       ├── en-GB/
│   │       │   └── mspaint.exe.mui
│   │       ├── es-ES/
│   │       │   └── mspaint.exe.mui
│   │       ├── es-MX/
│   │       │   └── mspaint.exe.mui
│   │       ├── et-EE/
│   │       │   └── mspaint.exe.mui
│   │       ├── fi-FI/
│   │       │   └── mspaint.exe.mui
│   │       ├── fr-CA/
│   │       │   └── mspaint.exe.mui
│   │       ├── fr-FR/
│   │       │   └── mspaint.exe.mui
│   │       ├── he-IL/
│   │       │   └── mspaint.exe.mui
│   │       ├── hr-HR/
│   │       │   └── mspaint.exe.mui
│   │       ├── hu-HU/
│   │       │   └── mspaint.exe.mui
│   │       ├── it-IT/
│   │       │   └── mspaint.exe.mui
│   │       ├── ja-JP/
│   │       │   └── mspaint.exe.mui
│   │       ├── ko-KR/
│   │       │   └── mspaint.exe.mui
│   │       ├── lt-LT/
│   │       │   └── mspaint.exe.mui
│   │       ├── lv-LV/
│   │       │   └── mspaint.exe.mui
│   │       ├── nb-NO/
│   │       │   └── mspaint.exe.mui
│   │       ├── nl-NL/
│   │       │   └── mspaint.exe.mui
│   │       ├── pl-PL/
│   │       │   └── mspaint.exe.mui
│   │       ├── pt-BR/
│   │       │   └── mspaint.exe.mui
│   │       ├── pt-PT/
│   │       │   └── mspaint.exe.mui
│   │       ├── ro-RO/
│   │       │   └── mspaint.exe.mui
│   │       ├── ru-RU/
│   │       │   └── mspaint.exe.mui
│   │       ├── sk-SK/
│   │       │   └── mspaint.exe.mui
│   │       ├── sl-SI/
│   │       │   └── mspaint.exe.mui
│   │       ├── sr-Latn-RS/
│   │       │   └── mspaint.exe.mui
│   │       ├── sv-SE/
│   │       │   └── mspaint.exe.mui
│   │       ├── th-TH/
│   │       │   └── mspaint.exe.mui
│   │       ├── tr-TR/
│   │       │   └── mspaint.exe.mui
│   │       ├── uk-UA/
│   │       │   └── mspaint.exe.mui
│   │       ├── zh-CN/
│   │       │   └── mspaint.exe.mui
│   │       └── zh-TW/
│   │           └── mspaint.exe.mui
│   └── snipping/
│       ├── SnippingTool.exe.mui
│       └── snipping_lang_files/
│           ├── ar-SA/
│           │   └── SnippingTool.exe.mui
│           ├── bg-BG/
│           │   └── SnippingTool.exe.mui
│           ├── cs-CZ/
│           │   └── SnippingTool.exe.mui
│           ├── da-DK/
│           │   └── SnippingTool.exe.mui
│           ├── de-DE/
│           │   └── SnippingTool.exe.mui
│           ├── el-GR/
│           │   └── SnippingTool.exe.mui
│           ├── en-GB/
│           │   └── SnippingTool.exe.mui
│           ├── es-ES/
│           │   └── SnippingTool.exe.mui
│           ├── es-MX/
│           │   └── SnippingTool.exe.mui
│           ├── et-EE/
│           │   └── SnippingTool.exe.mui
│           ├── fi-FI/
│           │   └── SnippingTool.exe.mui
│           ├── fr-CA/
│           │   └── SnippingTool.exe.mui
│           ├── fr-FR/
│           │   └── SnippingTool.exe.mui
│           ├── he-IL/
│           │   └── SnippingTool.exe.mui
│           ├── hr-HR/
│           │   └── SnippingTool.exe.mui
│           ├── hu-HU/
│           │   └── SnippingTool.exe.mui
│           ├── it-IT/
│           │   └── SnippingTool.exe.mui
│           ├── ja-JP/
│           │   └── SnippingTool.exe.mui
│           ├── ko-KR/
│           │   └── SnippingTool.exe.mui
│           ├── lt-LT/
│           │   └── SnippingTool.exe.mui
│           ├── lv-LV/
│           │   └── SnippingTool.exe.mui
│           ├── nb-NO/
│           │   └── SnippingTool.exe.mui
│           ├── nl-NL/
│           │   └── SnippingTool.exe.mui
│           ├── pl-PL/
│           │   └── SnippingTool.exe.mui
│           ├── pt-BR/
│           │   └── SnippingTool.exe.mui
│           ├── pt-PT/
│           │   └── SnippingTool.exe.mui
│           ├── ro-RO/
│           │   └── SnippingTool.exe.mui
│           ├── ru-RU/
│           │   └── SnippingTool.exe.mui
│           ├── sk-SK/
│           │   └── SnippingTool.exe.mui
│           ├── sl-SI/
│           │   └── SnippingTool.exe.mui
│           ├── sr-Latn-RS/
│           │   └── SnippingTool.exe.mui
│           ├── sv-SE/
│           │   └── SnippingTool.exe.mui
│           ├── th-TH/
│           │   └── SnippingTool.exe.mui
│           ├── tr-TR/
│           │   └── SnippingTool.exe.mui
│           ├── uk-UA/
│           │   └── SnippingTool.exe.mui
│           ├── zh-CN/
│           │   └── SnippingTool.exe.mui
│           └── zh-TW/
│               └── SnippingTool.exe.mui
├── Documentation.md
├── LICENSE
├── OtherAIFeatures.md
├── README.md
├── RemoveAI-UpdateCleanup.ps1
├── RemoveWindowsAIPackage/
│   ├── amd64/
│   │   ├── ZoicwareRemoveWindowsAI-amd641.0.0.0.cab
│   │   ├── amd64_16bf9f5ddcdcc858358ce8a2a9f69f935b0e2c72_31bf3856ad364e35_38655.38527.65535.65535_none_9dea49e759204384.manifest
│   │   ├── amd64_1ac4efa52cc987e34206a4b499ef297c16f443f9_31bf3856ad364e35_38655.38527.65535.65535_none_d12a7b37e1ce0c63.manifest
│   │   ├── amd64_3e5f6992f365ae98da785153cb853cdd2b8d334d_31bf3856ad364e35_38655.38527.65535.65535_none_21a198b98b0eb5cb.manifest
│   │   ├── amd64_690413e3dcead26f87b3989953c5ed27bb12eb95_31bf3856ad364e35_38655.38527.65535.65535_none_2f5fa210a2da208e.manifest
│   │   ├── amd64_761f3629e488278caa4c7585c950f520404712cf_31bf3856ad364e35_38655.38527.65535.65535_none_fab6052e6768b003.manifest
│   │   ├── amd64_a1b65e8b129c7dfee79b5234097d94812770c52a_31bf3856ad364e35_38655.38527.65535.65535_none_427e504fcbfba8f2.manifest
│   │   ├── amd64_bf9f7f39101e056d32e46992b64d45da3774921c_31bf3856ad364e35_38655.38527.65535.65535_none_1b7aa6c634649ec5.manifest
│   │   ├── amd64_c93ca6c2cd59575fe45bad46f6152c80cc5ab492_31bf3856ad364e35_38655.38527.65535.65535_none_048f8255f6dd3270.manifest
│   │   ├── amd64_d18d700de06fc98ae558e2a73994193f028d6209_31bf3856ad364e35_38655.38527.65535.65535_none_99bf2484525af2f0.manifest
│   │   ├── amd64_microsoft-copilot-d..oyment-languagepack_31bf3856ad364e35_38655.38527.65535.65535_none_0fea620d27c4484e.manifest
│   │   ├── amd64_microsoft-copilot-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_26df2268220c2a52.manifest
│   │   ├── amd64_microsoft-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_58a35da8a335eb56.manifest
│   │   ├── amd64_microsoft-windows-s..ngshandlers-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_f88b80f068ad03a6.manifest
│   │   ├── amd64_userexperience-aix-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_cdba7e3535b8898d.manifest
│   │   ├── amd64_userexperience-aix_31bf3856ad364e35_38655.38527.65535.65535_none_293807153aa35c79.manifest
│   │   ├── amd64_userexperience-coreai-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_494247c8d14488ba.manifest
│   │   ├── amd64_userexperience-coreai_31bf3856ad364e35_38655.38527.65535.65535_none_851c3d913b2d96b4.manifest
│   │   ├── amd64_userexperience-recall_31bf3856ad364e35_38655.38527.65535.65535_none_d1d3458f41002cd0.manifest
│   │   └── update.cat
│   └── arm64/
│       ├── ZoicwareRemoveWindowsAI-arm641.0.0.0.cab
│       ├── arm64_072c8668ec63514fc98714c09cef5ffb61eac4d0_31bf3856ad364e35_38655.38527.65535.65535_none_fc8a4193bbbf8ce9.manifest
│       ├── arm64_19b4f2d2eb01fe86e2858f3356507a3743d63a96_31bf3856ad364e35_38655.38527.65535.65535_none_c3b6ebc0bc9bc32a.manifest
│       ├── arm64_2415624e03eaf74c3ed2718f0823e7ef1746afdd_31bf3856ad364e35_38655.38527.65535.65535_none_8ebe44a9559113a2.manifest
│       ├── arm64_37e84906b7c3ad6ec7fd0f73eb941da2bbd40170_31bf3856ad364e35_38655.38527.65535.65535_none_4755105c8785546a.manifest
│       ├── arm64_9977ad932a57937cbd5b595b7054ef37a6fa80d7_31bf3856ad364e35_38655.38527.65535.65535_none_176e9ba77eb5736f.manifest
│       ├── arm64_af04861f8804c4ce83a52310a455da3f912b468f_31bf3856ad364e35_38655.38527.65535.65535_none_9c9d75201debd11a.manifest
│       ├── arm64_b1c39ab687ddb87f21e0bef8191922a64760b277_31bf3856ad364e35_38655.38527.65535.65535_none_8c5f153cdaa8c371.manifest
│       ├── arm64_d555b631e519d0dcd7872958a590cb5e81441910_31bf3856ad364e35_38655.38527.65535.65535_none_ab9a0f7301cc9b81.manifest
│       ├── arm64_f9b5a2b834a34ab4b8fa8da477a953885907d528_31bf3856ad364e35_38655.38527.65535.65535_none_a9f36e0ec06d9f38.manifest
│       ├── arm64_microsoft-copilot-d..oyment-languagepack_31bf3856ad364e35_38655.38527.65535.65535_none_0fea6a4727c43cea.manifest
│       ├── arm64_microsoft-copilot-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_26df2aa2220c1eee.manifest
│       ├── arm64_microsoft-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_58a365e2a335dff2.manifest
│       ├── arm64_microsoft-windows-s..ngshandlers-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_f88b892a68acf842.manifest
│       ├── arm64_userexperience-aix-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_cdba866f35b87e29.manifest
│       ├── arm64_userexperience-aix_31bf3856ad364e35_38655.38527.65535.65535_none_29380f4f3aa35115.manifest
│       ├── arm64_userexperience-coreai-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_49425002d1447d56.manifest
│       ├── arm64_userexperience-coreai_31bf3856ad364e35_38655.38527.65535.65535_none_851c45cb3b2d8b50.manifest
│       ├── arm64_userexperience-recall_31bf3856ad364e35_38655.38527.65535.65535_none_d1d34dc94100216c.manifest
│       └── update.cat
└── RemoveWindowsAi.ps1
Condensed preview — 127 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (384K chars).
[
  {
    "path": ".github/FUNDING.yml",
    "chars": 881,
    "preview": "# These are supported funding model platforms\n\ngithub: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [u"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/bug_report.md",
    "chars": 446,
    "preview": "---\nname: Bug report\nabout: Create a report to help improve the script\ntitle: ''\nlabels: bug\nassignees: ''\n\n---\n\n**Descr"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/feature_request.md",
    "chars": 467,
    "preview": "---\nname: Feature request\nabout: Suggest an idea for this project\ntitle: ''\nlabels: enhancement\nassignees: ''\n\n---\n\n**Is"
  },
  {
    "path": "Documentation.md",
    "chars": 5369,
    "preview": "## Remove Windows AI Documentation\n---\n### OS Support\n\n- The script is created for any version of Windows 10 and Windows"
  },
  {
    "path": "LICENSE",
    "chars": 1065,
    "preview": "MIT License\n\nCopyright (c) 2024 zoicware\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\no"
  },
  {
    "path": "OtherAIFeatures.md",
    "chars": 1509,
    "preview": "## Other AI Features in Windows\r\n\r\n- the following features cannot be disabled or removed via a script (unless further d"
  },
  {
    "path": "README.md",
    "chars": 6943,
    "preview": "# Remove Windows Ai\r\n## Why?\r\nThe current 25H2 build of Windows 11 and future builds will include increasingly more AI f"
  },
  {
    "path": "RemoveAI-UpdateCleanup.ps1",
    "chars": 19535,
    "preview": "function Run-Trusted([String]$command, $psversion) {\r\n\r\n    function RunAsTI {\r\n        param(\r\n            [Parameter(P"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_16bf9f5ddcdcc858358ce8a2a9f69f935b0e2c72_31bf3856ad364e35_38655.38527.65535.65535_none_9dea49e759204384.manifest",
    "chars": 777,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_1ac4efa52cc987e34206a4b499ef297c16f443f9_31bf3856ad364e35_38655.38527.65535.65535_none_d12a7b37e1ce0c63.manifest",
    "chars": 757,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_3e5f6992f365ae98da785153cb853cdd2b8d334d_31bf3856ad364e35_38655.38527.65535.65535_none_21a198b98b0eb5cb.manifest",
    "chars": 768,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_690413e3dcead26f87b3989953c5ed27bb12eb95_31bf3856ad364e35_38655.38527.65535.65535_none_2f5fa210a2da208e.manifest",
    "chars": 793,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_761f3629e488278caa4c7585c950f520404712cf_31bf3856ad364e35_38655.38527.65535.65535_none_fab6052e6768b003.manifest",
    "chars": 765,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_a1b65e8b129c7dfee79b5234097d94812770c52a_31bf3856ad364e35_38655.38527.65535.65535_none_427e504fcbfba8f2.manifest",
    "chars": 753,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_bf9f7f39101e056d32e46992b64d45da3774921c_31bf3856ad364e35_38655.38527.65535.65535_none_1b7aa6c634649ec5.manifest",
    "chars": 754,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_c93ca6c2cd59575fe45bad46f6152c80cc5ab492_31bf3856ad364e35_38655.38527.65535.65535_none_048f8255f6dd3270.manifest",
    "chars": 757,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_d18d700de06fc98ae558e2a73994193f028d6209_31bf3856ad364e35_38655.38527.65535.65535_none_99bf2484525af2f0.manifest",
    "chars": 764,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_microsoft-copilot-d..oyment-languagepack_31bf3856ad364e35_38655.38527.65535.65535_none_0fea620d27c4484e.manifest",
    "chars": 388,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_microsoft-copilot-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_26df2268220c2a52.manifest",
    "chars": 375,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_microsoft-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_58a35da8a335eb56.manifest",
    "chars": 364,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_microsoft-windows-s..ngshandlers-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_f88b80f068ad03a6.manifest",
    "chars": 404,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_userexperience-aix-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_cdba7e3535b8898d.manifest",
    "chars": 376,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_userexperience-aix_31bf3856ad364e35_38655.38527.65535.65535_none_293807153aa35c79.manifest",
    "chars": 365,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_userexperience-coreai-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_494247c8d14488ba.manifest",
    "chars": 379,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_userexperience-coreai_31bf3856ad364e35_38655.38527.65535.65535_none_851c3d913b2d96b4.manifest",
    "chars": 368,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/amd64/amd64_userexperience-recall_31bf3856ad364e35_38655.38527.65535.65535_none_d1d3458f41002cd0.manifest",
    "chars": 368,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_072c8668ec63514fc98714c09cef5ffb61eac4d0_31bf3856ad364e35_38655.38527.65535.65535_none_fc8a4193bbbf8ce9.manifest",
    "chars": 768,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_19b4f2d2eb01fe86e2858f3356507a3743d63a96_31bf3856ad364e35_38655.38527.65535.65535_none_c3b6ebc0bc9bc32a.manifest",
    "chars": 753,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_2415624e03eaf74c3ed2718f0823e7ef1746afdd_31bf3856ad364e35_38655.38527.65535.65535_none_8ebe44a9559113a2.manifest",
    "chars": 757,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_37e84906b7c3ad6ec7fd0f73eb941da2bbd40170_31bf3856ad364e35_38655.38527.65535.65535_none_4755105c8785546a.manifest",
    "chars": 764,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_9977ad932a57937cbd5b595b7054ef37a6fa80d7_31bf3856ad364e35_38655.38527.65535.65535_none_176e9ba77eb5736f.manifest",
    "chars": 765,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_af04861f8804c4ce83a52310a455da3f912b468f_31bf3856ad364e35_38655.38527.65535.65535_none_9c9d75201debd11a.manifest",
    "chars": 757,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_b1c39ab687ddb87f21e0bef8191922a64760b277_31bf3856ad364e35_38655.38527.65535.65535_none_8c5f153cdaa8c371.manifest",
    "chars": 777,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_d555b631e519d0dcd7872958a590cb5e81441910_31bf3856ad364e35_38655.38527.65535.65535_none_ab9a0f7301cc9b81.manifest",
    "chars": 793,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_f9b5a2b834a34ab4b8fa8da477a953885907d528_31bf3856ad364e35_38655.38527.65535.65535_none_a9f36e0ec06d9f38.manifest",
    "chars": 754,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_microsoft-copilot-d..oyment-languagepack_31bf3856ad364e35_38655.38527.65535.65535_none_0fea6a4727c43cea.manifest",
    "chars": 388,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_microsoft-copilot-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_26df2aa2220c1eee.manifest",
    "chars": 375,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_microsoft-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_58a365e2a335dff2.manifest",
    "chars": 364,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_microsoft-windows-s..ngshandlers-copilot_31bf3856ad364e35_38655.38527.65535.65535_none_f88b892a68acf842.manifest",
    "chars": 404,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_userexperience-aix-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_cdba866f35b87e29.manifest",
    "chars": 376,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_userexperience-aix_31bf3856ad364e35_38655.38527.65535.65535_none_29380f4f3aa35115.manifest",
    "chars": 365,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_userexperience-coreai-deployment_31bf3856ad364e35_38655.38527.65535.65535_none_49425002d1447d56.manifest",
    "chars": 379,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_userexperience-coreai_31bf3856ad364e35_38655.38527.65535.65535_none_851c45cb3b2d8b50.manifest",
    "chars": 368,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAIPackage/arm64/arm64_userexperience-recall_31bf3856ad364e35_38655.38527.65535.65535_none_d1d34dc94100216c.manifest",
    "chars": 368,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersio"
  },
  {
    "path": "RemoveWindowsAi.ps1",
    "chars": 305333,
    "preview": "param(\r\n    [switch]$EnableLogging,\r\n    [switch]$nonInteractive,\r\n    [ValidateSet('DisableRegKeys',          \r\n       "
  }
]

// ... and 82 more files (download for full content)

About this extraction

This page contains the full source code of the zoicware/RemoveWindowsAI GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 127 files (353.6 KB), approximately 136.8k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!