Enumerating Sharing Permissions via EWS Managed API in PowerShell

The following PowerShell script enumerates the sharing DACLS on the Inbox and Calendar of the user under whom the script is running.  I’ve not yet attempted to enumerate the permissions for a different user. I included the “$perms[$i].UserID | fl *” line to illustrate why I use an IF-THEN construct.  The default permission throws an odd wrinkle into the mix.


#---------------------------------- ews_get_perms.ps1 ------------------------
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.0\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFile($dllpath)

$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)
$uri=[system.URI] " https://YOUR.EWS.FQDN/ews/exchange.asmx"
$service.Url = $uri

$inbox= [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)

$perms = $inbox.permissions

"`nPermissions on Inbox:"

for ($i=0;$i -le ($perms.Count - 1);$i++) {
if ($perms[$i].UserId.DisplayName -eq $null) {$user=$perms[$i].UserId.StandardUser}
Else {$user=$perms[$i].UserId.DisplayName}
$perms[$i].UserID |fl *
"User : $user"
"CanCreateItems : $($perms[$i].CanCreateItems)"
"CanCreateSubFolder : $($perms[$i].CanCreateSubFolders)"
"IsFolderOwner : $($perms[$i].IsFolderOwner)"
"IsFolderVisible : $($perms[$i].IsFolderVisible)"
"IsFolderContact : $($perms[$i].IsFolderContact)"
"EditItems : $($perms[$i].EditItems)"
"DeleteItems : $($perms[$i].DeleteItems)"
"ReadItems : $($perms[$i].ReadItems)"
"PermissionLevel : $($perms[$i].PermissionLevel)"
"DisplayPermissionLevel : $($perms[$i].DisplayPermissionLevel)"
"-----------------------------------------------"
}

$cal=[Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar)

$perms = $cal.permissions

"`nPermissions on Calendar:"

