Start Date for IIS AppPool


Being that IIS is an important part of what I do. I had to verify that the Application pool for my sites were actually being restarted during my automation.    With that in mind I needed to find the time that the application pool last started.  So my quest became how do I figure out when that application pool last restarted.

My first thought was to import the webadministration module and then look at the application pool in the IIS provider.

PS c:\Import-module Webaministration

PS c:\cd IIS:\AppPools

PS IIS:\AppPools>> (gi .\DefaultAppPool\WorkerProcesses) | get-member

This resulted in the following

2016-02-06 11_50_33-Start

Unfortunately I cannot seem to find a method that has the start or Date of any sort in the member properties for my application pool in question.

So I resorted to using CIM. Using the Class called Win32_proces I can find the name of the process and the creation date.  Now since IIS always starts the starts the same process I need to pay attention to the -ap value in the command line.

iis

NOw that I have my process’s like the name w3wp I can now just get the time from creation date like this:

iis2

Now to formulate this into a nice function:

function Get-WebApppoolstatus
{
param
(
[Object]
$pool
)
$poolReturn = $NULL
$poolStatus = Get-ciminstance -classname win32_process -filter "Name like '%w3wp%'" | Select-Object name, Processid, commandline, creationdate
foreach($status in $poolStatus)
{
if(($status.commandline) -like "*$pool*" -and ($pool -ne $null))
{
$poolReturn = $status
}
}
return $poolReturn
}

Github Gist Location for this script

Until then Keep scripting

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s