Powershell script which Enables Recycle event logging and disable the Recycle on configuration change setting for application pool in IIS

Introduction

The sample powershell script will help in enabling the Recycle event logging and disable the Recycle on configuration change setting for application pools in IIS.

Running the Sample

Step1: Open the PSIISEnableRecycleLogs.ps1 in Administrator mode from the Powershell ISE.
Step2: Make sure you have the Administrative priviledges on all the IIS webservers.
Step3: Then execute the powershell script from Powershell ISE

Using the Code

The following code snippet is the sample of Script that serves the above requirement

Firstly import the web administration module

PowerShell
Edit|Remove
Import-Module WebAdministration

The below script can be used to enable the Recycle event logging and disable the Recycle on configuration change setting for application pools

PowerShell
Edit|Remove
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/applicationPools/add[@name='MyAppPool']/recycling" -name "disallowRotationOnConfigChange" -value "False" 
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/applicationPools/add[@name='MyAppPool']/recycling" -name "logEventOnRecycle" -value "Time,Requests,Schedule,Memory,IsapiUnhealthy,OnDemand,ConfigChange,PrivateMemory"

More Information

The following article will provide a few cmdlets which are available for the IIS:
http://technet.microsoft.com/en-us/library/ee790599.aspx  

Microsoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.