none
Problem with Remove-AppxProvisionedPackage called in TS - cmdlet hangs on intermittent basis RRS feed

  • Question

  • This post is not only to get potential solutions to this specific issue, but also to take the pulse from peers that could also be experiencing this problem.

    FYI, I actually have a ticket opened with Microsoft for this, but since things are not moving fast, I am trying to collect data as much as possible.

    We do need to remove some builtin APPX apps, not only in bare-metal scenario, but also during upgrade (Win7 to Win10, and Win10 to Win10).

    There are a few ways to do so, using PowerShell or DISM in online mode, and DISM in offline mode. Many PowerShell scripts can be found on the web to remove APPX apps online, those scripts often rely on Remove-AppxProvisionedPackage cmdlet. I saw from other posts that people having this issue often fallback removing those apps offline, which is fine in bare-metal scenarios, but not feasible in upgrade scenario when using a third party disk encryption tool that does not allow to suspend protection like BitLocker. This is the case for the client I am currently working for.

    In last resort, if this issue cannot be solved on a timely manner, I will go with DISM commands in offline mode for bare-metal scenario, and for upgrade scenario, customize the install.wim file in my upgrade package to remove the APPS manually in offline mode. But ideally, in our situation, the PowerShell cmdlets would be the easiest way to go, especially with the frequent  releases of Windows 10 versions.

    This issue is not related to script code error, because the script we use to remove APPX works fine, it is just that on an intermittent basis, when we call the Remove-AppxProvisionedPackage cmdlet, it will just hang. We do remove about 20 apps, and the hang can occur on any of them.

    What I found so far is that the cmdlet uses DISM APIs to remove APPX, when we call it, we can see in the C:\Windows\Logs\DISM\DISM.log the call to the APPX removal, here is a sample:

    2019-05-21 11:15:21, Info                  DISM   API: PID=7744 TID=4156 Calling RemoveAllUserAppx with package full name = Microsoft.XboxApp_41.41.18001.0_neutral_~_8wekyb3d8bbwe - CRemoveAppxCommandObject::InternalExecute

    When tha hang occurs, there is absolutely no error showing at the PowerShell level or DISM log, it is just like an infinite loop.

    Microsoft support did analyze many dumps and trace that I sent to them, they found out a strange behavior where the AppXSVC service, which should be running when installing or removing APPX apps, was stopped while the cmdlet was still waiting for the uninstall to complete. This serivce is configured in manual startup mode by default.

    So far, I am reproducing the issue when calling the cmdlet from a PowerShell script launched through a SCCM task sequence, the SCCM CB infra is at 1902 version, but I also had the issue with 1810. I am not 100% sure if SCCM TS has a role to play with this, but I cannot exclude it based on my tests. I tried reproducing the issue by running the PowerShell script manually, or through a scheduled task running under the SYSTEM account, and I was not able to do so.

    So far, I have never experienced the issue on older computer models (like 2 or 3 years old), I only see it on recent computer models. At the beginning, I thought it could be driver related, I did many tests by using minimal drivers (network) in the driver package, issue was still present. I tried to see if it could be related to a BIOS setting, but didn't find anything with it. Take note that I am also using latest drivers and BIOS updates published by the PC manufacturer.

    I can reproduce the issue on many recent computer models. I checked the different models on which I have experienced it so far to try to find a common denominator. The most obvious is that they all have a NVME disk. The older computer models we have on the floor, and for which we never had the issue, are SATA SSD or SATA HDD.

    Also, this is not an issue related to a specific version of Windows 10, so far, I have been able to reproduce it with Windows 10 1803 and 1809.

    Other tests I did to find a viable workaround are:

    • Disable APPX updates before PowerShell script execution by configuring a local group policy + reboot: powershell.exe -command "Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\WindowsStore -Name AutoDownload -Value 2 -Type DWord -Force" It seems to help but issue still occurs.
    • Inject latest quality updates in the WIM, issue occurs even more often when I did that.
    • Configure the AppXSVC service in Automatic startup mode before PowerShell script execution. It seems to help, but issue still occurs.
    • Run the PowerShell script with a Run Command Line task instead of Run PowerShell Script task in the task sequence, that didn't change anything.

    I found out that when the hang occurs, a DISMHOST.exe process is running, if I kill this process, the script execution continues without error. After execution, I check the installed APPX with the Get-AppxProvisionedPackage -Online cmdlet to find out that the apps were effectively removed, including the one on which the hang occurred.

    So, I modified the PowerShell script to run the Remove-AppxProvisionedPackage in a ScriptBlock (so in asynchronous mode), then I configured a sleep delay, if the DISMHOST.exe process is still running after this delay, I kill it. So far, this is the best workaround I found to be working 100% of the time, but I do not consider it as a viable workaround since killing a process is definitely not recommanded, even if the apps get removed anyway.

    A colleague told me that he found information about other people suspecting issue with the Remove-AppxProvisionedPackage cmdlet when run on computers having NVME disks. I don't know if many other people are in the same situation as me.

    I will keep this post updated once I get interesting information from Microsoft support.

    Tnx

    Patrick


    • Edited by Patrick77298 Tuesday, May 21, 2019 6:06 PM Correction
    Tuesday, May 21, 2019 5:10 PM

Answers

  • Just to close this thread.

    With Windows 10 1809 and higher, no more need to run the Remove-AppxProvisionedPackage -Online cmdlet, the Remove-AppxPackage -AllUsers cmdlet will remove both the provisioned package and from users. This is confirmed by Microsoft and the support engineer told me that they plan to release a KB article on this. From my side, we have been using a new version of our script using only Remove-AppxPackage -AllUsers and never had any issue.

    For Windows 10 1803, Microsoft told me that you still need to run the Remove-AppxProvisionedPackage -Online cmdlet followed by Remove-AppxPackage -Allusers. Nothing will be done from their side to make Windows 10 1803 behaving like 1809 since this release is already starting to get old; they are already performing minimal support for 1803 until its death scheduled for November 2020.

    So with Windows 10 1803, the intermittent hang issue will still be present with Remove-AppxProvisionedPackage -Online. Recently, I went to another client using Windows 10 1803 and they had the exact same issue, they use Lenovo computers. A way to workaround the issue on this version of Windows is to remove the APPX offline or if you still want to do it online, in your PowerShell script, launch the problematic cmdlet through a Start-Job ScriptBlock to bypass the hang, you may sleep a few seconds after launching the script block. This is not elegant, but so far it did the job for us; it seems that everytime the hang occurs, the APPX is removed, it is just that the PowerShell cmdlet never received the return code from DISM and waits indefinitely. Ex.:

    Start-Job -ScriptBlock {
    
            #We proceed with provisioned application removal
            Try
            {
    
              Remove-AppxProvisionedPackage -Online -PackageName $Using:sProvPackageFullName
    
            }
    
            #Error handling in case of removal failure
            Catch
            {
    
              $sErrorMessage = $_.Exception.Message
    
              $sLogOutput = "Removal of provisioned app $Using:sAppxName failed, error message is : " + $sErrorMessage
              Write-Output $sLogOutput
    
            }
    
          }
    
          #Sleep for 3 seconds
          Start-Sleep -Seconds 3
    
          #Continue with Remove-AppxPackage -AllUsers

    • Marked as answer by Patrick77298 Saturday, October 26, 2019 4:45 AM
    Saturday, October 26, 2019 4:44 AM

