I’ve been working on our first Windows 11 deployments, and have noticed I’m getting the following error when the decrapifier script step runs from an MDT task sequence.

As this is the first Windows 11 version I’ve deployed, I don’t know if this is specific to just 24H2, or if there’s other W11 versions it’s also present with.

When the script is run on the client outside of the task sequence (i.e. finish the deployment, then run the script), it does so without error, getting and removing appxpackages as expected, it only seems to be failing as part of the task sequence and I feel like I’m pretty much at a dead end as to why.
I found semi-related suggestions of ensuring features were enabled in Windows PE (.NET and PowerShell) which I added and regenerated boot images, although to my mind it’s a post-PE step anyway (I have the script executing between Restore User State and Restore Groups under State Restore). I also tried the suggestion of calling Import-Module Appx beforehand to see if the issue was the Get-AppxPackage cmdlet not being loaded for some reason, but this had no effect (and threw no additional error)

The error I’m getting is (the actual script path is the UNC path for the script within the deployment share):

>The type initializer for '<Module>' threw an exception.
> At \\path\to\script.ps1:132 char:17
>+      $RemoveApps = Get-AppxPackage -allusers | where-object {$_.na...
>+                          ~~~~~~~~~~~~~~~
>NotSpecified (:) [], TypeInitializationException

Line 132 char 17 is the start of the Get-AppxPackage command
I have a modified version of the script, hence the different line number, but I’ve tested with the vanilla script dated Jan 6 2022 and get the same error, just a different line number (plus several more errors relating to registry keys etc. that I’ve taken out for W11 in my modified version - like the W10 start menu xml)

Has anyone else seen something similar? Did you find a way to ‘fix’ it?
I’ve confirmed I don’t get the error on W10 with all else the same (same order in task sequence, same parameters, all other MDT settings/option the same etc.)

6 Spice ups

I’m fighting this exact same issue. I ran this script with windows 10 and 11 22h2 with no issues. Just went to do a new deployment with 24h2 and am having issues. Did you ever find the work around?

Same issue here. This is new with Windows 11 24H2 and was not happening with Windows 11 23H2. (or Windows 10)

It doesn’t seem to be possible to user Get-AppxPackage | Remove-AppxPackage from within a task sequence anymore. In my case I’m trying to remove “New Outlook”.

The best I could do is remove the provisioning package, which does work:

Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq "Microsoft.OutlookForWindows" } | ForEach-Object {
    Remove-AppxProvisionedPackage -Online -PackageName $_.PackageName
}

Removing the provisioning package prevents New Outlook from installing when new users log in, but does still leave a copy in the local administrator account that the deployment was running under since it already installed itself before the provisioning package was removed…

Removing the provisioning package before capturing doesn’t work either - Microsoft reinstalls it when the image first boots during the deployment - they really want you to have New Outlook!

I just updated MDT with Windows 11 24H2 and also seeing the same issue.
Copying the script to the machine and running it works fine but doesnt run correctly via MDT.
Did anyone find a fix?

robyholmes did Versions for Windows 11 Deployment | O/S Deployment

Update for others on this, it seems you can’t use the Powershell Script option on the Task Sequence. So you use the ‘Run Command Line’ step instead with the following:

Powershell.exe -ExecutionPolicy ByPass -File “%SCRIPTROOT%[i]W11 Apps Removal Script[/i].ps1”