Tuesday, July 22, 2008

Working with Active Directory Dates

Recently, my friend and colleague asked me about how to limit an ldap search to only return objects that were created after a certain date. 'whenCreated' should be a logical choice to solve that. However, this attribute has an interesting format, see this reference. So, i marked up a few functions to help us work with the date naturally within Powershell.
function ConvertToAdDate([DateTime]$date) {
"{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}.0Z" -f $date.year,$date.month, `
$date.day, $date.Hour, $date.Minute, $date.Second
}
function ConvertFromAdDate([String] $date) {
$pattern = `
'^(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})(?<hrs>\d{2})`
(?<min>\d{2})(?<sec>\d{2})\.0Z$
'
$match = [regex]::Match($date,$pattern)
if ($match.success) {
$result = New-Object System.DateTime($match.groups["year"].value,`
$match.groups["month"].value,$match.groups["day"].value,`
$match.groups["hrs"].value,$match.groups["min"].value, `
$match.groups["sec"].value,[DateTimeKind]::Utc)
$result.ToLocalTime()
}
else {
$null
}
}

Friday, July 11, 2008

Purging Mailboxes In Exchange 2003

I have recently demonstrated how to Purge a mailbox in Exchange 2007 but did not show anything for Exchange 2003. Here is what I do to purge mailboxes on Exchange 2003 server.

$list = gwmi -ComputerName "ex2k3srv" -Class Exchange_Mailbox -Namespace Root\MicrosoftExchangeV2 | ?{ $_.DateDiscoveredAbsentInDS -ne $null }
$list | %{ $_.Purge() }

For IT admins and Sales guys!!!

It's been all over the web. Still, I need to post this link b/c I'll be coming back to it for entertainment for awhile.

http://www.thewebsiteisdown.com/salesguy.html

Thursday, July 3, 2008

Purging Mailboxes in Exchange 2007

We all know how vastly different Exchange 2007 Management Console (EMC) is from Exchange System Manager (ESM) in Exchange 2003. The other day I had to test a migration for work and realized that I no longer have an easy ability to purge mailboxes through EMC just like I used to in ESM:

Under the hood, selecting Purge in ESM calls Exchange_Mailbox.Purge method.
In Exchange 2007, WMI is gone. So Powershell comes to the rescue.
After reviewing "Remove-Mailbox" reference at TechNet
, it sounds like "-Permanent" should be piped when removing the user and that's it. However, things are not that simple.
If mailbox is already disassociated, then I can query a list of disconnected mailboxes like this:
Get-MailboxStatistics | ?{ $_.DisconnectDate -ne $null}
Now, I need to pipe the "Remove-Mailbox", but which parameters do I choose?
It took me some mocking around but it turns out this is what you need:
Get-MailboxStatistics | ?{ $_.DisconnectDate -ne $null} | `
%
{ Remove-Mailbox -Database "Mailbox Database" `
-StoreMailboxIdentity
$_.MailboxGuid -WhatIf:$false}

Thursday, June 5, 2008

PowerShell Team is working hard, and for a good reason

So, I am involved lately in issues other than Exchange administration. However, I've always liked to keep tabs on what's new. Powershell team recently came out with their new CTP2 of Powershell V2. The hot buzz so far is Remoting features, but they do require understanding of WinRm. Anyone who wants to stay in the Exchange development scene for a few years to come would need to understand both platforms.

Monday, May 19, 2008

exchMasterAccountSid bytes again, and again.

I have recently spent a considerable amount of time supporting one of our customers who for some reason was unable to perform MAPILOGONEx command via MFCMAPI. We were issuing the OPENSTORE_USE_ADMIN_PRIVILEGE OPENSTORE_TAKE_OWNERSHIP which translate to using Administrative Previleges.

After much speculation about lack of permissions, it turned out that customer's environment was at Exchange 2003 SP2 but did not have a fix for msExchMasterAccountSid issue. That same issue that even had msexchange.org guys write a tool, NoMas. Apparently, Information Store disallows the administrative permission resolution as well. NoMas can help a lot with the short-term workaround, while applying KB916783 ensures the correct behavior.

Now, I need to actually look at some of our apps and review their functionality under this scenario.

Sunday, May 4, 2008

Changing focus of the blog a bit

Ok,
so I went quiet a bit just as I planned to blog more. The reason is simple. I have swapped jobs . Now, entrached in development as opposed to IT support, my focus is still with MS Exchange and Messaging. However, my day-to-day tasks are now involve looking deeper at AD integration with Exchange (various versions) and with time MAPI.