Search code examples
powershelliisserverautomationadministrator

How to enable expire web content in IIS using powershell


I'm doing automation for server setup using powershell script. I want to enable the expire web content and set it to After and value should be set to 1 DAY

enter image description here


Solution

  • Here are the powershell script.

    Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/staticContent/clientCache" -name "cacheControlMode" -value "UseMaxAge"
    
    Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/staticContent/clientCache" -name "cacheControlMaxAge" -value "1.00:00:00"