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
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.
NOw that I have my process’s like the name w3wp I can now just get the time from creation date like this:
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