Posts
49
Comments
83
Trackbacks
0
Technet Webcast follow-up (out-html, out-ie)

Thanks to all the cool folks who attended today's webcast: Exchange Server 2007 Management Shell and Scripting (Level 300). As promised, here are the scripts I used. I first saw Out-IE used by the awesome Jim Truher. I wrote it recently when one of my colleagues asked if we there was a way to pop-up html pages without calling IE manually. Here it is:

$ie = new-object -com InternetExplorer.Application
$ie.navigate("about:blank")
while ($ie.busy) { sleep 1 }
$ie.visible = $true
$ie.document.write("$input")
# if above line doesn't work on your system, uncomment line below
# $ie.document.IHTMLDocument2_write("$input")
$ie

Put the lines above in a msh/ps1 file and run it (example below)! As for Out-HTML, there actually is a cmdlet built into PowerShell/Monad called "ConvertTo-Html". I wrote Out-HTML to kind of prove the point that you can have generic scripts for creating reports.

It additionally has two features that CovertTo-HTML does not have: 1) it shows you what cmd you ran to create the report (super handy if you create a report and then forget what you did to create it :) and 2) it handles different object outputs a little differently so that it makes reports easier to read. Its a little prettier too. Here it is.

To run the script, rename it out-html.msh (Exchange/RC0) or out-html.ps1 (PowerShell RC1) and place it somewhere in your PATH (or alternatively give the full path to the script when running it). Example:

get-childitem | select Name,Length | out-html > foo.html get-childitem | select Name,Length | out-html | out-ie

Please feel free to show off your customizations to the scripts above or just reuse them as is. I'd love to see what kind of cool Exchange reporting tricks people will come up with. Oh, and if you still have unanswered questions after the webcast, feel free to leave a comment or trackback.

posted on Tuesday, May 09, 2006 8:05 PM Print
Comments
Gravatar
# 
Martin Pavlis (MVP)
5/15/2006 4:05 AM
  
Could you please do me a favor? Your PPT is not accesible on MS Technet Webcast page - it looks like URL error. Is there any other possibility how to get this presentation? Or, could you please send me it by email? Thanks a lot!
Gravatar
# 
Joey Washburn
5/10/2006 7:05 AM
  
How do I use your out-html? I am new to scripting and stumbled on to this.

Here is the script I have now and it works but the output is ugly

Get-wmiobject -class Exchange_Mailbox -Namespace ROOT\MicrosoftExchangev2 -ComputerName SERVER | select-object MailboxDisplayName,TotalItems,Size | sort -descending "Size" | convertto-html -Title "Mailbox Sizes" | out-file test.html
Gravatar
# 
Joey Washburn
5/11/2006 10:05 AM
  
It worked great. Thanks. I added to out-html Web Page Title so that I can put a title on the page and I have made three or four variations so that I can call them as needed. How would I make it a variable similiar to the converttothml -Title functionality?
Gravatar
# 
Joey Washburn
5/11/2006 11:05 AM
  
I have another question. Is it in the realm of possibility to color table rows Red if they are larger than X amount, yellow if they are between X and y and green for the rest? Would that be a change to your out-html or would it be in the orginal script?
Gravatar
# 
vivek
5/16/2006 7:05 PM
  
I asked the technet folks to look into the link. Apparently there were some delay/issues with posting PPTs last week.
Gravatar
# 
brian
8/25/2006 4:08 AM
  
It was good speaking to you at the Air Lift, I am looking for a monad scipt/command that will allow me to sort user on e2k3 by size then move either the top or bottom X number of users. I am not to good with the commands yet, any help
Gravatar
# 
Lance
11/8/2006 12:11 PM
  
I had to change a few lines of out-html to make it work. On lines 48 and 58 I changed the string to use \
Gravatar
# 
Henrik Walther
7/22/2006 12:07 PM
  
Vivek quick question.

Does EMS read the path under environment variables doing startup, or do I specify the path to let's say c:\scripts (where out-html.msh and out-ie.msh are located) another place?
Gravatar
# 
John Smith
12/27/2006 7:12 PM
  
Can anyone explain why $ie.document.write doesn\'t work for me. It throws a \'Type mismatch\' error everytime.

I have been scripting InternetExplorer.Application for many years. Calling it (especially IE7) from PowerShell gobbles up tonnes of memory that are not released. There is no programmatic way of shutting down that IE instance. I always have to kill it manually. Once when I killed the instance, 170MB of memory was released.

Is there a proper way to clean up?
Gravatar
# 
Jewelry
8/24/2007 1:08 AM
  
Thanks for the info guys. I really learned a lot from here. Keep it commin.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 5 and 4 and type the answer here:
News
A little slow these days as I'm busy working on exchangelabs.com. I will try and post tidbits when I get some time. Enjoy the older posts till then!