Quantcast
Channel: Randy Riness @ SPSCC aggregator
Viewing all articles
Browse latest Browse all 3015

MSDN Blogs: Query the active worker process information in IIS 7.X using Powershell

$
0
0

 

Recently I worked with one of the customer, who wanted assistance in displaying the Process-Id, Application Pool Name and the Request StartTime of the IIS Worker Process (w3wp.exe) in IIS 7.X and higher through Powershell.

This blog includes the script which will serve the customer’s above requirement.

Pre-Requisites for running the below script:

1. We need IIS 7.X and higher version installed on the WebServer along with the IIS Management Scripts and Tools Feature        installed. This feature is needed to gain access to the root/WebAdministration namespace which we use to query the         IIS related information.

clip_image001

2. We need the Powershell to run the script.

3. Make sure that you are an Administrator on the Server where you will be running this script.

How to run the script:

1. You can modify the below script as per your environment and place it a file with extension .ps1 and run it through elevated powershell window.

2. Alternatively, You can also run the script through PowerShell ISE.

Using the Code:

 

# Ensure to import the WebAdministration module

Import-ModuleWebAdministration

# Declare the variables

$server="localhost"

$search="*"

$wmiQuery=[wmisearcher]"SELECT * FROM __Namespace where NAME like 'WebAdministration' or NAME like 'MicrosoftIISv2'"

$wmiQuery.Scope.Path ="\\"+$server+"\root"

$WebNamespace=$wmiQuery.Get()

# Checking if the the server has IIS installed

if($WebNamespace-like'*WebAdministration*')

{

    "IIS  found on $server"

    $WPlist=Get-WmiObject-NameSpace'root\WebAdministration'-class'WorkerProcess'-ComputerName'LocalHost'

    # Loop through the list of active IIS Worker Processes w3wp.exe and fetch the PID, AppPool Name and the startTime

    forEach ($WPin$WPlist)

    {

        if ($WP.apppoolname -like$search)

        {

           write-host"Found:""PID:"$WP.processid  "AppPool_Name:"$WP.apppoolname
             (get-process-ID$WP.processid|selectstarttime)

        }

    }

}

Else

{

   write-host"WARNING: IIS not detected."

}

 


Viewing all articles
Browse latest Browse all 3015

Trending Articles