Posts
49
Comments
83
Trackbacks
0
May 2006 Entries
TechEd 2006: Boston. Be there or be rectangular.
I hope to see you in Boston--my session will be MSG324: Exchange 2007 Management Scripting and Shell (I believe the session is at 4:00 on the 13th, but times may change so be sure to check). Oh yeah, and I'm supposed to put this sticker on my blog. See you there!

 

posted @ Wednesday, May 24, 2006 9:05 PM | Feedback (0)
How to 2007: Setting the Journal Recipient in Exchange 2007

Whenever I do a webcast or presentation, I try to use examples which are immediately useable. Sometimes its tough to get a pulse on what are the frequent things that people do with Exchange, so I've been looking at what the community has written scripts for in 2003 and converting them to the equivalent in 2007. I hope that a) this will provide a "bootstrap" so you have some snippets to use immediately and b) that this will show you that cmdline/scripting in 2007 is much easier (you don't have to be afraid to learn about it or use it). Here's a good example to kick this effort off: Glen put an excellent script solution to setting the journal recipient in Exchange 2003. As you can see, CDOEXM lets you do it, but its a little complex. Here is the equivalent in Exchange 2007:

set-MailboxDatabase servername\mdbname -JournalRecipient domain\username

And no I'm not lying, that's really what it is. Is the above statement a "script"? Technically yes, but its so much simpler! Not only that, its much more powerful. Let's say you want to set the journal recipient on ALL your mailbox databases:

get-MailboxDatabase | set-MailboxDatabase -JournalRecipient domain\username

How about setting the journal recipient on all mailbox databases on a particular server?

get-MailboxDatabase -server MyServer | set-MailboxDatabase -JournalRecipient domain\username

And if you get a little nervous with this new fangled tool (sometimes I do too!), you can check what a command is going to do before actually running the command (whoa) by running whatif:

set-MailboxDatabase servername\mdbname -JournalRecipient domain\username -whatif

So don't be scared by the cmdline. Its easy once you learn a few basic concepts (verb-noun naming convention, how to pipeline and how to pass parameters) and is likely to save you lots of time and effort. Finally, let's compare the # of lines it took to do this in CDOEXM vs. PowerShell/Monad (using the first example given above):

CDOEXM:

Lines      : 43
Words      : 173
Characters : 1643

PowerShell/Monad:

Lines      : 1
Words      : 4
Characters : 72
 

posted @ Saturday, May 20, 2006 5:05 AM | Feedback (0)
Tweak master flash (or how you can tweak community scripts too)

Joey asked a cool question on my last post on out-html: what if you wanted to colorize the output of out-html so that some rows/values were colored differently based on a criteria?

I can think of a couple of different ways to handle this, and it certainly is a nice hack. But rather than building the solution, I'll post some hints and see if the community can pull some nice stuff together :). Here are some ideas: Since the goal is to color values in any given column/row a given color based on a certain criteria, why not parameterize this as a function of the input? In simpler terms, why not let the user pass in a "rule" on how out-html should color things?

To be even more specific: add a parameter (or more than one parameter) to the script that takes a color value, a criteria which when evaluated to true will apply that color, and finally a property to which the color/criteria should apply. Here's a usage pattern:

get-mailboxstatistics | out-html -property ItemCount -criteria { $prop -lt 100 } -color "Green"

Some further things to hack: how would you add support for more than one propertr and more than one criteria? Ok, so that's one approach. How about an approach which focuses on the input before it gets to out-html? Imagine a pre-processer to out-html:

get-mailboxstatistics | apply-colors | out-html

This function in the middle would output basically the same thing as get-mailboxstatistics except it would add the appropriate formatting to values that you care about. The downside of this approach might be that the function is tied to a particular input data set. But you could combine approaches #1 and #2 to come up with some common ground. So there are some ideas on how to do this.

As usual, I'm probably complicating things too much, so if you have a simpler solution... go for it and show us how its done :) If I get some more time to tweak I'll see if I can cook up a version of out-html that supports custom coloring. Till then, happy hacking!

