How can I turn on DynamicCompression feature of IIS programmatically?

http-compression, iis-7, iis-7.5, server-configuration, windows-7

Solution

This is the way I would have done it:

dism /online /enable-feature /featurename:IIS-HttpCompressionDynamic

dism allows you to check the return code of command, allowing you to verify that it worked (or was already installed)

Problem

I'm making an installer program for my web application. My web application uses CSS and JS heavily, so I want to enable both Static and Dynamic HttpCompression for IIS7/7.5. It needs 2 steps: - I can modified the `web.config`, put `<httpcompression>` tag, it's ok. - DynamicContentCompression must be turned on in Windows Feature to make httpCompression work. Static HttpCompression is enable by default in IIS7 and IIS7.5, but Dynamic HttpCompression is not enable by default (although it's available). I can do manually by turn on: `Start/ControlPanel/ProgramsAndFeatures/TurnWindowsFeatures on or Off/IIS/WWW Service/Performance features/Dynamic Content Compression`, but How can I programmatically turn it on that Windows Feature? I can use PowerShell, C# in my installer. Any idea how I might be able to do this? Thanks.

Original source