Disk Cleanup and the joys of Features-on-demand

Features-on-demand – it’s a great new “feature” – when it works. However, the rest of the time it is a real headache.

A couple of months ago I decided I wanted to trim down the size of my Windows Server 2012 R2 VM’s. Disk Cleanup (cleanmgr.exe) is one tool that I’ve often found really useful to have on a server install, especially when preparing OS VM images to ensure the install is as lean and clean as possible.

However, by default the tool isn’t installed on Windows Server 2012. To get access to Disk Cleanup on a server OS you need to install the Desktop Experience feature:

Install Desktop Experience using Add Roles and Features Wizard

Install Desktop Experience using Add Roles and Features Wizard

Because I had used features-on-demand to remove any disabled packages from the system I received a message telling me I might need to specify an alternate location for the source files:

Specify an Alternate Source path

Specify an Alternate Source path

Anyone who has used features-on-demand should be familiar with this:

Desktop Experience Feature-on-demand removed

Desktop Experience Feature-on-demand removed

Because I haven’t got a GPO restricting my servers from downloading updates and packages from Windows Update I thought I wouldn’t have a problem and didn’t need to specify a source.

I was wrong:

Failed to install the Desktop Exprience

Failed to install the Desktop Experience

That is a bit odd – the server has access to Windows Update – it had downloaded updates earlier that day. Other removed features-on-demand features had been installed on this server without an issue, downloading the source files directly from Windows Update. So I was a little puzzled as to why this was different.

No problem, I thought! All that needs to be done is specify a source. In case this is useful, the following TechNet article covers the different ways of specifying a source when installing features that have been removed:

Configure Features on Demand in Windows Server

There are several different sources that can be provided to the Add Roles and Features Wizard:

  • Specify a WIM file (and index) containing the windows installation files for the OS version that was installed on the server. This is usually a file called install.wim that can be found in the Sources folder of the Windows Server2012R2 installation media.

    Install Feature using a WIM source

    Install Feature using a WIM source

  • Specify the windows folder of a working OS install containing the files for this feature. This is usually done by mapping a drive to a share or by mountingaVHD/VHDx file as a drive to the OS.

    Install Feature using a shared Windows Folder on a machine with the Desktop Experience feature installed

    Install Feature using a shared Windows Folder on a machine with the Desktop Experience feature installed

I tried both of the above methods but neither of them seemed to work for the Desktop Experience feature. The same error occurred every time:

Install-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 source files could not be downloaded.
Use the "source" option to specify the location of the files that are required to restore the feature. For more
information on specifying a source location, see http://go.microsoft.com/fwlink/?LinkId=243077. Error: 0x800f0906

I also tried installing the feature using PowerShell, using no alternative source, using a WIM source and using a Windows folder source:

Install-WindowsFeature -name Desktop-Experience -IncludeAllSubfeature -Restart -Source z:

But each time I received the same error message:

Install Feature with PowerShell and specifing a valid source - failure.

Install Feature with PowerShell and specifying a valid source – failure.

At this point I had all but given up. Luckily I didn’t. I thought I’d give it one last try – but this time instead of using commands from the PowerShell DISM module I’d use DISM.EXE directly:

DISM /online /enable-feature /featurename:DesktopExperience /all /source:z:\

Success! DISM worked!

DISM for the WIN! Back of the net!

DISM for the WIN! Back of the net!

This screenshot and the one above of the PowerShell install-windowsfeature failing to install the feature are from the same machine with the same source mapped.

Z: drive here was mapped to a share of the c:\windows folder of a server that has the Desktop Experience feature correctly installed.

It looks like DISM may operate in a slightly different way to PowerShell DISM Module and the Add Roles and Features Wizard when it comes to installing features.

So, if Add Roles and Features Wizard and PowerShell Install-WindowsFeature fail, try DISM – it might work!

Additional Notes

I have also run into the same problem when installing the AD DS feature on a different server – so I don’t think this is specific to the machine or the feature. It has also occurred on machines that I want to convert from a core install to a gui install.

I have tried installing the feature on a clean install of the OS and it works fine – but as soon as all the latest windows hotfixes for the OS are installed from Windows Update the feature can no longer be installed (if it has been removed).

From my investigation, many other people have experienced this problem with varying degrees of success in solving it. Some have said that patching the WIM file with all the latest hotfixes worked for them – but it didn’t for me (but it did inspire me to write a PowerShell module to ease the WIM patch process – more on this in another post). I was certainly in the “tearing my hair out” group until I randomly tried this.

Also, I did try DISM without specifying a source as well, and it failed with the same error code as the PowerShell did:

