Sunday, May 30, 2010

Sample of Powershell usage for displaying in IE

$oIE=new-object -com internetexplorer.application
while ($oIE.busy) {
    sleep -milliseconds 50
$procList=ps |select-object ProcessName,Handles,NPM,PM,WS,VM,CPU,Id |convertto-html

$oDocBody=$oIE.document.documentelement.lastchild ;

#populate the document.body

$"12pt Arial";

#Reading back from IE.
$oTBody=@($oIE.document.getElementsByTagName("TBODY"))[0] ;
foreach ($oRow in $oTBody.childNodes) 
   #check the 4 column(WS),and highlight it if it is greater than 5MB.
   $WS=(@($oRow.childNodes)[4].innerhtml) -as [int]  ;
   if (($ws -ne $null) -and ($WS -ge 5mb)) {
       $oRow.bgColor="#AAAAAA" ;

#Prepare a title.

$"bold 20pt Arial"
$oTitle.innerhtml="Process List";
$oTitle.align="center" ;

#Display the title before the Table object.
$oTable=@($oIE.document.getElementsByTagName("TABLE"))[0] ;
$oDocBody.insertBefore($oTitle,$oTable) > $null;

No comments: