Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have wrote a PowerShell script that catches all of the running IIS worker processes on a remote server and returns back diagnostic information (appppolname, cpu, virtual memory etc). It is then converted to HTML and displayed to the user.

$server = Read-Host Enter server name...

if (!(test-connection -computername $server -quiet))
{ 
Write-Host $server is not pingable, does not exist, or timed out. Please try a different server.
}

else 
{
$command = 
{add-pssnapin WebAdministration

function get-iiswp([string]$name="*")
{

   $list = get-process w3wp -ea SilentlyContinue
   if ($error)
   {

Write-Host There are no IIS worker processes currently running. Error Message: $error

   }
        else
        {
            foreach($p in $list)
                { 
                $filter = "Handle='" + $p.Id + "'"
                $wmip = get-WmiObject Win32_Process -filter $filter 

                if($wmip.CommandLine -match "-ap `"(.+)`"")
                    {
                        $appName = $matches[1]
                        $p | add-member NoteProperty AppPoolName $appName
                    }
                }
    $list | where { $_.AppPoolName -like $name }
    }
}

get-iiswp | select-object -property *
}


invoke-command -computername $server -scriptblock $command | ConvertTo-HTML ID, AppPoolName, @{Label="CPU(s)";Expression={if ($_.CPU -ne $()) {$_.CPU.ToString("N")}}}, @{Label="Virtual Memory";Expression={[int]($_.VM/1MB)}}, @{Label="Physical Memory";Expression={[int]($_.WS/1024)}} | Out-file D:/test.html

}

I am looking for a way to format the HTML-output to convert the AppPoolName output of the table into a link where it would use the AppPoolName and PID within the link itself (ex. http://powershell.com/requests.ps1x?PID=$PID&AppPoolName=$AppPoolName

If any one has any thoughts or ideas that could solve and point me in the right direction, it would be much appreciated.

Thanks!

-----------Update-------------------

Here is the example output:

<tr><tr><tr>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML TABLE</title>
</head><body>
<h2>IIS Worker Process Diagnostic</h2>
<table>
<colgroup>
<col/>
<col/>
<col/>
<col/>
<col/>
</colgroup>
<tr><th>ID</th><th>AppPoolName</th><th>CPU(s)</th><th>Virtual Memory</th><th>Physical Memory</th></tr>
<tr><td>3820</td><td>AppPool1</td><td>4.92</td><td>355</td><td>74200</td></tr>
<tr><td>4108</td><td>AppPool2</td><td>0.23</td><td>106</td><td>21380</td></tr>
<tr><td>4940</td><td>AppPool3</td><td>0.20</td><td>590</td><td>39444</td></tr>
<tr><td>7244</td><td>AppPool4</td><td>0.33</td><td>596</td><td>42556</td></tr>
</table>
</body></html>
share|improve this question

1 Answer 1

I think you could replace the AppPoolName (in ConvertTo-HTML) with this...

@{Label="AppPoolName";Expression={ '<a href="http://powershell.com/requests.ps1x?PID=$($_.PID)&AppPoolName=$($_.AppPoolName)">$($_.AppPoolName)</a>' }}

That's just off the top of me head and not tested... :-)

share|improve this answer
    
Hypothetically, you would think that would work. Given this script is executed in the PowerShell ASP (PS1X) it requires you to insert HTML with %> and <%. When I input the HTML link within this parameter it returns the link (although correct) above the HTML converted table. –  gp80586 Sep 23 '11 at 19:53
    
think i understand - could you post examples of script and output? –  Matt Sep 24 '11 at 9:01
    
I posted it above –  gp80586 Sep 26 '11 at 20:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.