Powershell - Exchange O365 - 列表共享邮箱的大小,不包括一些其他列表
Powershell - Exchange O365 - size of listed sharedmailboxes excluding some of another list
我真的是 powershell(和开发)的新手抱歉...
我需要列出 ExchangeO365 上一些共享邮箱的大小,但不是全部。此代码来自网络
#Prepare Output file with headers
Out-File -FilePath $OutputFile -InputObject "DisplayName,UserPrincipalName,MailboxSize,ProhibitSendQuota,ProhibitSendReceiveQuota" -Encoding UTF8
#gather all shared mailboxes
$objMailboxes = get-mailbox -ResultSize Unlimited -filter {RecipientTypeDetails -eq "SharedMailbox"} | select DisplayName,UserPrincipalName,MailboxSize,ProhibitSendQuota,ProhibitSendReceiveQuota
#get mailboxstatistics and Iterate through all mailboxes (but take long time)
Foreach ($objMailbox in $objMailboxes)
{
#Connect to the users mailbox
$objMailboxStats = get-mailboxstatistics -Identity ($objMailbox.UserPrincipalName) | Select TotalItemSize
#Prepare UserPrincipalName variable
$strUserPrincipalName = $objMailbox.UserPrincipalName
$strDisplayName = $objMailbox.DisplayName
#Get the size
$ItemSizeString = $objMailboxStats.TotalItemSize.ToString()
$strMailboxSize = "{0:N2}" -f ($ItemSizeString.SubString(($ItemSizeString.IndexOf("(") + 1),($itemSizeString.IndexOf(" bytes") - ($ItemSizeString.IndexOf("(") + 1))).Replace(",","")/1024/1024)
#Get the quotas
$ItemSizeString = $objMailbox.ProhibitSendQuota.ToString()
$strMailboxProhibitSendQuota = "{0:N2}" -f ($ItemSizeString.SubString(($ItemSizeString.IndexOf("(") + 1),($itemSizeString.IndexOf(" bytes") - ($ItemSizeString.IndexOf("(") + 1))).Replace(",","")/1024/1024)
$ItemSizeString = $objMailbox.ProhibitSendReceiveQuota.ToString()
$strMailboxProhibitSendReceiveQuota = "{0:N2}" -f ($ItemSizeString.SubString(($ItemSizeString.IndexOf("(") + 1),($itemSizeString.IndexOf(" bytes") - ($ItemSizeString.IndexOf("(") + 1))).Replace(",","")/1024/1024)
#Output result to screen for debuging
#write-host "$strDisplayName : $strMailboxSize"
#Prepare the user details in CSV format for writing to file
$strMailboxDetails = ('"'+$strUserPrincipalName+'","'+$strDisplayName+'","'+$strMailboxSize+'","'+$strMailboxProhibitSendQuota+'","'+$strMailboxProhibitSendReceiveQuota+'"')
#Append the data to file
Out-File -FilePath $OutputFile -InputObject $strMailboxDetails -Encoding UTF8 -append
}
还有塔达!我有一个 csv,但我不想为某些特定的共享邮箱请求邮箱统计
可能会创建一些新的共享邮箱,我不想冒险忘记将新邮箱添加到清单
所以我更喜欢创建一个 .txt 文件来列出所有不需要的邮箱,所以如果我忘记添加一些新的不需要的邮箱,它不会很戏剧化,我可以每年更正一次
#here is the list of undesired sharedmailboxes, it contains UserPrincipalName only
$excludeMailboxes = get-content -path c:\temp\listExclusionSharedMailboxes.txt
我如何才能只列出共享邮箱的统计使用情况而不列出 excludeMailboxes 上的使用情况??
正如我所说,我真的是菜鸟,如果您有其他出色的方法,我很乐意(尝试)学习...
感谢大家
注意:此答案假设您的文件包含电子邮件地址列表,每个电子邮件地址都在单独的行中。
让我们先尝试将要检查的邮箱列表保存到新变量中:
$toBeIncluded = $objMailboxes | Where-Object {$excludeMailboxes -notcontains $_.UserPrincipalName}
要验证是否已正确过滤,您可以比较这两个值:
$objMailboxes.count
$toBeIncluded.count
确认过滤成功后,您只需在 ForEach
:
中使用新变量
Foreach ($toBeIncluded in $objMailboxes)
就这些了!
我真的是 powershell(和开发)的新手抱歉... 我需要列出 ExchangeO365 上一些共享邮箱的大小,但不是全部。此代码来自网络
#Prepare Output file with headers
Out-File -FilePath $OutputFile -InputObject "DisplayName,UserPrincipalName,MailboxSize,ProhibitSendQuota,ProhibitSendReceiveQuota" -Encoding UTF8
#gather all shared mailboxes
$objMailboxes = get-mailbox -ResultSize Unlimited -filter {RecipientTypeDetails -eq "SharedMailbox"} | select DisplayName,UserPrincipalName,MailboxSize,ProhibitSendQuota,ProhibitSendReceiveQuota
#get mailboxstatistics and Iterate through all mailboxes (but take long time)
Foreach ($objMailbox in $objMailboxes)
{
#Connect to the users mailbox
$objMailboxStats = get-mailboxstatistics -Identity ($objMailbox.UserPrincipalName) | Select TotalItemSize
#Prepare UserPrincipalName variable
$strUserPrincipalName = $objMailbox.UserPrincipalName
$strDisplayName = $objMailbox.DisplayName
#Get the size
$ItemSizeString = $objMailboxStats.TotalItemSize.ToString()
$strMailboxSize = "{0:N2}" -f ($ItemSizeString.SubString(($ItemSizeString.IndexOf("(") + 1),($itemSizeString.IndexOf(" bytes") - ($ItemSizeString.IndexOf("(") + 1))).Replace(",","")/1024/1024)
#Get the quotas
$ItemSizeString = $objMailbox.ProhibitSendQuota.ToString()
$strMailboxProhibitSendQuota = "{0:N2}" -f ($ItemSizeString.SubString(($ItemSizeString.IndexOf("(") + 1),($itemSizeString.IndexOf(" bytes") - ($ItemSizeString.IndexOf("(") + 1))).Replace(",","")/1024/1024)
$ItemSizeString = $objMailbox.ProhibitSendReceiveQuota.ToString()
$strMailboxProhibitSendReceiveQuota = "{0:N2}" -f ($ItemSizeString.SubString(($ItemSizeString.IndexOf("(") + 1),($itemSizeString.IndexOf(" bytes") - ($ItemSizeString.IndexOf("(") + 1))).Replace(",","")/1024/1024)
#Output result to screen for debuging
#write-host "$strDisplayName : $strMailboxSize"
#Prepare the user details in CSV format for writing to file
$strMailboxDetails = ('"'+$strUserPrincipalName+'","'+$strDisplayName+'","'+$strMailboxSize+'","'+$strMailboxProhibitSendQuota+'","'+$strMailboxProhibitSendReceiveQuota+'"')
#Append the data to file
Out-File -FilePath $OutputFile -InputObject $strMailboxDetails -Encoding UTF8 -append
}
还有塔达!我有一个 csv,但我不想为某些特定的共享邮箱请求邮箱统计
可能会创建一些新的共享邮箱,我不想冒险忘记将新邮箱添加到清单
所以我更喜欢创建一个 .txt 文件来列出所有不需要的邮箱,所以如果我忘记添加一些新的不需要的邮箱,它不会很戏剧化,我可以每年更正一次
#here is the list of undesired sharedmailboxes, it contains UserPrincipalName only
$excludeMailboxes = get-content -path c:\temp\listExclusionSharedMailboxes.txt
我如何才能只列出共享邮箱的统计使用情况而不列出 excludeMailboxes 上的使用情况?? 正如我所说,我真的是菜鸟,如果您有其他出色的方法,我很乐意(尝试)学习...
感谢大家
注意:此答案假设您的文件包含电子邮件地址列表,每个电子邮件地址都在单独的行中。
让我们先尝试将要检查的邮箱列表保存到新变量中:
$toBeIncluded = $objMailboxes | Where-Object {$excludeMailboxes -notcontains $_.UserPrincipalName}
要验证是否已正确过滤,您可以比较这两个值:
$objMailboxes.count
$toBeIncluded.count
确认过滤成功后,您只需在 ForEach
:
Foreach ($toBeIncluded in $objMailboxes)
就这些了!