posted @ Thursday, May 11, 2006 10:05 PM | Feedback (2)
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 @ Tuesday, May 09, 2006 8:05 PM | Feedback (10)
Get-Mailbox, the most popular cmdlet

I just noticed that I use Get-Mailbox everywhere in my examples. Why is that? I suppose its because this a) Exchange is all about Mailboxes (if you didn't know, Exchange is an e-mail / collaboration server) and b) its so easy to use. The basic pattern for Get-Mailbox is below:  

Get-Mailbox

If you just run this, the cmdlet will return upto 1000 mailbox enabled users. Why 1000? Well we have to cap our results somewhere, as if we returned everything, very large amounts of data would be returned. Small companies will never notice. Large companies can do:

Get-Mailbox -resultsize 99999

Or whatever number of results they want returned. The cool thing is that you can also do:

Get-Mailbox -resultsize Unlimited

Which returns all mailboxes. BTW: This same pattern can be applied to all the other recipient cmdlets as well as queue viewer cmdlets. So what else can get-mailbox cmdlet do? A lot. The next simplest example is to get one particular user:

Get-Mailbox domain\username
Get-Mailbox username 
Get-Mailbox user@foo.com
Get-Mailbox -identity username

You'll note that many different formats are accepted (in fact, you can pass in GUIDs and DNs too!). The 2nd important thing to note is that -identity is a positional parameter. Positional means that if you omit -identity on the cmdline, the first token is assumed to be the argument to -identity. In simple words, it saves you some typing. For example: ever wanted to get all the mailboxes that reside on a particular mailbox database? There you go:  

Get-Mailbox -database Get-Mailbox -database server1\sg2\mdb1

Note the format that I passed into -database: server\storagegroup\mdb. You can also pass in just the name, we will try and match it against all databases on the local server, if none are found, we'll let you know. Much better than passing DNs or GUIDs around.  But wait, what if you wanted to see all mailboxes that reside on a particular server?  

Get-Mailbox -server server1

Well that's all good, but what if you wanted to find some user based on some more complex query? That's why we have the -filter option:

Get-Mailbox -filter { Name -like '*vivek*' -and Company -eq 'viveksharma.com'  }

This is called server side filtering. The recipient cmdlets and the queue cmdlets support this concept. Basically it takes the query you specify and only returns those results. Note, in Monad you can always do client side filtering on any object even in the cmdlet does not support any advanced filtering. The moral equivalent to the previous cmd in client side filtering terms is:

Get-Mailbox | where { $_.Name -like '*vivek' -and $_.Company -eq 'viveksharma.com' }

Not much different is it? Server side filtering is useful for cmdlets that return a large set of data, but in general we rely on client side filtering to do much of the work in Exchange. Ok, one last freebie, after this I will have to charge. Just kidding of course. We optimized some cases just for you:

Get-Mailbox *vivek*

That will run a server side wildcard search across all mailbox user names (and smtp addresses too). So you can do things like this:

Get-Mailbox *vivek* | format-table Name,*quota*

Which will get all the mailboxes that have 'vivek' in their name and show you table output with their name, and various quota sizes. Now show me the vbscript equivalent of that!

posted @ Thursday, May 04, 2006 10:05 PM | Feedback (4)
A simple version of Top or How to monitor data in a Monad session
In the cmdline, sometimes its handy to have a console open in the background just for monitoring some data. For example, in my Unix admin days, I used to use top to monitor what was going on in the system. In Monad/PowerShell, I use this little hack: param(    [scriptblock]$command=$(throw "A script block is required..."),    $timer=5 ) while ($true) {    clear-host    &$command | format-table    start-sleep $timer > $null } You can run this by doing: topit { }. For example, this is how you would use this trick to monitor how many users are logged on to the current server: topit { get-logonstatistics } -timer 10  The cool thing about this is that it works against any cmd in the world! Huzzah! (I can't believe I just said "huzzah").
posted @ Wednesday, May 03, 2006 8:05 PM | Feedback (1)
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!