Updated Remove Apps Script, and a Workaround


I’ve updated the script attached to http://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 http://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 (18)
  1. Miroslaw says:

    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!

  2. Miroslaw says:

    For version 1.1 of RemoveApps.ps1
    I've modified line 96 to read $configFile = $PSScriptRoot + "" + "RemoveApps.xml"

    because the XML was not being found otherwise.
    Line 121 has an undefined variable $dataDir

  3. 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.

  4. Aaron.H says:

    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!

  5. John says:

    Hi Michael, Thanks for taking the time to write this blog - Just to let you know this solution only half worked for us. It seemed that this would allow us to run one script that referenced the DISM cmdlets, but running another script (after a backup) would
    fail. In the end we had to copy down a new Microsoft.DISM.Powershell.dll using a PowerShell script. I've blogged about this on my blog:
    http://justanotheritblog.co.uk where I have linked to your post. Thanks for the help! John.

  6. TribleTrouble says:

    @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")

  7. TribleTrouble says:

    Looks like the actual XML was stripped from the command when i posted it, it needs to be added in between the two singlequotes after [xml] without linebreaks.

  8. Aymann says:

    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?

  9. ryan says:

    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?

  10. What is the error you are receiving?

    1. rambler says:

      I am seeing odd behaviour. Running v1.2 I have tried online and offline, but neither fully works.
      When I run offline as a task in MDT task sequence it removes 7 and warns that it is unable to find the remaining 15.

      If I then run after the deployment I can view the RemoveApps.log file:
      **********************
      Windows PowerShell transcript start
      Start time: 20160504004905
      Username: 6TBR252\Administrator
      RunAs User: 6TBR252\Administrator
      Machine: 6TBR252 (Microsoft Windows NT 10.0.10240.0)
      Host Application: C:\windows\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe
      Process ID: 4384
      PSVersion: 5.0.10240.16384
      WSManStackVersion: 3.0
      SerializationVersion: 1.1.0.1
      CLRVersion: 4.0.30319.42000
      BuildVersion: 10.0.10240.16384
      PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0.10240.16384
      PSRemotingProtocolVersion: 2.3
      **********************
      Transcript started, output file is C:\Users\ADMINI~1\AppData\Local\Temp\RemoveApps.log
      PS>TerminatingError(New-Object): "Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."
      INFO: Wrote list of apps to C:\Users\ADMINI~1\AppData\Local\Temp\RemoveApps.xml, edit and place in the same folder as the script to use that list for future script executions
      INFO: Apps selected for removal: .Count
      **********************
      Windows PowerShell transcript end
      End time: 20160504004907
      **********************

      The log notes the creation of RemoveApps.xml, but it is not written.

      Any help appreciated.

  11. ryan says:

    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.

  12. 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.

    1. Shawn Butler says:

      I am getting the following for every app

      INFO: Removing provisioned package Microsoft.Appconnector
      PS>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.RemoveAppxProvisionedPackageCommand
      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.RemoveAppxProvisionedPackageCommand

      I run the Import-Module DISM and receive no erros.....
      any ideas?

  13. ryan says:

    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.

    1. ClientGuy says:

      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?

  14. gizmo says:

    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 progr
    am. 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?

  15. Brad says:

    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?

  16. Shawn Butler says:

    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?

  17. Pelle says:

    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).

    1. Pelle says:

      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 :)..

  18. Ryan says:

    So one of my original images, I didn't leave in the Calculator, so it removed that and pretty much everything else. So when trying to add back I'm getting the error below. Any help is greatly appreciated.

    Command:
    Add-AppxPackage -Path 'C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_10.1510.9020.0_neutral_split.scale-125_8wekyb3d8bbwe\AppxManifest.xml' -Register -DisableDevelopmentMode -Verbose

    Error:

    Add-AppxPackage : Deployment failed with HRESULT: 0x80073CF3, Package failed updates, dependency or conflict
    validation.
    Windows cannot install resource package Microsoft.WindowsCalculator_8wekyb3d8bbwe because the app package it requires
    could not be found. Ensure that the app package is installed before installing the resource package
    NOTE: For additional information, look for [ActivityId] 74638d54-9591-0001-f25b-64749195d101 in the Event Log or use
    the command line Get-AppxLog -ActivityID 74638d54-9591-0001-f25b-64749195d101
    + CategoryInfo : WriteError: (C:\Program File...ppxManifest.xml:String) [Add-AppxPackage], IOException
    + FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

  19. Big E IT says:

    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.

  20. Peter says:

    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

    1. Peter says:

      Sorted it.
      Even though everything told me to place the .ps1 file in to the various modules folders. Puting into windows\system32 worked.

Comments are closed.

Skip to main content