Posts
47
Comments
55
Trackbacks
0
And these are some of my favorite scripts… Part 1
I'm starting a new series that showcase different features of PowerShell and Exchange by posting scripts first and then letting you (the readers) figure out what the script does. I'll update the post with an explanation of the scripts after some time, but first, use the comments to post your solutions / questions / complaints :) The idea is to first a) get people to learn how to read scripts and then b) learn how to write them. As a side effect, there will be some new scripts out there for you to use (some will be just generic PowerShell and some Exchange specifc)  To kick things off,  here is a script that uses begin/end/process blocks and hashes to do something useful. Can you guess what it does? param($property=$null)begin {  $script:hash = @{} } process {  if(($script:property) -and ( $_.$script:property ))  {   $obj = ($_ | select-object $script:property).$script:property  }  else  {   $obj = $_   $script:property = "Name"  }  if( $script:hash.$obj -eq $null )  {   $script:hash.$obj = @(1, $_);  }  else  {   $script:hash.$obj[0]++  } } end {  foreach($key in $script:hash.keys | sort)  {   $result = new-object System.Management.Automation.PsObject   add-member -input $Result -type Note* -Name Input -value $script:hash.$Key[1]   add-member -input $Result -type Note* -Name $script:property -value $Key   add-member -input $Result -type Note* -Name Count -value $script:hash.$Key[0]   write-output $result  } }

posted on Tuesday, November 30, 1999 12:11 AM Print
Comments
No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 8 and 5 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!