Install Feature using DISM fails with no Source specified.

Install Feature using DISM fails with no Source specified.

At first I actually thought the soution was using DISM with the /LimitAccess switch to prevent DISM from using the internet to download the packages, but after further tests it doesn’t seem to make any difference – DISM works with and without this switch. The equivelent to the /LimitAccess switch also doesn’t appear to be available in the PowerShell Install-WindowsFeature cmdlet.


4 thoughts on “Disk Cleanup and the joys of Features-on-demand

  1. Frederik Grøn Schack says:


    I’ve been fighting with the exact same problem and related problems in Server 2012 R2.

    I read somewhere that Microsoft has updated the way their packages are signed and that might be causing the problem.

    I also had better luck with DISM. When I install with DISM, I can uninstall with the Uninstall-WindowsFeature, but can’t reinstall the feature with Install-WindowsFeature, even though the package is available. I think that also points in the direction that it’s something with the signing.

    I further had another problem after working with DISM, installing and uninstilling stuff in a WIM file. The whole directory that I used DISM in got locked down. I’ve been fighting a whole day to delete the folder, taking ownership from TrustedInstaller from all subfolders, but still couldn’t “SHIFT-Delete”, instead I got an “Element not found” error, but I could delete, small portions at a time (normal delete). The stuff in the recycle bin then had the same problem, it said “Element not found” when I tried to delete the content, but in the end they disappeared. The funny part is that the deletion of about 15 GB of data from the recycle bin, didn’t show up as freed space on the harddrive? So I have no clue where that space went.

    I’m new to the server environment, have only been messing with it for a month, but I’ve got a general feeling that Server 2012 isn’t extremely reliable. A lot of things don’t work the way they are supposed to.

    For example I can install a Certificate Authority from the GUI, but not from Powershell with the exact same options:
    Install-AdcsCertificationAuthority -Credential (get-credential) -CAType EnterpriseRootCa -CryptoProviderName “Microsoft Strong Cryptographic Provider” -KeyLength 4096 -HashAlgorithmName MD5 -AllowAdministratorInteraction $true -CACommonName Forsythiavej31-CA -CADistinguishedNameSuffix “DC=Forsythiavej31, DC=local” -ValidityPeriod Years -ValidityPeriodUnits 2

    Communicatoin between domain servers and servers outside the domain seems flaky. I can access a server through a PSSession, but not through the ServerManager where I get an authentication error. I’ve done everything that I’ve read online and nothing works. It seems like when you start building a domain, everything has to go into the domain to work.

    Best regards,


    • Hi Frederik,

      I can feel your pain with some of this stuff. Some features in WS2012R2 require quite a bit of “pushing” to get them working right. But once they’re right they work beautifully. One thing I can recommend is “don’t use features on demand” unless you’re absolutely sure the OS is never going to need to be changed. This is actually not so bad if you’re intending for your OS’s to be disposable (e.g. it breaks or you need a change then reinstall). But this is far more difficult with core infrastructure (like DC’s and CA’s).

      What I generally do when setting up a Lab or new WS 2012 R2 environment is take the basic WS2012R2 ISO, install a clean image with it. Then completely patch it up as far as it will go. Then I’ll sysprep it and keep that as my base image from then on in. You’ll have a lot more luck with an image with all the latest patches with it.

      And looking at your ADCS PS command, that looks like it would work – I can’t see any problems with that (I write the ADCSDeployment DSC Resource for the DSC Resource kit so I’ve got a fair bit of experience with ADCS deploys). Do you by any chance get an error?

      You’re right about the comms between Server Manager and other non-Domain computers – this can be tough to configure. But it usually just comes down to either Firewall or Authorization. But if you’re entering a Username/Password combo the server to manage, make sure you’re specifying the “MachineName/Username” format.

      Sorry I can’t be of more help!


      • Frederik Grøn Schack says:

        Hi Daniel,

        Thanks for your quick reply.

        Well, I like to solve problems, so I think I’ve stumbled on the right thing here 😀 It doesn’t give me a whole lot of pain, but sometimes it’s hard to make sens of. When there is no authentication errors with PS Remoting, but authentication errors from Server Manager? It’s hard for me to make sense of and I’ve been typing those credentials many times and very carefully, to be sure. I tried with computer name, I tried with IP-address, put down the firewall and stuff like that.

        I do appreciate a lot of Server 2012’s qualities. I love Powershell, this is one thing I think Microsoft hit bulls eye with. It has structural integrity, it’s extremely generic and very powerfull, especially with DSC. But I’m also learning where not to tread 🙂

        Best regards,


Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s