All replies

  • I actually just started seeing my Windows 10 Powershell script randomly hang up as well. I'm running SCCM 1810, and imaging with Win 10 1803. Our intern has seen it happen twice in about 15 machines that he has imaged. The task just sits on the powershell script forever, so I had him kill the process. I figured he was just cursed haha... The machines he has had an issue with are newer Dell Optiplex 5050's, which have Sata SSD's. I keep the drivers and BIOS updates at the latest versions in the task as well. I will have to dig into it if it occurs again to see if it's the same issue you've discovered. Appreciate you taking the time to post this!

    Dennis

    Wednesday, May 22, 2019 12:08 PM
  • Hi,

    can you post the script as well as the place from the TS step?
    It also can depend on the packages (required) which you want to remove.

    Consumer Features disabled?

    <RunSynchronous>
                    <RunSynchronousCommand wcm:action="add">
                        <Description>disable driver update</Description>
                        <Order>1</Order>
                        <Path>reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OOBE /v DisableVoice /d 1 /t REG_DWORD /f</Path>
                    </RunSynchronousCommand>
                    <RunSynchronousCommand wcm:action="add">
                        <Description>DisableWindowsConsumerFeatures</Description>
                        <Order>2</Order>
                        <Path>reg add HKLM\Software\Policies\Microsoft\Windows\CloudContent /v DisableWindowsConsumerFeatures /t REG_DWORD /d 1 /f</Path>
                    </RunSynchronousCommand>
                    <RunSynchronousCommand wcm:action="add">
                        <Description>disable WindowsStore</Description>
                        <Order>3</Order>
                        <Path>reg add HKLM\SOFTWARE\Policies\Microsoft\WindowsStore /v AutoDownload /t REG_DWORD /d 2 /f</Path>
                    </RunSynchronousCommand>
                </RunSynchronous>

    $apps=@( 	
    "Microsoft.BingWeather_4.25.20211.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.DesktopAppInstaller_2019.125.2243.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.GetHelp_10.1706.13331.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.Getstarted_7.3.20251.0_neutral_~_8wekyb3d8bbwe"
    #"Microsoft.HEIFImageExtension_1.0.13472.0_x64__8wekyb3d8bbwe"
    "Microsoft.Messaging_2019.125.32.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.Microsoft3DViewer_5.1902.20012.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.MicrosoftOfficeHub_18.1901.1141.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.MicrosoftSolitaireCollection_4.2.11280.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.MicrosoftStickyNotes_3.1.53.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.MixedReality.Portal_2000.19010.1151.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.MSPaint_2019.213.1858.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.Office.OneNote_16001.11126.20076.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.OneConnect_5.1902.361.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.People_2019.123.2346.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.Print3D_3.3.311.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.ScreenSketch_2018.1214.231.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.SkypeApp_14.35.152.0_neutral_~_kzf8qxf38zg5c"
    "Microsoft.StorePurchaseApp_11811.1001.1813.0_neutral_~_8wekyb3d8bbwe"
    #"Microsoft.VP9VideoExtensions_1.0.13333.0_x64__8wekyb3d8bbwe"
    "Microsoft.Wallet_2.4.18324.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.WebMediaExtensions_1.0.13321.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.WebpImageExtension_1.0.12821.0_x64__8wekyb3d8bbwe"
    "Microsoft.Windows.Photos_2019.18114.19418.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.WindowsAlarms_2019.105.629.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.WindowsCalculator_2019.105.612.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.WindowsCamera_2018.826.78.0_neutral_~_8wekyb3d8bbwe"
    "microsoft.windowscommunicationsapps_16005.11029.20108.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.WindowsFeedbackHub_2019.226.2324.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.WindowsMaps_2019.108.627.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.WindowsSoundRecorder_2019.105.618.0_neutral_~_8wekyb3d8bbwe"
    #"Microsoft.WindowsStore_11811.1001.1813.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.Xbox.TCUI_1.23.28002.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.XboxApp_48.48.7001.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.XboxGameOverlay_1.32.17005.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.XboxGamingOverlay_2.26.14003.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.XboxIdentityProvider_12.50.6001.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.XboxSpeechToTextOverlay_1.17.29001.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.YourPhone_2018.1128.231.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.ZuneMusic_2019.18111.17311.0_neutral_~_8wekyb3d8bbwe"
    "Microsoft.ZuneVideo_2019.18111.17311.0_neutral_~_8wekyb3d8bbwe"
    )
    foreach ($app in $apps) {Get-AppXProvisionedPackage -path "c:\mount\1903" | where PackageName -EQ $app | Remove-AppxProvisionedPackage}
    

    BR, G.

    Monday, May 27, 2019 9:04 AM
  • Hi,

    Take note that we are having the issue when removing the APPX applications online, not offline.

    The PowerShell script step runs just after the Setup Windows and ConfigMgr task.

    The hang can occur on any of the applications that we remove, it is really intermittent, here's the list:

    AppxName
    Microsoft.Getstarted
    Microsoft.Microsoft3DViewer
    Microsoft.MicrosoftOfficeHub
    Microsoft.MicrosoftSolitaireCollection
    Microsoft.Office.OneNote
    Microsoft.OneConnect
    Microsoft.Print3D
    Microsoft.SkypeApp
    Microsoft.Wallet
    Microsoft.WindowsCommunicationsApps
    Microsoft.WindowsFeedbackHub
    Microsoft.Xbox.TCUI
    Microsoft.XboxApp
    Microsoft.XboxGameOverlay
    Microsoft.XboxGamingOverlay
    Microsoft.XboxIdentityProvider
    Microsoft.XboxSpeechToTextOverlay
    Microsoft.ZuneMusic
    Microsoft.ZuneVideo

    So far, I tried disabling Windows Store updates (Autodownload registry value), it seemed to help reducing the number of occurences, but it didn't fix the issue, it does still happen.

    I see in your sample that you also disable Cortana voice (DisableVoice registry value) and consumer features (suggested tiles in Start layout - DisableWindowsConsumerFeatures registry value).

    I will give it a try by adding those policies before running the script.

    For reference, here's the PowerShell script we use, it is based on a template that you can easily find on the web:

    $CSVInputFilePath = ".\Builtin Universal Apps To Remove.csv"
    
    $sLogFile = ($Env:SystemDrive) + "\Logs\Remove Builtin Universal Apps.log"
    
    #Start logging
    Start-Transcript $sLogFile
    
    Write-Output "Logging to $sLogFile"
    
    #We import the CSV file content
    $CSVInputFile = Import-CSV $CSVInputFilePath
    
    #We proceed if the input CSV file is present
    If (Test-Path $CSVInputFilePath)
    {
    
      #We process each line (or record) of the file
      ForEach ($objLine in $CSVInputFile)
      {
    
        #We retrieve the universal application display name from the current line
        $sAppxName = $objLine.AppxName
    
        #We retrieve the provisioned package full name (the one containing a GUID)
        $sProvPackageFullName = (Get-AppxProvisionedPackage -Online | Where {$_.DisplayName -eq $sAppxName}).PackageName
    
        #We proceed if we were able to retrieve the provisioned package full name (application found)
        If ($sProvPackageFullName)
        {
    
          $sLogOutput = "Removing provisioned universal application : " + $sAppxName
          Write-Output $sLogOutput
    
          #We proceed with provisioned application removal
          Try
          {
    
            Remove-AppxProvisionedPackage -Online -PackageName $sProvPackageFullName
    
          }
    
          #Error handling in case of removal failure
          Catch
          {
    
            $sErrorMessage = $_.Exception.Message
    
            $sLogOutput = "Removal of provisioned app $sAppxName failed, error message is : " + $sErrorMessage
            Write-Output $sLogOutput
    
          }
    
        }
    
        #Log message if the application was not found
        Else
        {
    
          $sLogOutput = "Provisioned universal application $sAppxName was not detected."
          Write-Output $sLogOutput
    
        }
    
        #We retrieve the package full name (the one containing a GUID)
        $sPackageFullName = (Get-AppxPackage $sAppxName).PackageFullName
    
        #We proceed if we were able to retrieve the package full name (application found)
        If ($sPackageFullName)
        {
    
          $sLogOutput = "Removing universal application from user profiles: " + $sAppxName
          Write-Output $sLogOutput
    
          #We proceed with application removal from all user profiles
          Try
          {
    
            Remove-AppxPackage -Package $sPackageFullName -AllUsers
    
          }
    
          #Error handling in case of removal failure
          Catch
          {
    
            $sErrorMessage = $_.Exception.Message
    
            $sLogOutput = "Non-critical error: Removal from user profiles of app $sAppxName failed , error message is : " + $sErrorMessage
            Write-Output $sLogOutput
    
          }
    
        }
    
        #Log message if the application was not found in user profiles
        Else
        {
    
          $sLogOutput = "Universal application $sAppxName was not detected in user profiles."
          Write-Output $sLogOutput
    
        }
    
      }
    
    }
    
    #Log error message if input CSV file is not found
    Else
    {
    
      $sLogOutput = "Error - Input CSV file not found: " + $CSVInputFilePath
      Write-Output $sLogOutput
    
      #Stop logging
      Stop-Transcript
    
      Exit 666
    
    }
    
    #Stop logging
    Stop-Transcript


    • Edited by Patrick77298 Monday, May 27, 2019 8:32 PM Correction
    Monday, May 27, 2019 8:16 PM
  • Just to add information about the fact that I have been able to reproduce the problem with Windows 10 1903 also. The case is still under investigation with Microsoft.
    Monday, May 27, 2019 8:18 PM
  • Just a side comment, I am using install.wim directly in SCCM OSD, using both PS1 scripts, remove and removeprovisioned published during 1703, but now running those 1803 and no problems. Done wipe and load and in-Place upgrade both. I use lot of GPO to stop communicating to MS services. Never used dism for this purpose.

    MCSE Mobility 2018. Expert on SCCM, Windows 10, ALOVPN, MBAM.

    Tuesday, May 28, 2019 6:35 AM
  • Just to add information about the fact that I have been able to reproduce the problem with Windows 10 1903 also. The case is still under investigation with Microsoft.

    I'm not a friend of this approach because the lead time per client is extended. Therefore, make all the adjustments on a modular level and have the best experience with it.
    Costs me about 1 hour per OS version and if you calculate the throughput time per client and script, this results (for large environment) quickly in several days / weeks (without time consumption for troubleshooting because PS has always dependencies and not every script that runs equal in TS).

    Anyway, the script ends (in my Lab/W10 1903) with an exception on line 65 where the package name was not found and it seems that this is not really designed for Task Sequence.
    As well as in line 2, $Env:SystemDrive was resolved to C:\_SMSTaskSequence\Packages\[PkgName]\ which indicates a fault, because the logfile would be never seen if the TS run successfull.

    So for comparison, i take another script which do the job quick (wihout error).

    $programs=@()
    $programs+="Microsoft.Getstarted"
    $programs+="Microsoft.Microsoft3DViewer"
    $programs+="Microsoft.MicrosoftOfficeHub"
    $programs+="Microsoft.MicrosoftSolitaireCollection"
    $programs+="Microsoft.Office.OneNote"
    $programs+="Microsoft.OneConnect"
    $programs+="Microsoft.Print3D"
    $programs+="Microsoft.SkypeApp"
    $programs+="Microsoft.Wallet"
    $programs+="Microsoft.WindowsCommunicationsApps"
    $programs+="Microsoft.WindowsFeedbackHub"
    $programs+="Microsoft.Xbox.TCUI"
    $programs+="Microsoft.XboxApp"
    $programs+="Microsoft.XboxGameOverlay"
    $programs+="Microsoft.XboxGamingOverlay"
    $programs+="Microsoft.XboxIdentityProvider"
    $programs+="Microsoft.XboxSpeechToTextOverlay"
    $programs+="Microsoft.ZuneMusic"
    $programs+="Microsoft.ZuneVideo"
    
    ForEach ($App in $programs){
        $PackageFullName = (Get-AppxPackage $App).PackageFullName
        $ProPackageFullName = (Get-AppxProvisionedPackage -online | where {$_.Displayname -eq $App}).PackageName
        write-host $PackageFullName
        Write-Host $ProPackageFullName
        if($PackageFullName){
            Write-Host "Removing Package: $App"
            remove-AppxPackage -package $PackageFullName
        }
        else{
            Write-Host "Unable to find package: $App"
        }
        if($ProPackageFullName){
            Write-Host "Removing Provisioned Package: $ProPackageFullName"
            Remove-AppxProvisionedPackage -online -packagename $ProPackageFullName
        }
        else{
            Write-Host "Unable to find provisioned package: $App"
        }
    }
    

    If you like a more professional way, then try this https://github.com/SCConfigMgr/ConfigMgr/blob/master/Operating%20System%20Deployment/Invoke-RemoveBuiltinApps.ps1 from Nickolaj Andersen amazing Repository https://github.com/SCConfigMgr/ConfigMgr

    BR, G.

    Tuesday, May 28, 2019 11:04 AM
  • I forgot to mention that the Logs folder at the root of system drive referred in the script that I provided is pre-created before the script execution, which explains the fact that the script didn't resolve to the correct logging location when you tested it. Anyway, the issue I am having is not related to script execution failure or exception. In our environment, the script works fine or hangs on Remove-AppxProvisionedPackage.

    As for the method we use, effectively, we could remove those apps offline and manually from the Install.wim to avoid the processing on clients. But the script execution time, when it runs fine, is pretty short, about 10-15 seconds, and the fact that we handle the applications to remove using their friendly name in a separate CSV file is just to make the process less cumbersome.

    It is client processing time optimization (the way you do) against tasks optimization for the OSD staff (our way). It is all based on compromise and choice.

    My point here is more that Microsoft provides those cmdlets to remove APPX online and it is their job to make them reliable and document their requirements if any (ex.: many people talk about the need to disable Windows store updates before running the cmdlet, it makes sense, but honestly, the tool should handle that automatically, moreover, the cmdlet docs from Microsoft doesn't talk about it at all). So I am not ready to give up yet Microsoft.

    I see in your suggested script that you call Remove-AppXPackage first, then Remove-AppxProvisionedPackage, also, you don't specify the -AllUsers parameter for Remove-AppXPackage. I will try your script to see if I am still able to reproduce the issue.

    Tnx



    • Edited by Patrick77298 Tuesday, May 28, 2019 8:42 PM Correction
    Tuesday, May 28, 2019 3:32 PM
  • Yes, I think to place the topic in an official position is also a good idea and I did not want to give a lesson but only express my opinion. Deployment process(es) depends on many factors and not everyone shares the same views. The -AllUsers switch is in my opinion only necessary if user profiles already exist, but this is not the case in this step. 
    I'm not quite sure where the script works fine, but maybe another comparison helps: https://gallery.technet.microsoft.com/Windows-10-remove-builtin-3a65a09b

    Good luck & BR, G.

     
    Wednesday, May 29, 2019 9:17 AM
  • I did a test and found something interesting. The script we have is used for both bare-metal and upgrade scenarios (Win7 to Win10 and Win10 to Win10), this is why we use the -AllUsers switch.

    So I did try your script, but I found that if you omit Remove-AppXProvisionedPackage -Online, the cmdlet causing us issues, and add the -AllUsers parameter to Remove-AppXPackage, the provisioned apps get removed also.

    After execution, I ran the Get-AppXProvisionedPackage -Online cmdlet and the apps didn't appear, they were removed. I did this test on Win10 1809. Another interresting fact is that Remove-AppXPackage -AllUsers cmdlet, as opposed to Remove-AppXProvisionedPackage -Online, do not use DISM APIs, applications got removed and I didn't find any entry in the C:\Windows\Logs\DISM\DISM.log about it. This looks promising. I am now doing reliability tests and will get back with results.

    I will also ask Microsoft to provide explanation and clarification about those cmdlets. The documentation on Microsoft Docs site is not very detailed.

    If you have a chance, can you run the script below in your Win10 1903 task sequence to see if you get the same result?

    Tnx

    $programs=@()
    $programs+="Microsoft.Getstarted"
    $programs+="Microsoft.Microsoft3DViewer"
    $programs+="Microsoft.MicrosoftOfficeHub"
    $programs+="Microsoft.MicrosoftSolitaireCollection"
    $programs+="Microsoft.Office.OneNote"
    $programs+="Microsoft.OneConnect"
    $programs+="Microsoft.Print3D"
    $programs+="Microsoft.SkypeApp"
    $programs+="Microsoft.Wallet"
    $programs+="Microsoft.WindowsCommunicationsApps"
    $programs+="Microsoft.WindowsFeedbackHub"
    $programs+="Microsoft.Xbox.TCUI"
    $programs+="Microsoft.XboxApp"
    $programs+="Microsoft.XboxGameOverlay"
    $programs+="Microsoft.XboxGamingOverlay"
    $programs+="Microsoft.XboxIdentityProvider"
    $programs+="Microsoft.XboxSpeechToTextOverlay"
    $programs+="Microsoft.ZuneMusic"
    $programs+="Microsoft.ZuneVideo"
    
    ForEach ($App in $programs){
        $PackageFullName = (Get-AppxPackage $App).PackageFullName
        write-host $PackageFullName
        if($PackageFullName){
            Write-Host "Removing Package: $App"
            remove-AppxPackage -package $PackageFullName -AllUsers
        }
        else{
            Write-Host "Unable to find package: $App"
        }
    }

    Wednesday, May 29, 2019 3:47 PM
  • Update: I verified with Microsoft through our opened ticket and they confirmed to me that effectively, the Remove-AppxPackage cmdlet used with the -AllUsers parameter removes the need to also run Remove-AppxProvisionedPackage -Online. The first cmdlet not only removes the app from the user profiles, but also the provisioned app. Microsoft tested on Windows 10 1903 successfully and told me that they are going to publish an article about it.

    From my side, I tested with Windows 10 1809 and it works perfectly. I did run the SCCM task sequence 20 times in a row on my test computer, it went through every time without any hang, and all the apps are removed as expected.

    Only one problem, when I test the cmdlet Remove-AppxPackage -AllUsers on Windows 10 1803, it does fail every time with 0x80070002 error (file not found). Microsoft told that that it should work, since the -AllUsers parameter was introduced with Windows 10 1803, they are testing now, our case is still opened.

    But at least, we now a viable solution going forward.

    Here's a code sample you may use to validate the behavior on Windows 10 1809 and later:

    $sPackageFullName = (Get-AppxPackage "Microsoft.BingWeather").PackageFullName
    Remove-AppxPackage -Package $sPackageFullName -AllUsers                                                 #This command will fail on Windows 10 1803, successful on Windows 10 1809 and later
    Get-AppxProvisionedPackage -Online                                                                      #This command is just to prove that Bing Weather app is effectively removed and not provisioned anymore
    

    Friday, June 14, 2019 4:58 PM
  • Just to close this thread.

    With Windows 10 1809 and higher, no more need to run the Remove-AppxProvisionedPackage -Online cmdlet, the Remove-AppxPackage -AllUsers cmdlet will remove both the provisioned package and from users. This is confirmed by Microsoft and the support engineer told me that they plan to release a KB article on this. From my side, we have been using a new version of our script using only Remove-AppxPackage -AllUsers and never had any issue.

    For Windows 10 1803, Microsoft told me that you still need to run the Remove-AppxProvisionedPackage -Online cmdlet followed by Remove-AppxPackage -Allusers. Nothing will be done from their side to make Windows 10 1803 behaving like 1809 since this release is already starting to get old; they are already performing minimal support for 1803 until its death scheduled for November 2020.

    So with Windows 10 1803, the intermittent hang issue will still be present with Remove-AppxProvisionedPackage -Online. Recently, I went to another client using Windows 10 1803 and they had the exact same issue, they use Lenovo computers. A way to workaround the issue on this version of Windows is to remove the APPX offline or if you still want to do it online, in your PowerShell script, launch the problematic cmdlet through a Start-Job ScriptBlock to bypass the hang, you may sleep a few seconds after launching the script block. This is not elegant, but so far it did the job for us; it seems that everytime the hang occurs, the APPX is removed, it is just that the PowerShell cmdlet never received the return code from DISM and waits indefinitely. Ex.:

    Start-Job -ScriptBlock {
    
            #We proceed with provisioned application removal
            Try
            {
    
              Remove-AppxProvisionedPackage -Online -PackageName $Using:sProvPackageFullName
    
            }
    
            #Error handling in case of removal failure
            Catch
            {
    
              $sErrorMessage = $_.Exception.Message
    
              $sLogOutput = "Removal of provisioned app $Using:sAppxName failed, error message is : " + $sErrorMessage
              Write-Output $sLogOutput
    
            }
    
          }
    
          #Sleep for 3 seconds
          Start-Sleep -Seconds 3
    
          #Continue with Remove-AppxPackage -AllUsers

    • Marked as answer by Patrick77298 Saturday, October 26, 2019 4:45 AM
    Saturday, October 26, 2019 4:44 AM
  • I am getting

    DismInitialize Failed. Error code = 0x80004005

    CategoryInfo: NotSpecified

    FullyQualifiedErrorId: Microsoft.Dism.Commands.GetAppxProvisionedPacakgeCommand


    I am just running Get-

    appXProvisionedPackage -Online | Select PackageName

    but the issue occurs also when i try to add or remove provisioned packages

    OS Build is : 16299.165

    Version: 1709

    Were anyone able to resolve this issue?

    The Dism.log is created but with 0 KB and no content.

     
    • Edited by AHKH Monday, February 3, 2020 9:09 AM
    Monday, February 3, 2020 9:08 AM
  • In 1909, if I only use Remove-AppxPackaged -AllUsers, the email icon will stay! Adding the Preprovisioned will remove the mail icon. But I am talking about Intune, not sccm.

    With Windows 10 1809 and higher, no more need to run the Remove-AppxProvisionedPackage -Online cmdlet, the Remove-AppxPackage -AllUsers cmdlet will remove both the provisioned package and from users.


    MCSE Mobility 2018. Expert on SCCM, Windows 10, ALOVPN, MBAM.

    Tuesday, February 4, 2020 8:16 AM