Updated Remove Apps Script, and a Workaround
I’ve updated the script attached to https://blogs.technet.com/b/mniehaus/archive/2015/11/11/removing-windows-10-in-box-apps-during-a-task-sequence.aspx to address a couple of issues:
- Fixed a bug that prevented the script from working properly offline when no RemoveApp.xml file was present (requiring the script to dynamically generate the list offline). Thanks to Osama Altawil for reporting that issue a few weeks ago.
- Modified the logic that located the RemoveApps.xml file. It now loads the file from the current PowerShell working directory.
I also updated the blog and script comments to indicate that the Storage Management Cmdlets are also required.
One other issue that has been reported by a variety of people: When running the script offline in Windows PE 1511 as part of an MDT Lite Touch task sequence, the script is unable to load the DISM PowerShell module, and as a result the script fails. We did figure out how to reproduce the problem with a generic Windows PE boot image:
- Load a web page or HTA using MSHTA.EXE, then close MSHTA.EXE.
- Run PowerShell.exe, try to “Import-Module DISM”.
The module import command fails with error 0x80131515. We’re still investigating exactly what’s going on with that, but in the meantime, there is a simple workaround, described at https://stackoverflow.com/questions/19957161/add-type-load-assembly-from-network-unc-share-error-0x80131515 for a similar problem. (For whatever reason, after running MSHTA.EXE, PowerShell thinks that the DISM module isn’t local.) Just add a step to your task sequence that copies a file named powershell.exe.config into X:\Windows\System32\WindowsPowerShell\v1.0 folder (or embed it in your boot image), with the following content:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
If you do that prior to the step that runs RemoveApps.ps1, then the DISM module will load fine and the script will work. (With any luck, there will be a permanent solution in a future ADK release.)
Comments
- Anonymous
December 31, 2015
On what was supposed to be a day off and the last day of the year at midnight, you are still supporting your MDT community.
Thanks! - Anonymous
January 03, 2016
The comment has been removed - Anonymous
January 03, 2016
Ugh. I posted version 1.2 of the script to fix that. I had tried the pre-PowerShell 3.0 method of determining the file location and that failed miserably in Windows PE, was hoping a relative path would work better. But hopefully $PSScriptRoot will be reliable. - Anonymous
January 04, 2016
Thanks Michael. After your update today, and the guidance above about fixing the DISM issue, I was finally able to successfully clean off a preset list of apps using the offline mode with MDT. Super helpful! - Anonymous
January 19, 2016
The comment has been removed - Anonymous
January 29, 2016
@Michael Niehaus, thanks for the great explanation, but i think i have a alternative solution that doesn't require you to copy any files. I guess this could be useful for other Things as well.
powershell.exe -ExecutionPolicy Bypass -command ([xml]'').Save("X:WindowsSystem32WindowsPowerShellv1.0powershell.exe.config") - Anonymous
January 29, 2016
The comment has been removed - Anonymous
February 02, 2016
Thanks Michael, this worked great on my RTM Win 10 build. Unfortunately the v15.11 upgrade reinstalled all of the Universal Applications and I can't find any GPO's to disable them. Would you have any suggestions? - Anonymous
February 22, 2016
Tried for awhile to get this to work in PE. Every time I run it, it returns that the package was not found -- though they're there. I even tried manually removing them in PE and still got the same return. Has anyone seen this running this process? - Anonymous
February 22, 2016
What is the error you are receiving?- Anonymous
May 04, 2016
The comment has been removed
- Anonymous
- Anonymous
February 23, 2016
Remove-AppxProvisionedPackage : Package not found. I tried Remove-AppxProvisionedPackage -Path %OSDISK% -package whatever like the script is running and that seemed to give the same return as well. - Anonymous
February 23, 2016
It sounds like you didn't include the DISM Cmdlets into the Windows PE boot image. If using MDT Lite Touch, also try "Import-Module DISM" to see if that returns an error (other than "not found", which indicates it's not there) related to the workaround above.- Anonymous
March 31, 2016
I am getting the following for every app INFO: Removing provisioned package Microsoft.AppconnectorPS>TerminatingError(Remove-AppxProvisionedPackage): "The system cannot find the file specified."Remove-AppxProvisionedPackage : The system cannot find the file specified.At \clmshares\itd\deploymentshare2013\scripts\removeapps.ps1:171 char:14+ ... $a = Remove-AppxProvisionedPackage -Path $script:OfflinePath - ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Remove-AppxProvisionedPackage], COMException + FullyQualifiedErrorId : Microsoft.Dism.Commands.RemoveAppxProvisionedPackageCommandRemove-AppxProvisionedPackage : The system cannot find the file specified.At \clmshares\itd\deploymentshare2013\scripts\removeapps.ps1:171 char:14+ ... $a = Remove-AppxProvisionedPackage -Path $script:OfflinePath - ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Remove-AppxProvisionedPackage], COMException + FullyQualifiedErrorId : Microsoft.Dism.Commands.RemoveAppxProvisionedPackageCommandI run the Import-Module DISM and receive no erros..... any ideas?
- Anonymous
- Anonymous
February 23, 2016
I went back in and after copying the config file over, my test machine ran Import-Module dism without issue. What's strange is I can point get-appxprovisionedpackage at the offline install and see the apps but then remove-appx fail to find it, like it's not installed or something. I opted to remove during deployment for now, at least with the consumer experiences GPO I can keep them out going forward.- Anonymous
March 10, 2016
I have the same issue as Ryan. I seems that the Remove-AppxProvisionedPackage command needs a different parameter to remove the packages offline. Should the list be storing .PackageName instead of .Display name?
- Anonymous
- Anonymous
March 18, 2016
trying to run the script to remove the win 10 applications and it is coming back with Mounting Windows-Image failed...Error: The term 'Mount-WindowsImage' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. have tried going to powershell 4 and that didn't seem to make a difference.suggestions? - Anonymous
March 22, 2016
I'm curious how to do this during (Win10 to Win10) in-place upgrades (via ts). I'm guessing we would apply this using an online scenario, but the local Administrator account would need to be enabled first or you would need to configure the task sequence to run as a different user, in order to run the remove powershell scripts? Having a tough go at this, any suggestions? - Anonymous
March 30, 2016
Finally got all the steps in the, offline version, TS running with no errors, and it spends a good amount of time on the Removing apps step however once it finishes the deploy and reboots all the apps are either still there, or have been put back on. As I get no error messages at all, I assume they were successfully removed but ended up back on.... Using 1511 x64 Enterprise.....Any suggestions? - Anonymous
April 13, 2016
I found out the hard way the importance of correct encoding of the Powershell.exe.config file.To anyone still having issues after following this brilliant guide, Offline appx package removal, make sure the Powershell.exe.config file is encoded with UTF8 (I created the file with notepad and the default encoding ANSI - no fun experience).- Anonymous
April 13, 2016
Seems like I had more problems than I thought. Got it solved with pretty much the same approach as John mentioned (January 19, 2016 at 11:05 pm) but picking up the dll from the deployment share instead. Still, It's probably a good idea to have the correct encoding of the settings file :)..
- Anonymous
- Anonymous
April 14, 2016
The comment has been removed - Anonymous
May 23, 2016
Can we please see a screenshot of the task sequence step where we use the workaround to copy the powershell.exe.config to the X:\Windows\System32\WindowsPowerShell\v1.0 folder? I am trying that, but I am still having problems and feeling really dumb right now. - Anonymous
August 02, 2016
I have used this script before but I have formated my computer and now I get this when I run the script.\removeapps.ps1 : The term '.\removeapps.ps1' is not recognized as the name of a cmdlet, function, script file,What have I forgotten to do?Thanks Peter- Anonymous
August 02, 2016
Sorted it.Even though everything told me to place the .ps1 file in to the various modules folders. Puting into windows\system32 worked.
- Anonymous