Get the source code for Exchange cmdlets (Disable-Mailbox)


Sometime we want to understand how exactly PowerShell and especially Exchange cmdlets work. For example we would like to find out which Exchange properties are removed within Disable-Mailbox. We can see exact source code for those cmdlets via a reflector (.NET assembly browser) – commercial (.NET Reflector) or open-source (ILSpy) products.

First, we need to find out a cmdlet library and therefore DLL file. It is quite easy in Exchange 2010:

# Exchange 2010
PS C:\> Get-Command Disable-Mailbox | fl DLL,ImplementingType

DLL: D:\exchsrvr\V14\bin\Microsoft.Exchange.Management.dll
ImplementingType: Microsoft.Exchange.Management.RecipientTasks.DisableMailbox

Unfortunately the Get-Command does not contain DLL or ImplementingType properties in Exchange 2013 and we has to use a different method:

# Exchange 2013
[PS] C:\>Get-Command Disable-Mailbox | fl DLL,ImplementingType

[PS] C:\>Get-ChildItem (Get-Command exsetup).Path.Replace("\ExSetup.exe","") | where extension -like *dll | foreach { if (($PSitem | Select-String "disable-mailbox" -Quiet) -eq $true){$PsItem}}

    Directory: C:\Exchsrvr\bin 

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         3/29/2013   3:23 AM   22946456 Microsoft.Exchange.Management.dll

Let’s back to our example. If you disable the mailbox from the Exchange organization you have to expect lose the Exchange properties. This fact is fortunately announced:

Disabling mailbox "restest1" will remove the Exchange properties from the Active Directory user object and mark the mailbox in the database for removal. If the mailbox has an archive or remote archive, the archive will also be marked for removal. In the case of remote archives, this action is permanent. You can't reconnect this user to the remote archive again.

So can we found out what is actually removed? Probably yes, if we download ILSpy (installation is not needed), open the DLL and search disablemailbox related code we will see the PropertiesToReset.

07-10-2013 4-21-15ADRecipientSchema.AcceptMessagesOnlyFrom
ADRecipientSchema.AcceptMessagesOnlyFromDLMembers
ADRecipientSchema.AddressBookPolicy
ADRecipientSchema.AddressListMembership
ADRecipientSchema.Alias
ADUserSchema.ArchiveGuid
ADUserSchema.ArchiveName
ADUserSchema.ArchiveDatabase
ADUserSchema.ArchiveQuota
ADUserSchema.ArchiveWarningQuota
ADUserSchema.ArchiveDomain
ADUserSchema.ArchiveStatus
ADRecipientSchema.BlockedSendersHash
ADUserSchema.CallAnsweringAudioCodec
ADUserSchema.Database
ADRecipientSchema.DefaultPublicFolderMailbox
ADUserSchema.DeletedItemFlags
ADUserSchema.DeliverToMailboxAndForward
ADRecipientSchema.EmailAddresses
ADUserSchema.ExternalOofOptions
ADUserSchema.ExchangeGuid
ADUserSchema.ExchangeSecurityDescriptor
ADUserSchema.ExchangeUserAccountControl
ADRecipientSchema.ForwardingAddress
ADRecipientSchema.ForwardingSmtpAddress
ADRecipientSchema.GrantSendOnBehalfTo
ADRecipientSchema.HiddenFromAddressListsEnabled
ADRecipientSchema.HomeMTA
ADUserSchema.IssueWarningQuota
ADRecipientSchema.IsRootPublicFolderMailbox
ADRecipientSchema.InternetEncoding
ADOrgPersonSchema.LanguagesRaw
ADRecipientSchema.LegacyExchangeDN
ADUserSchema.ManagedFolderMailboxPolicy
ADRecipientSchema.MailboxPlan
ADRecipientSchema.RoleAssignmentPolicy
ADRecipientSchema.MasterAccountSid
ADRecipientSchema.MaxReceiveSize
ADRecipientSchema.MaxSendSize
ADUserSchema.OfflineAddressBook
ADRecipientSchema.PoliciesExcluded
ADRecipientSchema.PoliciesIncluded
ADUserSchema.ProhibitSendQuota
ADUserSchema.ProhibitSendReceiveQuota
ADUserSchema.QueryBaseDN
ADRecipientSchema.RawExternalEmailAddress
ADRecipientSchema.RecipientDisplayType
ADRecipientSchema.RecipientLimits
ADRecipientSchema.RecipientTypeDetails
ADUserSchema.RecoverableItemsQuota
ADUserSchema.RecoverableItemsWarningQuota
ADUserSchema.CalendarLoggingQuota
ADRecipientSchema.RejectMessagesFrom
ADRecipientSchema.RejectMessagesFromDLMembers
ADRecipientSchema.RequireAllSendersAreAuthenticated
ADRecipientSchema.ResourceCapacity
ADRecipientSchema.ResourceMetaData
ADRecipientSchema.ResourceSearchProperties
ADRecipientSchema.ResourcePropertiesDisplay
ADUserSchema.RulesQuota
ADUserSchema.ServerLegacyDN
ADRecipientSchema.SafeSendersHash
ADRecipientSchema.SafeRecipientsHash
ADRecipientSchema.SimpleDisplayName
ADUserSchema.SecurityProtocol
ADRecipientSchema.TextEncodedORAddress
ADUserSchema.UseDatabaseQuotaDefaults
ADRecipientSchema.WindowsEmailAddress
ADUserSchema.ElcExpirationSuspensionEndDate
ADUserSchema.ElcExpirationSuspensionStartDate
ADUserSchema.CalendarVersionStoreDisabled
ADUserSchema.ElcExpirationSuspensionEnabled
ADUserSchema.LitigationHoldDate
ADUserSchema.LitigationHoldEnabled
ADUserSchema.LitigationHoldOwner
ADUserSchema.RetainDeletedItemsFor
ADUserSchema.RetentionComment
ADUserSchema.RetentionUrl
ADUserSchema.SingleItemRecoveryEnabled
ADRecipientSchema.CustomAttribute1
ADRecipientSchema.CustomAttribute2
ADRecipientSchema.CustomAttribute3
ADRecipientSchema.CustomAttribute4
ADRecipientSchema.CustomAttribute5
ADRecipientSchema.CustomAttribute6
ADRecipientSchema.CustomAttribute7
ADRecipientSchema.CustomAttribute8
ADRecipientSchema.CustomAttribute9
ADRecipientSchema.CustomAttribute10
ADRecipientSchema.CustomAttribute11
ADRecipientSchema.CustomAttribute12
ADRecipientSchema.CustomAttribute13
ADRecipientSchema.CustomAttribute14
ADRecipientSchema.CustomAttribute15
ADRecipientSchema.ExtensionCustomAttribute1
ADRecipientSchema.ExtensionCustomAttribute2
ADRecipientSchema.ExtensionCustomAttribute3
ADRecipientSchema.ExtensionCustomAttribute4
ADRecipientSchema.ExtensionCustomAttribute5
ADUserSchema.UMEnabledFlags
ADUserSchema.OperatorNumber
ADUserSchema.UMPinChecksum
ADRecipientSchema.UMRecipientDialPlanId
ADUserSchema.UMMailboxPolicy
ADUserSchema.MailboxMoveTargetMDB
ADUserSchema.MailboxMoveSourceMDB
ADUserSchema.MailboxMoveTargetArchiveMDB
ADUserSchema.MailboxMoveSourceArchiveMDB
ADUserSchema.MailboxMoveFlags
ADUserSchema.MailboxMoveStatus
ADUserSchema.MailboxMoveRemoteHostName
ADUserSchema.MailboxMoveBatchName

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s