for ($i=0;$i -le ($perms.Count - 1);$i++) {
if ($perms[$i].UserId.DisplayName -eq $null) {$user=$perms[$i].UserId.StandardUser}
Else {$user=$perms[$i].UserId.DisplayName}
$perms[$i].UserID | fl *
"User : $user"
"CanCreateItems : $($perms[$i].CanCreateItems)"
"CanCreateSubFolder : $($perms[$i].CanCreateSubFolders)"
"IsFolderOwner : $($perms[$i].IsFolderOwner)"
"IsFolderVisible : $($perms[$i].IsFolderVisible)"
"IsFolderContact : $($perms[$i].IsFolderContact)"
"EditItems : $($perms[$i].EditItems)"
"DeleteItems : $($perms[$i].DeleteItems)"
"ReadItems : $($perms[$i].ReadItems)"
"PermissionLevel : $($perms[$i].PermissionLevel)"
"DisplayPermissionLevel : $($perms[$i].DisplayPermissionLevel)"
"-----------------------------------------------"

Misleading NDR Notifications

Background: About a month ago, we ran into a peculiar situation where store.exe on one of our mailbox servers was repeatedly crashing, with Event ID 9673 being generated in the Application Event Log from MSExchangeIS.  Per KnowledgeBase article 959135, the appropriate fix for this was to apply the recently-released Rollup 7 for Exchange 2007 SP1.  That didn’t fix the issue, but instead the crash rate increased.  After a marathon consultation with Microsoft Premier Support, we discovered that, in addition to the installation of the rollup, it was necessary to create a registry key called “Search Folder Nesting Level” in HKLM\System\CCS\Services\MSExchangeIS\ParamtersSystem and set it to a value of 10 (down from its default value of 20). At the time of the incident, the need for this registry setting was not yet mentioned in the KB article.

Continue reading

Using the EWS Managed API via PowerShell

As part of the rollout of the Exchange 2010 beta, Microsoft has released a beta API library for working with Exchange Web Services which can also be used in conjunction with an Exchange 2007 server. As with any .NET library, this can be invoked from PowerShell. There is an example here of retrieving the number of unread messages in the Inbox, as well as some attributes from the last message received. Unfortunately, the API documentation doesn’t give PowerShell examples, so figuring out how to invoke the calls requires a bit of trial and error. Here is a script I cobbled together which simply sends an email message:
Continue reading

Fun With Custom PSObjects

I was recently asked to generate a report on mailbox usage by a specific subset of AEMS users.  The tricky part is that the various pieces of info that I need are returned by two distinct Exchange Management Shell commands.  In order to merge properties from two different returned objects, I found it expedient to tack the values from those properties into a new PSObject:

#initializing an array to hold the constructed PSObjects
[array]$users = $null          

#  iterate through all members of myGroup
Get-DistributionGroupMember “myGroup” | ForEach-Object {    
# some info needed from Get-Mailbox
$mb=get-mailbox  $_.samaccountname    
# some from Get-MailboxStatistics
$mbstats = get-mailboxstatistics $_.samaccountname   

# create PSObject into which we will merge results
$user = New-Object PSObject   

# Now we add the desired properties into the PSObject
$user | Add-Member NoteProperty Name $mb.DisplayName
$user | Add-Member NoteProperty Usage $mbstats.TotalItemSize.Value.ToMB() 
$user | Add-Member NoteProperty Quota $mb.ProhibitSendQuota
$user | Add-Member NoteProperty Account $mb.SamAccountName 

# skipping users for whom no data is returned because they’ve never logged in
if ($mb.DisplayName -ne $NULL){$users += $user}

}

# Now, export the report as a CSV file:
$users | export-csv -path .\myGroup-Users.csv

E14 Officially Goes Beta as Exchange 2010

The MS Exchange Team Blog has spilled the beans.  Biggest change (other than cross-browser support for OWA Premium) is the discontinuation of support for Single Copy Clustering (SCC). Other big changes include online mailbox moves, user-initiated message tracking, and elimination of storage groups.

InfoWorld has a nice overview.
The official MS site is here.
TechNet documentation is here.
MSDN docs are here.

PowerShell Training

The folks at Microsoft have made it pretty clear that they regard PowerShell (the scripting language formerly known as “monad”) as the future for managing their server products. Exchange 2007 was just the first wave, with the latest versions of SharePoint and SQL quickly following suite.  When Windows Server 2008 R2 is released, it will be accompanied by PowerShell v2.0, which will include a whole new batch of AD management cmdlets (including one for un-deleting AD objects – yeah!), as well as a PSDrive provider which will allow the Active Directory to be accessed from PowerShell as if it were a filesystem.

Last week, I and several of my collegues had the good fortune to attend a PowerShell training class.  Although I’ve been using PowerShell now for over a year to manage Exchange 2007, the class did provide a good opportunity to bone up on the fundamentals, and even helped me clear up some misconceptions that I had about how certain commands work. (ForEach and ForEach-Object are different commands?  That explains a lot….)

For anyone interested in learning more about PowerShell, here are some good resources:

No LaTeX support? Drat.

Sadly, UT’s WordPress implementation does not include support for LaTeX tags.  I’ve submitted a suggestion to add such support. I’m thinking that it will greatly improve the appeal of this service to faculty and students in math, science, and engineering disciplines.  I’ve also posted an example on WordPress.com of what such support can do.

If such support were in place, the following code would show the LaTeX logo:

$latex \LaTeX$

Whither E14?

The next version of Exchange, E14, is in beta as part of Microsoft’s Live@EDU service. When it will go RTM is anybody’s guess. Rumors have been spilled that E14 will go RTM in October 2009, but there is no telling when it will actually drop.

Also in 2010, we’ll be facing the need to move our Exchange environment to a new data center. Plus, it would be nice to move the underlying OS from Windows Server 2003 to Server 2008 (2003 HA clusters can’t be upgraded in-place to 2008).  I’ve been busily scheming to formulate devious plans which would allow us to accomplish both without an extensive outage or mass mailbox moves.  Hint:  it involves Standby Continuous Replication.  Of course, any such schemes that I concoct now are subject to change once Microsoft finally announces the details of E14, including upgrade paths and supported configurations.  They have been mum on both subjects thus far.

So, what will we get with E14?  The biggest feature announced thus far is cross-platform support for OWA Premium, which would be of great benefit to the many Mac users in our environment (including me).