Iis – Logging when ApplicationPool is started/stopped via Powershell

application-poolsiisloggingpowershell

I use a Powershell script to, among other things, start and stop an IIS Application Pool via the following commands:

Stop-WebAppPool -Name $appPoolName;
Stop-WebAppPool -Name $appPoolName;

Is there a log file from IIS where the event, that is starting and stopping of an Application Pool, is logged?

As suggested here, I have already looked in the Event Viewer under System, but did not find anything.

I also know that the logging of Recycling can be configured in detail at the Advanced Settings of the respective Application Pool in IIS, but I am not sure if this applies to starting/stopping, because actually I am not recycling.

Best Answer

As long as you have IIS 7.5 or newer (see the note at the bottom), you can enable additional logging.

In Event Viewer, expand the "Application and Services Logs" section. Then expand "Microsoft, then "Windows". Then expand "IIS-Configuration, right-click on "Operational", and choose "Enable Log".

Now this log will receive events whenever an application pool is stopped or started via the IIS Management GUI. In my limited testing, it doesn't seem to log an event when the Powershell Stop-WebAppPool and Start-WebAppPool commands are used. So, to get both GUI-generated Stop/Start events, and Powershell generated ones, you'll need to add lines to your Powershell script to write to that event log.

(Note: 6.2 is probably the version of the IIS Manager tool that you are using, and/or the internal version number of Windows. Windows Server 2012 R2 comes with version 8.5 of IIS.)