From 45f9c961bdacf4c5f8197b9753b6cef158ca9b22 Mon Sep 17 00:00:00 2001 From: Samuel Levesque Date: Tue, 5 Sep 2023 16:10:42 -0400 Subject: [PATCH 1/3] Added properties --- .../MSFT_EXODistributionGroup.psm1 | 398 ++++++++++++++++-- 1 file changed, 370 insertions(+), 28 deletions(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXODistributionGroup/MSFT_EXODistributionGroup.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_EXODistributionGroup/MSFT_EXODistributionGroup.psm1 index 8d6c44085a..ef9bb201e8 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_EXODistributionGroup/MSFT_EXODistributionGroup.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXODistributionGroup/MSFT_EXODistributionGroup.psm1 @@ -78,6 +78,110 @@ function Get-TargetResource [System.Boolean] $RoomList, + [Parameter()] + [System.String] + $AcceptMessagesOnlyFrom, + + [Parameter()] + [System.String] + $AcceptMessagesOnlyFromDLMembers, + + [Parameter()] + [System.String] + $AcceptMessagesOnlyFromSendersOrMembers, + + [Parameter()] + [System.String] + $CustomAttribute1, + + [Parameter()] + [System.String] + $CustomAttribute2, + + [Parameter()] + [System.String] + $CustomAttribute3, + + [Parameter()] + [System.String] + $CustomAttribute4, + + [Parameter()] + [System.String] + $CustomAttribute5, + + [Parameter()] + [System.String] + $CustomAttribute6, + + [Parameter()] + [System.String] + $CustomAttribute7, + + [Parameter()] + [System.String] + $CustomAttribute8, + + [Parameter()] + [System.String] + $CustomAttribute9, + + [Parameter()] + [System.String] + $CustomAttribute10, + + [Parameter()] + [System.String] + $CustomAttribute11, + + [Parameter()] + [System.String] + $CustomAttribute12, + + [Parameter()] + [System.String] + $CustomAttribute13, + + [Parameter()] + [System.String] + $CustomAttribute14, + + [Parameter()] + [System.String] + $CustomAttribute15, + + [Parameter()] + [System.String] + $EmailAddresses, + + [Parameter()] + [System.String] + $GrantSendOnBehalfTo, + + [Parameter()] + [System.String] + $HiddenFromAddressListsEnabled, + + [Parameter()] + [System.String] + $Identity, + + [Parameter()] + [System.String] + $IsDirSynced, + + [Parameter()] + [System.String] + $LegacyExchangeDN, + + [Parameter()] + [System.String] + $SendOofMessageToOriginatorEnabled, + + [Parameter()] + [System.String] + $WhenCreated, + [Parameter()] [System.String] [ValidateSet('Always', 'Internal', 'Never')] @@ -156,10 +260,12 @@ function Get-TargetResource if ($null -ne $Script:exportedInstances -and $Script:ExportMode) { $distributionGroup = $Script:exportedInstances | Where-Object -FilterScript {$_.Name -eq $Name} + $distributionGroupMembers = Get-DistributionGroupMember $Name -ErrorAction Stop -ResultSize Unlimited } else { $distributionGroup = Get-DistributionGroup -Filter "Name -eq ""$Name""" -ErrorAction Stop + $distributionGroupMembers = Get-DistributionGroupMember $Name -ErrorAction Stop -ResultSize Unlimited } if ($null -eq $distributionGroup) @@ -182,34 +288,60 @@ function Get-TargetResource } $result = @{ - Alias = $distributionGroup.Alias - BccBlocked = $distributionGroup.BccBlocked - BypassNestedModerationEnabled = $distributionGroup.BypassNestedModerationEnabled - Description = $descriptionValue - DisplayName = $distributionGroup.DisplayName - HiddenGroupMembershipEnabled = $distributionGroup.HiddenGroupMembershipEnabled - ManagedBy = $distributionGroup.ManagedBy - MemberDepartRestriction = $distributionGroup.MemberDepartRestriction - MemberJoinRestriction = $distributionGroup.MemberJoinRestriction - Members = $distributionGroup.Members - ModeratedBy = $distributionGroup.ModeratedBy - ModerationEnabled = $distributionGroup.ModerationEnabled - Name = $distributionGroup.Name - Notes = $distributionGroup.Notes - OrganizationalUnit = $distributionGroup.OrganizationalUnit - PrimarySmtpAddress = $distributionGroup.PrimarySmtpAddress - RequireSenderAuthenticationEnabled = $distributionGroup.RequireSenderAuthenticationEnabled - RoomList = $distributionGroup.RoomList - SendModerationNotifications = $distributionGroup.SendModerationNotifications - Type = $groupTypeValue - Ensure = 'Present' - Credential = $Credential - ApplicationId = $ApplicationId - CertificateThumbprint = $CertificateThumbprint - CertificatePath = $CertificatePath - CertificatePassword = $CertificatePassword - Managedidentity = $ManagedIdentity.IsPresent - TenantId = $TenantId + Alias = $distributionGroup.Alias + BccBlocked = $distributionGroup.BccBlocked + BypassNestedModerationEnabled = $distributionGroup.BypassNestedModerationEnabled + Description = $descriptionValue + DisplayName = $distributionGroup.DisplayName + HiddenGroupMembershipEnabled = $distributionGroup.HiddenGroupMembershipEnabled + ManagedBy = $distributionGroup.ManagedBy + MemberDepartRestriction = $distributionGroup.MemberDepartRestriction + MemberJoinRestriction = $distributionGroup.MemberJoinRestriction + Members = $distributionGroupMembers.Name + ModeratedBy = $distributionGroup.ModeratedBy + ModerationEnabled = $distributionGroup.ModerationEnabled + Name = $distributionGroup.Name + Notes = $distributionGroup.Notes + OrganizationalUnit = $distributionGroup.OrganizationalUnit + PrimarySmtpAddress = $distributionGroup.PrimarySmtpAddress + RequireSenderAuthenticationEnabled = $distributionGroup.RequireSenderAuthenticationEnabled + RoomList = $distributionGroup.RoomList + SendModerationNotifications = $distributionGroup.SendModerationNotifications + AcceptMessagesOnlyFrom = $distributionGroup.AcceptMessagesOnlyFrom + AcceptMessagesOnlyFromDLMembers = $distributionGroup.AcceptMessagesOnlyFromDLMembers + AcceptMessagesOnlyFromSendersOrMembers = $distributionGroup.AcceptMessagesOnlyFromSendersOrMembers + CustomAttribute1 = $distributionGroup.CustomAttribute1 + CustomAttribute2 = $distributionGroup.CustomAttribute2 + CustomAttribute3 = $distributionGroup.CustomAttribute3 + CustomAttribute4 = $distributionGroup.CustomAttribute4 + CustomAttribute5 = $distributionGroup.CustomAttribute5 + CustomAttribute6 = $distributionGroup.CustomAttribute6 + CustomAttribute7 = $distributionGroup.CustomAttribute7 + CustomAttribute8 = $distributionGroup.CustomAttribute8 + CustomAttribute9 = $distributionGroup.CustomAttribute9 + CustomAttribute10 = $distributionGroup.CustomAttribute10 + CustomAttribute11 = $distributionGroup.CustomAttribute11 + CustomAttribute12 = $distributionGroup.CustomAttribute12 + CustomAttribute13 = $distributionGroup.CustomAttribute13 + CustomAttribute14 = $distributionGroup.CustomAttribute14 + CustomAttribute15 = $distributionGroup.CustomAttribute15 + EmailAddresses = $distributionGroup.EmailAddresses + GrantSendOnBehalfTo = $distributionGroup.GrantSendOnBehalfTo + HiddenFromAddressListsEnabled = $distributionGroup.HiddenFromAddressListsEnabled + Identity = $distributionGroup.Identity + IsDirSynced = $distributionGroup.IsDirSynced + LegacyExchangeDN = $distributionGroup.LegacyExchangeDN + SendOofMessageToOriginatorEnabled = $distributionGroup.SendOofMessageToOriginatorEnabled + WhenCreated = $distributionGroup.WhenCreated + Type = $groupTypeValue + Ensure = 'Present' + Credential = $Credential + ApplicationId = $ApplicationId + CertificateThumbprint = $CertificateThumbprint + CertificatePath = $CertificatePath + CertificatePassword = $CertificatePassword + Managedidentity = $ManagedIdentity.IsPresent + TenantId = $TenantId } Write-Verbose -Message "Found Distribution Group $($Name)" @@ -308,6 +440,111 @@ function Set-TargetResource [System.Boolean] $RoomList, + [Parameter()] + [System.String] + $AcceptMessagesOnlyFrom, + + [Parameter()] + [System.String] + $AcceptMessagesOnlyFromDLMembers, + + [Parameter()] + [System.String] + $AcceptMessagesOnlyFromSendersOrMembers, + + + [Parameter()] + [System.String] + $CustomAttribute1, + + [Parameter()] + [System.String] + $CustomAttribute2, + + [Parameter()] + [System.String] + $CustomAttribute3, + + [Parameter()] + [System.String] + $CustomAttribute4, + + [Parameter()] + [System.String] + $CustomAttribute5, + + [Parameter()] + [System.String] + $CustomAttribute6, + + [Parameter()] + [System.String] + $CustomAttribute7, + + [Parameter()] + [System.String] + $CustomAttribute8, + + [Parameter()] + [System.String] + $CustomAttribute9, + + [Parameter()] + [System.String] + $CustomAttribute10, + + [Parameter()] + [System.String] + $CustomAttribute11, + + [Parameter()] + [System.String] + $CustomAttribute12, + + [Parameter()] + [System.String] + $CustomAttribute13, + + [Parameter()] + [System.String] + $CustomAttribute14, + + [Parameter()] + [System.String] + $CustomAttribute15, + + [Parameter()] + [System.String] + $EmailAddresses, + + [Parameter()] + [System.String] + $GrantSendOnBehalfTo, + + [Parameter()] + [System.String] + $HiddenFromAddressListsEnabled, + + [Parameter()] + [System.String] + $Identity, + + [Parameter()] + [System.String] + $IsDirSynced, + + [Parameter()] + [System.String] + $LegacyExchangeDN, + + [Parameter()] + [System.String] + $SendOofMessageToOriginatorEnabled, + + [Parameter()] + [System.String] + $WhenCreated, + [Parameter()] [System.String] [ValidateSet('Always', 'Internal', 'Never')] @@ -497,6 +734,111 @@ function Test-TargetResource [System.Boolean] $RoomList, + [Parameter()] + [System.String] + $AcceptMessagesOnlyFrom, + + [Parameter()] + [System.String] + $AcceptMessagesOnlyFromDLMembers, + + [Parameter()] + [System.String] + $AcceptMessagesOnlyFromSendersOrMembers, + + + [Parameter()] + [System.String] + $CustomAttribute1, + + [Parameter()] + [System.String] + $CustomAttribute2, + + [Parameter()] + [System.String] + $CustomAttribute3, + + [Parameter()] + [System.String] + $CustomAttribute4, + + [Parameter()] + [System.String] + $CustomAttribute5, + + [Parameter()] + [System.String] + $CustomAttribute6, + + [Parameter()] + [System.String] + $CustomAttribute7, + + [Parameter()] + [System.String] + $CustomAttribute8, + + [Parameter()] + [System.String] + $CustomAttribute9, + + [Parameter()] + [System.String] + $CustomAttribute10, + + [Parameter()] + [System.String] + $CustomAttribute11, + + [Parameter()] + [System.String] + $CustomAttribute12, + + [Parameter()] + [System.String] + $CustomAttribute13, + + [Parameter()] + [System.String] + $CustomAttribute14, + + [Parameter()] + [System.String] + $CustomAttribute15, + + [Parameter()] + [System.String] + $EmailAddresses, + + [Parameter()] + [System.String] + $GrantSendOnBehalfTo, + + [Parameter()] + [System.String] + $HiddenFromAddressListsEnabled, + + [Parameter()] + [System.String] + $Identity, + + [Parameter()] + [System.String] + $IsDirSynced, + + [Parameter()] + [System.String] + $LegacyExchangeDN, + + [Parameter()] + [System.String] + $SendOofMessageToOriginatorEnabled, + + [Parameter()] + [System.String] + $WhenCreated, + [Parameter()] [System.String] [ValidateSet('Always', 'Internal', 'Never')] From 4494bea7d6cbed069da5301b33d6abc2a87e3808 Mon Sep 17 00:00:00 2001 From: Samuel Levesque Date: Tue, 7 Nov 2023 08:50:13 -0500 Subject: [PATCH 2/3] New ressource ExoMailboxStatistics --- .../MSFT_ExoMailboxStatistics.psm1 | 1479 +++++++++++++++++ .../MSFT_ExoMailboxStatistics.schema.mof | 74 + .../MSFT_EXOMailboxStatistics/readme.md | 5 + .../MSFT_EXOMailboxStatistics/settings.json | 53 + .../1-ConfigureMailboxStatistics.ps1 | 78 + 5 files changed, 1689 insertions(+) create mode 100644 Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/MSFT_ExoMailboxStatistics.psm1 create mode 100644 Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/MSFT_ExoMailboxStatistics.schema.mof create mode 100644 Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/readme.md create mode 100644 Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/settings.json create mode 100644 Modules/Microsoft365DSC/Examples/Resources/EXOMailboxStatistics/1-ConfigureMailboxStatistics.ps1 diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/MSFT_ExoMailboxStatistics.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/MSFT_ExoMailboxStatistics.psm1 new file mode 100644 index 0000000000..15c26ca9db --- /dev/null +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/MSFT_ExoMailboxStatistics.psm1 @@ -0,0 +1,1479 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + ######################## + #Minimum property set + ######################## + [Parameter()] + [System.String] + $DeletedItemCount, + + [Parameter(Mandatory = $true)] + [System.String] + $DisplayName, + + [Parameter()] + [System.String] + $ItemCount, + + [Parameter()] + [System.String] + $MailboxGuid, + + [Parameter()] + [System.String] + $TotalDeletedItemSize, + + [Parameter()] + [System.String] + $TotalItemSize, + + ######################## + #All property set + ######################## + [Parameter()] + [System.String] + $AssociatedItemCount, + + [Parameter()] + [System.String] + $AttachmentTableAvailableSize, + + [Parameter()] + [System.String] + $AttachmentTableTotalSize, + + [Parameter()] + [System.String] + $DatabaseIssueWarningQuota, + + [Parameter()] + [System.String] + $DatabaseName, + + [Parameter()] + [System.String] + $DatabaseProhibitSendQuota, + + [Parameter()] + [System.String] + $DatabaseProhibitSendReceiveQuota, + + [Parameter()] + [System.String] + $DisconnectDate, + + [Parameter()] + [System.String] + $DisconnectReason, + + [Parameter()] + [System.String] + $DumpsterMessagesPerFolderCountReceiveQuota, + + [Parameter()] + [System.String] + $DumpsterMessagesPerFolderCountWarningQuota, + + [Parameter()] + [System.String] + $ExternalDirectoryOrganizationId, + + [Parameter()] + [System.String] + $FastIsEnabled, + + [Parameter()] + [System.String] + $FolderHierarchyChildrenCountReceiveQuota, + + [Parameter()] + [System.String] + $FolderHierarchyChildrenCountWarningQuota, + + [Parameter()] + [System.String] + $FolderHierarchyDepthReceiveQuota, + + [Parameter()] + [System.String] + $FolderHierarchyDepthWarningQuota, + + [Parameter()] + [System.String] + $FoldersCountReceiveQuota, + + [Parameter()] + [System.String] + $FoldersCountWarningQuota, + + [Parameter()] + [System.String] + $IsAbandonedMoveDestination, + + [Parameter()] + [System.String] + $IsArchiveMailbox, + + [Parameter()] + [System.String] + $IsDatabaseCopyActive, + + [Parameter()] + [System.String] + $IsHighDensityShard, + + [Parameter()] + [System.String] + $IsMoveDestination, + + [Parameter()] + [System.String] + $IsQuarantined, + + [Parameter()] + [System.String] + $LastLoggedOnUserAccount, + + [Parameter()] + [System.String] + $LastLogoffTime, + + [Parameter()] + [System.String] + $LastLogonTime, + + [Parameter()] + [System.String] + $LegacyDN, + + [Parameter()] + [System.String] + $MailboxMessagesPerFolderCountReceiveQuota, + + [Parameter()] + [System.String] + $MailboxMessagesPerFolderCountWarningQuota, + + [Parameter()] + [System.String] + $MailboxType, + + [Parameter()] + [System.String] + $MailboxTypeDetail, + + [Parameter()] + [System.String] + $MessageTableAvailableSize, + + [Parameter()] + [System.String] + $MessageTableTotalSize, + + [Parameter()] + [System.String] + $NamedPropertiesCountQuota, + + [Parameter()] + [System.String] + $NeedsToMove, + + [Parameter()] + [System.String] + $OtherTablesAvailableSize, + + [Parameter()] + [System.String] + $OtherTablesTotalSize, + + [Parameter()] + [System.String] + $OwnerADGuid, + + [Parameter()] + [System.String] + $QuarantineClients, + + [Parameter()] + [System.String] + $QuarantineDescription, + + [Parameter()] + [System.String] + $QuarantineEnd, + + [Parameter()] + [System.String] + $QuarantineFileVersion, + + [Parameter()] + [System.String] + $QuarantineLastCrash, + + [Parameter()] + [System.String] + $ResourceUsageRollingAvgDatabaseReads, + + [Parameter()] + [System.String] + $ResourceUsageRollingAvgRop, + + [Parameter()] + [System.String] + $ResourceUsageRollingClientTypes, + + [Parameter()] + [System.String] + $ServerName, + + [Parameter()] + [System.String] + $StorageLimitStatus, + + [Parameter()] + [System.String] + $SystemMessageCount, + + [Parameter()] + [System.String] + $SystemMessageSize, + + [Parameter()] + [System.String] + $SystemMessageSizeShutoffQuota, + + [Parameter()] + [System.String] + $SystemMessageSizeWarningQuota, + + ######################## + #Common parameters + ######################## + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $Credential, + + [Parameter()] + [System.String] + $ApplicationId, + + [Parameter()] + [System.String] + $TenantId, + + [Parameter()] + [System.String] + $CertificateThumbprint, + + [Parameter()] + [System.String] + $CertificatePath, + + [Parameter()] + [System.Management.Automation.PSCredential] + $CertificatePassword, + + [Parameter()] + [Switch] + $ManagedIdentity + ) + + Write-Verbose -Message "Getting configuration of Office 365 Mailbox Statistics $DisplayName" + if ($Script:ExportMode) + { + $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` + -InboundParameters $PSBoundParameters ` + -SkipModuleReload $true + } + else + { + $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` + -InboundParameters $PSBoundParameters + } + + #Ensure the proper dependencies are installed in the current environment. + Confirm-M365DSCDependencies + + #region Telemetry + $ResourceName = $MyInvocation.MyCommand.ModuleName -replace 'MSFT_', '' + $CommandName = $MyInvocation.MyCommand + $data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` + -CommandName $CommandName ` + -Parameters $PSBoundParameters + Add-M365DSCTelemetryEvent -Data $data + #endregion + + $nullReturn = $PSBoundParameters + $nullReturn.Ensure = 'Absent' + + try + { + + if ($null -ne $Script:MailboxStatistics -and $Script:ExportMode) + { + $mailboxStatistic = $Script:MailboxStatistics | Where-Object -FilterScript {$_.DisplayName -eq $DisplayName} + } + else + { + #Could include a switch for the different propertySets to retrieve https://learn.microsoft.com/en-us/powershell/exchange/cmdlet-property-sets?view=exchange-ps#get-exomailbox-property-sets + #Could include a switch for the different recipientTypeDetails to retrieve + $mailboxStatistic = Get-EXOMailbox -Identity $DisplayName ` + -RecipientTypeDetails 'RoomMailbox,SharedMailbox,UserMailbox' ` + -ErrorAction Stop ` + | Get-EXOMailboxStatistics -PropertySets All + } + + if ($null -eq $mailboxStatistic) + { + Write-Verbose -Message "The specified Mailbox Statistic doesn't already exist." + return $nullReturn + } + + $result = @{ + AssociatedItemCount = $mailboxStatistic.AssociatedItemCount + AttachmentTableAvailableSize = [math]::Round(($mailboxStatistic.AttachmentTableAvailableSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + AttachmentTableTotalSize = [math]::Round(($mailboxStatistic.AttachmentTableTotalSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + DatabaseIssueWarningQuota = [math]::Round(($mailboxStatistic.DatabaseIssueWarningQuota.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + DatabaseName = $mailboxStatistic.DatabaseName + DatabaseProhibitSendQuota = [math]::Round(($mailboxStatistic.DatabaseProhibitSendQuota.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + DatabaseProhibitSendReceiveQuota = [math]::Round(($mailboxStatistic.DatabaseProhibitSendReceiveQuota.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + DeletedItemCount = $mailboxStatistic.DeletedItemCount + DisconnectDate = $mailboxStatistic.DisconnectDate + DisconnectReason = $mailboxStatistic.DisconnectReason + DisplayName = $mailboxStatistic.DisplayName + DumpsterMessagesPerFolderCountReceiveQuota = $mailboxStatistic.DumpsterMessagesPerFolderCountReceiveQuota + DumpsterMessagesPerFolderCountWarningQuota = $mailboxStatistic.DumpsterMessagesPerFolderCountWarningQuota + ExternalDirectoryOrganizationId = $mailboxStatistic.ExternalDirectoryOrganizationId + FastIsEnabled = $mailboxStatistic.FastIsEnabled + FolderHierarchyChildrenCountReceiveQuota = $mailboxStatistic.FolderHierarchyChildrenCountReceiveQuota + FolderHierarchyChildrenCountWarningQuota = $mailboxStatistic.FolderHierarchyChildrenCountWarningQuota + FolderHierarchyDepthReceiveQuota = $mailboxStatistic.FolderHierarchyDepthReceiveQuota + FolderHierarchyDepthWarningQuota = $mailboxStatistic.FolderHierarchyDepthWarningQuota + FoldersCountReceiveQuota = $mailboxStatistic.FoldersCountReceiveQuota + FoldersCountWarningQuota = $mailboxStatistic.FoldersCountWarningQuota + IsAbandonedMoveDestination = $mailboxStatistic.IsAbandonedMoveDestination + IsArchiveMailbox = $mailboxStatistic.IsArchiveMailbox + IsDatabaseCopyActive = $mailboxStatistic.IsDatabaseCopyActive + IsHighDensityShard = $mailboxStatistic.IsHighDensityShard + IsMoveDestination = $mailboxStatistic.IsMoveDestination + IsQuarantined = $mailboxStatistic.IsQuarantined + ItemCount = $mailboxStatistic.ItemCount + LastLoggedOnUserAccount = $mailboxStatistic.LastLoggedOnUserAccount + LastLogoffTime = $mailboxStatistic.LastLogoffTime + LastLogonTime = $mailboxStatistic.LastLogonTime + LegacyDN = $mailboxStatistic.LegacyDN + MailboxGuid = $mailboxStatistic.MailboxGuid + MailboxMessagesPerFolderCountReceiveQuota = $mailboxStatistic.MailboxMessagesPerFolderCountReceiveQuota + MailboxMessagesPerFolderCountWarningQuota = $mailboxStatistic.MailboxMessagesPerFolderCountWarningQuota + MailboxType = $mailboxStatistic.MailboxType + MailboxTypeDetail = $mailboxStatistic.MailboxTypeDetail + MessageTableAvailableSize = [math]::Round(($mailboxStatistic.MessageTableAvailableSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + MessageTableTotalSize = [math]::Round(($mailboxStatistic.MessageTableTotalSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + NamedPropertiesCountQuota = $mailboxStatistic.NamedPropertiesCountQuota + NeedsToMove = $mailboxStatistic.NeedsToMove + OtherTablesAvailableSize = [math]::Round(($mailboxStatistic.OtherTablesAvailableSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + OtherTablesTotalSize = [math]::Round(($mailboxStatistic.OtherTablesTotalSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + OwnerADGuid = $mailboxStatistic.OwnerADGuid + QuarantineClients = $mailboxStatistic.QuarantineClients + QuarantineDescription = $mailboxStatistic.QuarantineDescription + QuarantineEnd = $mailboxStatistic.QuarantineEnd + QuarantineFileVersion = $mailboxStatistic.QuarantineFileVersion + QuarantineLastCrash = $mailboxStatistic.QuarantineLastCrash + ResourceUsageRollingAvgDatabaseReads = $mailboxStatistic.ResourceUsageRollingAvgDatabaseReads + ResourceUsageRollingAvgRop = $mailboxStatistic.ResourceUsageRollingAvgRop + ResourceUsageRollingClientTypes = $mailboxStatistic.ResourceUsageRollingClientTypes + ServerName = $mailboxStatistic.ServerName + StorageLimitStatus = $mailboxStatistic.StorageLimitStatus + SystemMessageCount = $mailboxStatistic.SystemMessageCount + SystemMessageSize = [math]::Round(($mailboxStatistic.SystemMessageSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + SystemMessageSizeShutoffQuota = [math]::Round(($mailboxStatistic.SystemMessageSizeShutoffQuota.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + SystemMessageSizeWarningQuota = [math]::Round(($mailboxStatistic.SystemMessageSizeWarningQuota.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + TotalDeletedItemSize = [math]::Round(($mailboxStatistic.TotalDeletedItemSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + TotalItemSize = [math]::Round(($mailboxStatistic.TotalItemSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + + Ensure = 'Present' + Credential = $Credential + ApplicationId = $ApplicationId + CertificateThumbprint = $CertificateThumbprint + CertificatePath = $CertificatePath + CertificatePassword = $CertificatePassword + Managedidentity = $ManagedIdentity.IsPresent + TenantId = $TenantId + } + + Write-Verbose -Message "Found an existing instance of Mailbox Statistics '$($DisplayName)'" + return $result + } + catch + { + New-M365DSCLogEntry -Message 'Error retrieving data:' ` + -Exception $_ ` + -Source $($MyInvocation.MyCommand.Source) ` + -TenantId $TenantId ` + -Credential $Credential + + return $nullReturn + } +} + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + ######################## + #Minimum property set + ######################## + [Parameter()] + [System.String] + $DeletedItemCount, + + [Parameter()] + [System.String] + $DisplayName, + + [Parameter()] + [System.String] + $ItemCount, + + [Parameter()] + [System.String] + $MailboxGuid, + + [Parameter()] + [System.String] + $TotalDeletedItemSize, + + [Parameter()] + [System.String] + $TotalItemSize, + + ######################## + #All property set + ######################## + [Parameter()] + [System.String] + $AssociatedItemCount, + + [Parameter()] + [System.String] + $AttachmentTableAvailableSize, + + [Parameter()] + [System.String] + $AttachmentTableTotalSize, + + [Parameter()] + [System.String] + $DatabaseIssueWarningQuota, + + [Parameter()] + [System.String] + $DatabaseName, + + [Parameter()] + [System.String] + $DatabaseProhibitSendQuota, + + [Parameter()] + [System.String] + $DatabaseProhibitSendReceiveQuota, + + [Parameter()] + [System.String] + $DisconnectDate, + + [Parameter()] + [System.String] + $DisconnectReason, + + [Parameter()] + [System.String] + $DumpsterMessagesPerFolderCountReceiveQuota, + + [Parameter()] + [System.String] + $DumpsterMessagesPerFolderCountWarningQuota, + + [Parameter()] + [System.String] + $ExternalDirectoryOrganizationId, + + [Parameter()] + [System.String] + $FastIsEnabled, + + [Parameter()] + [System.String] + $FolderHierarchyChildrenCountReceiveQuota, + + [Parameter()] + [System.String] + $FolderHierarchyChildrenCountWarningQuota, + + [Parameter()] + [System.String] + $FolderHierarchyDepthReceiveQuota, + + [Parameter()] + [System.String] + $FolderHierarchyDepthWarningQuota, + + [Parameter()] + [System.String] + $FoldersCountReceiveQuota, + + [Parameter()] + [System.String] + $FoldersCountWarningQuota, + + [Parameter()] + [System.String] + $IsAbandonedMoveDestination, + + [Parameter()] + [System.String] + $IsArchiveMailbox, + + [Parameter()] + [System.String] + $IsDatabaseCopyActive, + + [Parameter()] + [System.String] + $IsHighDensityShard, + + [Parameter()] + [System.String] + $IsMoveDestination, + + [Parameter()] + [System.String] + $IsQuarantined, + + [Parameter()] + [System.String] + $LastLoggedOnUserAccount, + + [Parameter()] + [System.String] + $LastLogoffTime, + + [Parameter()] + [System.String] + $LastLogonTime, + + [Parameter()] + [System.String] + $LegacyDN, + + [Parameter()] + [System.String] + $MailboxMessagesPerFolderCountReceiveQuota, + + [Parameter()] + [System.String] + $MailboxMessagesPerFolderCountWarningQuota, + + [Parameter()] + [System.String] + $MailboxType, + + [Parameter()] + [System.String] + $MailboxTypeDetail, + + [Parameter()] + [System.String] + $MessageTableAvailableSize, + + [Parameter()] + [System.String] + $MessageTableTotalSize, + + [Parameter()] + [System.String] + $NamedPropertiesCountQuota, + + [Parameter()] + [System.String] + $NeedsToMove, + + [Parameter()] + [System.String] + $OtherTablesAvailableSize, + + [Parameter()] + [System.String] + $OtherTablesTotalSize, + + [Parameter()] + [System.String] + $OwnerADGuid, + + [Parameter()] + [System.String] + $QuarantineClients, + + [Parameter()] + [System.String] + $QuarantineDescription, + + [Parameter()] + [System.String] + $QuarantineEnd, + + [Parameter()] + [System.String] + $QuarantineFileVersion, + + [Parameter()] + [System.String] + $QuarantineLastCrash, + + [Parameter()] + [System.String] + $ResourceUsageRollingAvgDatabaseReads, + + [Parameter()] + [System.String] + $ResourceUsageRollingAvgRop, + + [Parameter()] + [System.String] + $ResourceUsageRollingClientTypes, + + [Parameter()] + [System.String] + $ServerName, + + [Parameter()] + [System.String] + $StorageLimitStatus, + + [Parameter()] + [System.String] + $SystemMessageCount, + + [Parameter()] + [System.String] + $SystemMessageSize, + + [Parameter()] + [System.String] + $SystemMessageSizeShutoffQuota, + + [Parameter()] + [System.String] + $SystemMessageSizeWarningQuota, + + ######################## + #Common parameters + ######################## + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $Credential, + + [Parameter()] + [System.String] + $ApplicationId, + + [Parameter()] + [System.String] + $TenantId, + + [Parameter()] + [System.String] + $CertificateThumbprint, + + [Parameter()] + [System.String] + $CertificatePath, + + [Parameter()] + [System.Management.Automation.PSCredential] + $CertificatePassword, + + [Parameter()] + [Switch] + $ManagedIdentity + ) + + throw 'Updating Mailbox Statistics is not supported.' +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + ######################## + #Minimum property set + ######################## + [Parameter()] + [System.String] + $DeletedItemCount, + + [Parameter()] + [System.String] + $DisplayName, + + [Parameter()] + [System.String] + $ItemCount, + + [Parameter()] + [System.String] + $MailboxGuid, + + [Parameter()] + [System.String] + $TotalDeletedItemSize, + + [Parameter()] + [System.String] + $TotalItemSize, + + ######################## + #All property set + ######################## + [Parameter()] + [System.String] + $AssociatedItemCount, + + [Parameter()] + [System.String] + $AttachmentTableAvailableSize, + + [Parameter()] + [System.String] + $AttachmentTableTotalSize, + + [Parameter()] + [System.String] + $DatabaseIssueWarningQuota, + + [Parameter()] + [System.String] + $DatabaseName, + + [Parameter()] + [System.String] + $DatabaseProhibitSendQuota, + + [Parameter()] + [System.String] + $DatabaseProhibitSendReceiveQuota, + + [Parameter()] + [System.String] + $DisconnectDate, + + [Parameter()] + [System.String] + $DisconnectReason, + + [Parameter()] + [System.String] + $DumpsterMessagesPerFolderCountReceiveQuota, + + [Parameter()] + [System.String] + $DumpsterMessagesPerFolderCountWarningQuota, + + [Parameter()] + [System.String] + $ExternalDirectoryOrganizationId, + + [Parameter()] + [System.String] + $FastIsEnabled, + + [Parameter()] + [System.String] + $FolderHierarchyChildrenCountReceiveQuota, + + [Parameter()] + [System.String] + $FolderHierarchyChildrenCountWarningQuota, + + [Parameter()] + [System.String] + $FolderHierarchyDepthReceiveQuota, + + [Parameter()] + [System.String] + $FolderHierarchyDepthWarningQuota, + + [Parameter()] + [System.String] + $FoldersCountReceiveQuota, + + [Parameter()] + [System.String] + $FoldersCountWarningQuota, + + [Parameter()] + [System.String] + $IsAbandonedMoveDestination, + + [Parameter()] + [System.String] + $IsArchiveMailbox, + + [Parameter()] + [System.String] + $IsDatabaseCopyActive, + + [Parameter()] + [System.String] + $IsHighDensityShard, + + [Parameter()] + [System.String] + $IsMoveDestination, + + [Parameter()] + [System.String] + $IsQuarantined, + + [Parameter()] + [System.String] + $LastLoggedOnUserAccount, + + [Parameter()] + [System.String] + $LastLogoffTime, + + [Parameter()] + [System.String] + $LastLogonTime, + + [Parameter()] + [System.String] + $LegacyDN, + + [Parameter()] + [System.String] + $MailboxMessagesPerFolderCountReceiveQuota, + + [Parameter()] + [System.String] + $MailboxMessagesPerFolderCountWarningQuota, + + [Parameter()] + [System.String] + $MailboxType, + + [Parameter()] + [System.String] + $MailboxTypeDetail, + + [Parameter()] + [System.String] + $MessageTableAvailableSize, + + [Parameter()] + [System.String] + $MessageTableTotalSize, + + [Parameter()] + [System.String] + $NamedPropertiesCountQuota, + + [Parameter()] + [System.String] + $NeedsToMove, + + [Parameter()] + [System.String] + $OtherTablesAvailableSize, + + [Parameter()] + [System.String] + $OtherTablesTotalSize, + + [Parameter()] + [System.String] + $OwnerADGuid, + + [Parameter()] + [System.String] + $QuarantineClients, + + [Parameter()] + [System.String] + $QuarantineDescription, + + [Parameter()] + [System.String] + $QuarantineEnd, + + [Parameter()] + [System.String] + $QuarantineFileVersion, + + [Parameter()] + [System.String] + $QuarantineLastCrash, + + [Parameter()] + [System.String] + $ResourceUsageRollingAvgDatabaseReads, + + [Parameter()] + [System.String] + $ResourceUsageRollingAvgRop, + + [Parameter()] + [System.String] + $ResourceUsageRollingClientTypes, + + [Parameter()] + [System.String] + $ServerName, + + [Parameter()] + [System.String] + $StorageLimitStatus, + + [Parameter()] + [System.String] + $SystemMessageCount, + + [Parameter()] + [System.String] + $SystemMessageSize, + + [Parameter()] + [System.String] + $SystemMessageSizeShutoffQuota, + + [Parameter()] + [System.String] + $SystemMessageSizeWarningQuota, + + ######################## + #Common parameters + ######################## + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $Credential, + + [Parameter()] + [System.String] + $ApplicationId, + + [Parameter()] + [System.String] + $TenantId, + + [Parameter()] + [System.String] + $CertificateThumbprint, + + [Parameter()] + [System.String] + $CertificatePath, + + [Parameter()] + [System.Management.Automation.PSCredential] + $CertificatePassword, + + [Parameter()] + [Switch] + $ManagedIdentity + ) + + #Ensure the proper dependencies are installed in the current environment. + Confirm-M365DSCDependencies + + #region Telemetry + $ResourceName = $MyInvocation.MyCommand.ModuleName -replace 'MSFT_', '' + $CommandName = $MyInvocation.MyCommand + $data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` + -CommandName $CommandName ` + -Parameters $PSBoundParameters + Add-M365DSCTelemetryEvent -Data $data + #endregion + + Write-Verbose -Message "Testing configuration of Office 365 Mailbox Statistics $DisplayName" + + $CurrentValues = Get-TargetResource @PSBoundParameters + + Write-Verbose -Message "Current Values: $(Convert-M365DscHashtableToString -Hashtable $CurrentValues)" + Write-Verbose -Message "Target Values: $(Convert-M365DscHashtableToString -Hashtable $PSBoundParameters)" + + $TestResult = Test-M365DSCParameterState -CurrentValues $CurrentValues ` + -Source $($MyInvocation.MyCommand.Source) ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @('Ensure', ` + 'DisplayName') + + Write-Verbose -Message "Test-TargetResource returned $TestResult" + + return $TestResult +} + +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param + ( + ######################## + #Minimum property set + ######################## + [Parameter()] + [System.String] + $DeletedItemCount, + + [Parameter()] + [System.String] + $DisplayName, + + [Parameter()] + [System.String] + $ItemCount, + + [Parameter()] + [System.String] + $MailboxGuid, + + [Parameter()] + [System.String] + $TotalDeletedItemSize, + + [Parameter()] + [System.String] + $TotalItemSize, + + ######################## + #All property set + ######################## + [Parameter()] + [System.String] + $AssociatedItemCount, + + [Parameter()] + [System.String] + $AttachmentTableAvailableSize, + + [Parameter()] + [System.String] + $AttachmentTableTotalSize, + + [Parameter()] + [System.String] + $DatabaseIssueWarningQuota, + + [Parameter()] + [System.String] + $DatabaseName, + + [Parameter()] + [System.String] + $DatabaseProhibitSendQuota, + + [Parameter()] + [System.String] + $DatabaseProhibitSendReceiveQuota, + + [Parameter()] + [System.String] + $DisconnectDate, + + [Parameter()] + [System.String] + $DisconnectReason, + + [Parameter()] + [System.String] + $DumpsterMessagesPerFolderCountReceiveQuota, + + [Parameter()] + [System.String] + $DumpsterMessagesPerFolderCountWarningQuota, + + [Parameter()] + [System.String] + $ExternalDirectoryOrganizationId, + + [Parameter()] + [System.String] + $FastIsEnabled, + + [Parameter()] + [System.String] + $FolderHierarchyChildrenCountReceiveQuota, + + [Parameter()] + [System.String] + $FolderHierarchyChildrenCountWarningQuota, + + [Parameter()] + [System.String] + $FolderHierarchyDepthReceiveQuota, + + [Parameter()] + [System.String] + $FolderHierarchyDepthWarningQuota, + + [Parameter()] + [System.String] + $FoldersCountReceiveQuota, + + [Parameter()] + [System.String] + $FoldersCountWarningQuota, + + [Parameter()] + [System.String] + $IsAbandonedMoveDestination, + + [Parameter()] + [System.String] + $IsArchiveMailbox, + + [Parameter()] + [System.String] + $IsDatabaseCopyActive, + + [Parameter()] + [System.String] + $IsHighDensityShard, + + [Parameter()] + [System.String] + $IsMoveDestination, + + [Parameter()] + [System.String] + $IsQuarantined, + + [Parameter()] + [System.String] + $LastLoggedOnUserAccount, + + [Parameter()] + [System.String] + $LastLogoffTime, + + [Parameter()] + [System.String] + $LastLogonTime, + + [Parameter()] + [System.String] + $LegacyDN, + + [Parameter()] + [System.String] + $MailboxMessagesPerFolderCountReceiveQuota, + + [Parameter()] + [System.String] + $MailboxMessagesPerFolderCountWarningQuota, + + [Parameter()] + [System.String] + $MailboxType, + + [Parameter()] + [System.String] + $MailboxTypeDetail, + + [Parameter()] + [System.String] + $MessageTableAvailableSize, + + [Parameter()] + [System.String] + $MessageTableTotalSize, + + [Parameter()] + [System.String] + $NamedPropertiesCountQuota, + + [Parameter()] + [System.String] + $NeedsToMove, + + [Parameter()] + [System.String] + $OtherTablesAvailableSize, + + [Parameter()] + [System.String] + $OtherTablesTotalSize, + + [Parameter()] + [System.String] + $OwnerADGuid, + + [Parameter()] + [System.String] + $QuarantineClients, + + [Parameter()] + [System.String] + $QuarantineDescription, + + [Parameter()] + [System.String] + $QuarantineEnd, + + [Parameter()] + [System.String] + $QuarantineFileVersion, + + [Parameter()] + [System.String] + $QuarantineLastCrash, + + [Parameter()] + [System.String] + $ResourceUsageRollingAvgDatabaseReads, + + [Parameter()] + [System.String] + $ResourceUsageRollingAvgRop, + + [Parameter()] + [System.String] + $ResourceUsageRollingClientTypes, + + [Parameter()] + [System.String] + $ServerName, + + [Parameter()] + [System.String] + $StorageLimitStatus, + + [Parameter()] + [System.String] + $SystemMessageCount, + + [Parameter()] + [System.String] + $SystemMessageSize, + + [Parameter()] + [System.String] + $SystemMessageSizeShutoffQuota, + + [Parameter()] + [System.String] + $SystemMessageSizeWarningQuota, + + ######################## + #Common parameters + ######################## + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $Credential, + + [Parameter()] + [System.String] + $ApplicationId, + + [Parameter()] + [System.String] + $TenantId, + + [Parameter()] + [System.String] + $CertificateThumbprint, + + [Parameter()] + [System.String] + $CertificatePath, + + [Parameter()] + [System.Management.Automation.PSCredential] + $CertificatePassword, + + [Parameter()] + [Switch] + $ManagedIdentity + ) + + $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` + -InboundParameters $PSBoundParameters ` + -SkipModuleReload $true + + #Ensure the proper dependencies are installed in the current environment. + Confirm-M365DSCDependencies + + #region Telemetry + $ResourceName = $MyInvocation.MyCommand.ModuleName -replace 'MSFT_', '' + $CommandName = $MyInvocation.MyCommand + $data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` + -CommandName $CommandName ` + -Parameters $PSBoundParameters + Add-M365DSCTelemetryEvent -Data $data + #endregion + + try + { + $Script:ExportMode = $true + + [array]$Script:MailboxStatistics = Get-EXOMailbox -ResultSize Unlimited -RecipientTypeDetails 'RoomMailbox,SharedMailbox,UserMailbox' | Get-EXOMailboxStatistics -PropertySets All + + $dscContent = '' + $i = 1 + if ($MailboxStatistics.Length -eq 0) + { + Write-Host $Global:M365DSCEmojiGreenCheckMark + } + else + { + Write-Host "`r`n" -NoNewline + } + foreach ($mailboxStatistic in $MailboxStatistics) + { + Write-Host " |---[$i/$($mailboxStatistics.Length)] $($mailboxStatistic.DisplayName)" -NoNewline + $mailboxStatisticDisplayName = $mailboxStatistic.DisplayName + if ($mailboxStatisticDisplayName) + { + $params = @{ + AssociatedItemCount = $mailboxStatistic.AssociatedItemCount + AttachmentTableAvailableSize = [math]::Round(($mailboxStatistic.AttachmentTableAvailableSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + AttachmentTableTotalSize = [math]::Round(($mailboxStatistic.AttachmentTableTotalSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + DatabaseIssueWarningQuota = [math]::Round(($mailboxStatistic.DatabaseIssueWarningQuota.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + DatabaseName = $mailboxStatistic.DatabaseName + DatabaseProhibitSendQuota = [math]::Round(($mailboxStatistic.DatabaseProhibitSendQuota.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + DatabaseProhibitSendReceiveQuota = [math]::Round(($mailboxStatistic.DatabaseProhibitSendReceiveQuota.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + DeletedItemCount = $mailboxStatistic.DeletedItemCount + DisconnectDate = $mailboxStatistic.DisconnectDate + DisconnectReason = $mailboxStatistic.DisconnectReason + DisplayName = $mailboxStatistic.DisplayName + DumpsterMessagesPerFolderCountReceiveQuota = $mailboxStatistic.DumpsterMessagesPerFolderCountReceiveQuota + DumpsterMessagesPerFolderCountWarningQuota = $mailboxStatistic.DumpsterMessagesPerFolderCountWarningQuota + ExternalDirectoryOrganizationId = $mailboxStatistic.ExternalDirectoryOrganizationId + FastIsEnabled = $mailboxStatistic.FastIsEnabled + FolderHierarchyChildrenCountReceiveQuota = $mailboxStatistic.FolderHierarchyChildrenCountReceiveQuota + FolderHierarchyChildrenCountWarningQuota = $mailboxStatistic.FolderHierarchyChildrenCountWarningQuota + FolderHierarchyDepthReceiveQuota = $mailboxStatistic.FolderHierarchyDepthReceiveQuota + FolderHierarchyDepthWarningQuota = $mailboxStatistic.FolderHierarchyDepthWarningQuota + FoldersCountReceiveQuota = $mailboxStatistic.FoldersCountReceiveQuota + FoldersCountWarningQuota = $mailboxStatistic.FoldersCountWarningQuota + IsAbandonedMoveDestination = $mailboxStatistic.IsAbandonedMoveDestination + IsArchiveMailbox = $mailboxStatistic.IsArchiveMailbox + IsDatabaseCopyActive = $mailboxStatistic.IsDatabaseCopyActive + IsHighDensityShard = $mailboxStatistic.IsHighDensityShard + IsMoveDestination = $mailboxStatistic.IsMoveDestination + IsQuarantined = $mailboxStatistic.IsQuarantined + ItemCount = $mailboxStatistic.ItemCount + LastLoggedOnUserAccount = $mailboxStatistic.LastLoggedOnUserAccount + LastLogoffTime = $mailboxStatistic.LastLogoffTime + LastLogonTime = $mailboxStatistic.LastLogonTime + LegacyDN = $mailboxStatistic.LegacyDN + MailboxGuid = $mailboxStatistic.MailboxGuid + MailboxMessagesPerFolderCountReceiveQuota = $mailboxStatistic.MailboxMessagesPerFolderCountReceiveQuota + MailboxMessagesPerFolderCountWarningQuota = $mailboxStatistic.MailboxMessagesPerFolderCountWarningQuota + MailboxType = $mailboxStatistic.MailboxType + MailboxTypeDetail = $mailboxStatistic.MailboxTypeDetail + MessageTableAvailableSize = [math]::Round(($mailboxStatistic.MessageTableAvailableSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + MessageTableTotalSize = [math]::Round(($mailboxStatistic.MessageTableTotalSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + NamedPropertiesCountQuota = $mailboxStatistic.NamedPropertiesCountQuota + NeedsToMove = $mailboxStatistic.NeedsToMove + OtherTablesAvailableSize = [math]::Round(($mailboxStatistic.OtherTablesAvailableSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + OtherTablesTotalSize = [math]::Round(($mailboxStatistic.OtherTablesTotalSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + OwnerADGuid = $mailboxStatistic.OwnerADGuid + QuarantineClients = $mailboxStatistic.QuarantineClients + QuarantineDescription = $mailboxStatistic.QuarantineDescription + QuarantineEnd = $mailboxStatistic.QuarantineEnd + QuarantineFileVersion = $mailboxStatistic.QuarantineFileVersion + QuarantineLastCrash = $mailboxStatistic.QuarantineLastCrash + ResourceUsageRollingAvgDatabaseReads = $mailboxStatistic.ResourceUsageRollingAvgDatabaseReads + ResourceUsageRollingAvgRop = $mailboxStatistic.ResourceUsageRollingAvgRop + ResourceUsageRollingClientTypes = $mailboxStatistic.ResourceUsageRollingClientTypes + ServerName = $mailboxStatistic.ServerName + StorageLimitStatus = $mailboxStatistic.StorageLimitStatus + SystemMessageCount = $mailboxStatistic.SystemMessageCount + SystemMessageSize = [math]::Round(($mailboxStatistic.SystemMessageSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + SystemMessageSizeShutoffQuota = [math]::Round(($mailboxStatistic.SystemMessageSizeShutoffQuota.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + SystemMessageSizeWarningQuota = [math]::Round(($mailboxStatistic.SystemMessageSizeWarningQuota.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + TotalDeletedItemSize = [math]::Round(($mailboxStatistic.TotalDeletedItemSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + TotalItemSize = [math]::Round(($mailboxStatistic.TotalItemSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2) + + Ensure = 'Present' + Credential = $Credential + ApplicationId = $ApplicationId + CertificateThumbprint = $CertificateThumbprint + CertificatePath = $CertificatePath + CertificatePassword = $CertificatePassword + Managedidentity = $ManagedIdentity.IsPresent + TenantId = $TenantId + } + + $Results = Get-TargetResource @Params + + if ($Results -is [System.Collections.Hashtable] -and $Results.Count -gt 1) + { + $Results = Update-M365DSCExportAuthenticationResults -ConnectionMode $ConnectionMode ` + -Results $Results + $currentDSCBlock = Get-M365DSCExportContentForResource -ResourceName $ResourceName ` + -ConnectionMode $ConnectionMode ` + -ModulePath $PSScriptRoot ` + -Results $Results ` + -Credential $Credential + $dscContent += $currentDSCBlock + + Save-M365DSCPartialExport -Content $currentDSCBlock ` + -FileName $Global:PartialExportFileName + + Write-Host $Global:M365DSCEmojiGreenCheckMark + } + else + { + Write-Host $Global:M365DSCEmojiRedX + } + + $i++ + } + } + return $dscContent + } + catch + { + Write-Host $Global:M365DSCEmojiRedX + + New-M365DSCLogEntry -Message 'Error during Export:' ` + -Exception $_ ` + -Source $($MyInvocation.MyCommand.Source) ` + -TenantId $TenantId ` + -Credential $Credential + + return '' + } +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/MSFT_ExoMailboxStatistics.schema.mof b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/MSFT_ExoMailboxStatistics.schema.mof new file mode 100644 index 0000000000..c45c093d0d --- /dev/null +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/MSFT_ExoMailboxStatistics.schema.mof @@ -0,0 +1,74 @@ +[ClassVersion("1.0.0.0"), FriendlyName("EXOMailboxStatistics")] +class MSFT_EXOMailboxStatistics : OMI_BaseResource +{ + [Write, Description("")] String DeletedItemCount; + [Write, Description("")] String DisplayName; + [Write, Description("")] String ItemCount; + [Write, Description("")] String MailboxGuid; + [Write, Description("")] String TotalDeletedItemSize; + [Write, Description("")] String TotalItemSize; + [Write, Description("")] String AssociatedItemCount; + [Write, Description("")] String AttachmentTableAvailableSize; + [Write, Description("")] String AttachmentTableTotalSize; + [Write, Description("")] String DatabaseIssueWarningQuota; + [Write, Description("")] String DatabaseName; + [Write, Description("")] String DatabaseProhibitSendQuota; + [Write, Description("")] String DatabaseProhibitSendReceiveQuota; + [Write, Description("")] String DisconnectDate; + [Write, Description("")] String DisconnectReason; + [Write, Description("")] String DumpsterMessagesPerFolderCountReceiveQuota; + [Write, Description("")] String DumpsterMessagesPerFolderCountWarningQuota; + [Write, Description("")] String ExternalDirectoryOrganizationId; + [Write, Description("")] String FastIsEnabled; + [Write, Description("")] String FolderHierarchyChildrenCountReceiveQuota; + [Write, Description("")] String FolderHierarchyChildrenCountWarningQuota; + [Write, Description("")] String FolderHierarchyDepthReceiveQuota; + [Write, Description("")] String FolderHierarchyDepthWarningQuota; + [Write, Description("")] String FoldersCountReceiveQuota; + [Write, Description("")] String FoldersCountWarningQuota; + [Write, Description("")] String IsAbandonedMoveDestination; + [Write, Description("")] String IsArchiveMailbox; + [Write, Description("")] String IsDatabaseCopyActive; + [Write, Description("")] String IsHighDensityShard; + [Write, Description("")] String IsMoveDestination; + [Write, Description("")] String IsQuarantined; + [Write, Description("")] String LastLoggedOnUserAccount; + [Write, Description("")] String LastLogoffTime; + [Write, Description("")] String LastLogonTime; + [Write, Description("")] String LegacyDN; + [Write, Description("")] String MailboxMessagesPerFolderCountReceiveQuota; + [Write, Description("")] String MailboxMessagesPerFolderCountWarningQuota; + [Write, Description("")] String MailboxType; + [Write, Description("")] String MailboxTypeDetail; + [Write, Description("")] String MessageTableAvailableSize; + [Write, Description("")] String MessageTableTotalSize; + [Write, Description("")] String NamedPropertiesCountQuota; + [Write, Description("")] String NeedsToMove; + [Write, Description("")] String OtherTablesAvailableSize; + [Write, Description("")] String OtherTablesTotalSize; + [Write, Description("")] String OwnerADGuid; + [Write, Description("")] String QuarantineClients; + [Write, Description("")] String QuarantineDescription; + [Write, Description("")] String QuarantineEnd; + [Write, Description("")] String QuarantineFileVersion; + [Write, Description("")] String QuarantineLastCrash; + [Write, Description("")] String ResourceUsageRollingAvgDatabaseReads; + [Write, Description("")] String ResourceUsageRollingAvgRop; + [Write, Description("")] String ResourceUsageRollingClientTypes; + [Write, Description("")] String ServerName; + [Write, Description("")] String StorageLimitStatus; + [Write, Description("")] String SystemMessageCount; + [Write, Description("")] String SystemMessageSize; + [Write, Description("")] String SystemMessageSizeShutoffQuota; + [Write, Description("")] String SystemMessageSizeWarningQuota; + + [Write, Description("Present ensures the group exists, absent ensures it is removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; + [Write, Description("Credentials of the Exchange Global Admin"), EmbeddedInstance("MSFT_Credential")] string Credential; + [Write, Description("Id of the Azure Active Directory application to authenticate with.")] String ApplicationId; + [Write, Description("Id of the Azure Active Directory tenant used for authentication.")] String TenantId; + [Write, Description("Thumbprint of the Azure Active Directory application's authentication certificate to use for authentication.")] String CertificateThumbprint; + [Write, Description("Username can be made up to anything but password will be used for CertificatePassword"), EmbeddedInstance("MSFT_Credential")] String CertificatePassword; + [Write, Description("Path to certificate used in service principal usually a PFX file.")] String CertificatePath; + [Write, Description("Managed ID being used for authentication.")] Boolean ManagedIdentity; +}; + diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/readme.md b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/readme.md new file mode 100644 index 0000000000..2735beefea --- /dev/null +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/readme.md @@ -0,0 +1,5 @@ +# ExoMailboxStatistics + +## Description + +This resource allows users to retrieve Office 365 Mailbox Statistics. diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/settings.json b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/settings.json new file mode 100644 index 0000000000..4b5e759c56 --- /dev/null +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxStatistics/settings.json @@ -0,0 +1,53 @@ +{ + "resourceName": "EXOMailboxStatistics", + "description": "", + "roles": { + "read": [ + "Global Reader" + ], + "update": [ + "Exchange Administrator" + ] + }, + "permissions": { + "graph": { + "delegated": { + "read": [], + "update": [] + }, + "application": { + "read": [], + "update": [] + } + }, + "exchange": { + "requiredroles": [ + "Mail Enabled Public Folders", + "MyName", + "Public Folders", + "Compliance Admin", + "User Options", + "Message Tracking", + "View-Only Recipients", + "Role Management", + "Legal Hold", + "Audit Logs", + "Retention Management", + "Distribution Groups", + "Move Mailboxes", + "Information Rights Management", + "Mail Recipient Creation", + "Reset Password", + "View-Only Audit Logs", + "Mail Recipients", + "Mailbox Search", + "UM Mailboxes", + "Security Group Creation and Membership", + "Mailbox Import Export", + "MyMailboxDelegation", + "MyDisplayName" + ], + "requiredrolegroups": "Organization Management" + } + } +} diff --git a/Modules/Microsoft365DSC/Examples/Resources/EXOMailboxStatistics/1-ConfigureMailboxStatistics.ps1 b/Modules/Microsoft365DSC/Examples/Resources/EXOMailboxStatistics/1-ConfigureMailboxStatistics.ps1 new file mode 100644 index 0000000000..03d6d07011 --- /dev/null +++ b/Modules/Microsoft365DSC/Examples/Resources/EXOMailboxStatistics/1-ConfigureMailboxStatistics.ps1 @@ -0,0 +1,78 @@ +<# +This example is used to test new resources and showcase the usage of new resources being worked on. +It is not meant to use as a production baseline. +#> + +Configuration Example +{ + param + ( + [Parameter(Mandatory = $true)] + [PSCredential] + $credsGlobalAdmin + ) + + Import-DscResource -ModuleName Microsoft365DSC + + Node localhost + { + ExoMailboxStatistics "ExoMailboxStatistics-Adele Vance" + { + ApplicationId = $ConfigurationData.NonNodeData.ApplicationId; + AssociatedItemCount = 86; + AttachmentTableAvailableSize = 0.25; + AttachmentTableTotalSize = 4.56; + CertificateThumbprint = $ConfigurationData.NonNodeData.CertificateThumbprint; + DatabaseIssueWarningQuota = 1945; + DatabaseName = "NAMPR11DG329-db080"; + DatabaseProhibitSendQuota = 2048; + DatabaseProhibitSendReceiveQuota = 2355; + DeletedItemCount = 16; + DisplayName = "Adele Vance"; + DumpsterMessagesPerFolderCountReceiveQuota = 3000000; + DumpsterMessagesPerFolderCountWarningQuota = 2750000; + Ensure = "Present"; + ExternalDirectoryOrganizationId = "f4e8115b-2acf-4c30-8d0a-8e5268c8174c"; + FolderHierarchyChildrenCountReceiveQuota = 10000; + FolderHierarchyChildrenCountWarningQuota = 9000; + FolderHierarchyDepthReceiveQuota = 300; + FolderHierarchyDepthWarningQuota = 250; + FoldersCountReceiveQuota = 250000; + FoldersCountWarningQuota = 200000; + IsAbandonedMoveDestination = $False; + IsArchiveMailbox = $False; + IsDatabaseCopyActive = $True; + IsHighDensityShard = $False; + IsMoveDestination = $False; + IsQuarantined = $False; + ItemCount = 463; + LastLogoffTime = "2023-11-01 3:05:02 PM"; + LastLogonTime = "2023-11-01 2:54:59 PM"; + LegacyDN = "/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=1fb25a9426e94b1d911f42361f133074-AdeleV"; + MailboxGuid = "00de9d65-ce46-4a2d-afca-73c2800d27ed"; + MailboxMessagesPerFolderCountReceiveQuota = 1000000; + MailboxMessagesPerFolderCountWarningQuota = 900000; + MailboxType = "Private"; + MailboxTypeDetail = "UserMailbox"; + MessageTableAvailableSize = 9.97; + MessageTableTotalSize = 29.81; + NamedPropertiesCountQuota = 16384; + NeedsToMove = "None"; + OtherTablesAvailableSize = 0.56; + OtherTablesTotalSize = 14.28; + OwnerADGuid = "303f52c6-5943-4edb-a110-a99796365f61"; + QuarantineClients = ""; + ResourceUsageRollingAvgDatabaseReads = 0; + ResourceUsageRollingAvgRop = 0; + ResourceUsageRollingClientTypes = 2313161359686242346; + ServerName = "CH0PR11MB5249"; + SystemMessageCount = 2629; + SystemMessageSize = 11.45; + SystemMessageSizeShutoffQuota = 51200; + SystemMessageSizeWarningQuota = 50176; + TenantId = $OrganizationName; + TotalDeletedItemSize = 0.09; + TotalItemSize = 23.39; + } + } +} From 2c98847fdc173f3bdcc9fde54ddee64db047464b Mon Sep 17 00:00:00 2001 From: Samuel Levesque Date: Tue, 7 Nov 2023 09:42:27 -0500 Subject: [PATCH 3/3] Added changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index efec24833c..895e38bd85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ # UNRELEASED +* ExoMailboxStatistics + * Initial release + * O365OrgSettings * Force register the Office on the Web ServicePrincipal is it is not present. FIXES [#3842](https://github.com/microsoft/Microsoft365DSC/issues/3842)