Thursday, February 27, 2014

Everyday Powershell Returns! - Find exchange mailbox size

Fresh from an ass kicking at the Winter Scripting games we're back with another useful bit of Powershell!

We're building our Exchange 2013 environment now and have a burning need to see what our users mailboxes look like, in terms of the space they consume.

This little script did the trick for us and helped us plan our new information store layout.

Add-PSSnapin *exchange*

$users = Get-ADUser -searchbase "DC=somedomain,DC=com" -Filter * -Properties department

$report = @()
$count = $users.count
$i = 0
foreach ($user in $users)
{
    $i++
    $prog = ($i/$count* 100
    Write-Progress -Activity "Processing..." -percentcomplete $prog -CurrentOperation $user.samaccountname 
    $temp = ""| select Person, mailboxsize, itemcount, Team, Function
    $mailboxstats = Get-MailboxStatistics $user.samaccountname
    $temp.person = $user.samaccountname
    $temp.mailboxsize = $mailboxstats.totalitemsize.value.toMB()
    $temp.itemcount = $mailboxstats.itemcount
    $temp.team = $user.department
    $report += $temp
}
$report

Should be pretty self explanatory. Ask a question in the comments if you'd like clarification of anything. 

Wednesday, February 12, 2014

What I learnt at the Winter Scripting Games - Part 4

Great news!

We scored in the positives for event 2! Even got some good feeback from the judges. Great work Team Awesome...

Bad news!

We didn't get anything submitted for event 3. Missed an opportunity to capitalize on what we've learnt so far. Still there's event 4 to come.

We did get a decent function together for setting ACLs so event 3 wasn't a total write off.

For us it's more about have fun leaning challenges than the score anyway.

Wednesday, February 5, 2014

What I learned at the Winter Scripting Games - Part 3 - The Importance of Help

That’s what we learnt in event 1 of the scripting games. Our team of enthusiastic novices threw together a script that we thought met most of the requirements. It wasn't pretty and didn't include any comments or help.

Once the scoring was done we came out a -4. MINUS FOUR! Ouch.

Looking at the scoring criteria it became clear why. Much of the scoring seems to be around building the right kinds of good practice into your script.
We lost points on;
  • Appropriate use of Try/Catch
  • Appropriate use of verbose output including -Verbose support
  • Correct management of pipeline input
  • Appropriate use of parameter validation attributes
  • Comment- or file-based help
  • File names include date of production
  • Code shared between solutions
This is all pretty simple stuff that could almost be built into a script “template”. We’ll be working on that for future Events.

 So what we've learned is that the logic in your script isn't the best way to score points. I was pretty happy with our solution, give that it was produced by 3 novice scripters. OK 2 novices and me… A ‘Senior Novice’.


It was a great learning experience and the emotional kick of scoring NEGATIVE points made it clear how valuable it is to build this good practice stuff into our scripts.