Add-WindowsFeature Error: 0x800f0902 – The operation cannot be completed because Windows is currently performing another servicing operation

Today I encountered a problem, for which I couldn’t find a solution (which is pretty rare), so thought I’d post a blog about it and maybe someone can help me.

I sometimes have a problem with the Add-WindowsFeature. In powershell, overall it works fine, but sometimes it gives me the following error:

Add-WindowsFeature: The request to add or remove features on the specified server failed.

Installation of one or more roles, role services, or features failed.

The operation cannot be completed because Windows is currently performing another servicing operation.

Wait a few minutes and try running the command again. Error: 0x800f0902

At line:1 char:1

+ Add-WindowsFeature NET-Framework-Features,NET-Framework-Core,NET-Framework-45-Fe…

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (@{Vhd=;Credent…Name=localhost}:PSObject) [Install-WindowsFeature],    Exception

    + FullyQualifiedErrorId : DISMAPI_Error__Failed_To_Enable_Updates,Microsoft.Windows.ServerManager.Commands.AddWindowsFeatureCommand

It seems that either the System Center Endpoint Protection (update and/or scan) or the Automatic Maintenance (in the Action center) causes the Add-WindowsFeature to fail (not sure which of the two yet).

Edit: I could localize the problem to be the Automatic Maintenance (in the Action Center). Is there a way to pause or disable this during the running of my Powershell script? Or at least is there a check if it is active or not? So I can check that and wait with installing the Windows Feature until automatic maintenance is finished.

Edit: I found the solution by checking the information MS has about the Automatic Maintenance as described at MSDN on , which led me to the task scheduler.

Get-ScheduledTask | Where TaskPath -like "*TaskScheduler*"
Led me to show all possible automatic maintenance tasks. Since I don’t want to disable or delete the task, I got several options. Two of which will follow.

– I can stop all running instances by using the following code:
Get-ScheduledTask | Where TaskPath -like "*TaskScheduler*" | Stop-ScheduledTask

– I can wait until maintenance tasks are finished and then continue with my code:

$CheckIfMaintenanceIsRunning = $true
$RunningTasks = Get-ScheduledTask | Where TaskPath -like "*TaskScheduler*" | Where State -eq "Running"
Start-Sleep -Seconds 5
$CheckIfMaintenanceIsRunning = $True
$CheckIfMaintenanceIsRunning = $false

Since in my case the probability of maintenance running while I execute my script is pretty low and also shouldn’t take too long to finish and the fact that I will run my code on systems owned and maintained by other system administrators, I will choose the wait option.


Edit: as _Emin_ stated in the comments, it is better to use

Get-ScheduledTask -TaskPath *TaskScheduler*

Thus the corresponding code above would become:

Get-ScheduledTask -TaskPath *TaskScheduler* | Stop-ScheduledTask


$RunningTasks = Get-ScheduledTask -TaskPath *TaskScheduler*| Where State -eq "Running"


Tags: , , ,

2 responses to “Add-WindowsFeature Error: 0x800f0902 – The operation cannot be completed because Windows is currently performing another servicing operation”

  1. _Emin_ says :


    Do you know you can filter from the left (considered as a best practice) and that taskpath accepts wildcards

    Get-ScheduledTask -TaskPath *TaskScheduler*


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: