【问题标题】:Get-MailboxFolderStatistics out-file shows only numbersGet-MailboxFolderStatistics 输出文件仅显示数字
【发布时间】:2021-11-28 06:58:42
【问题描述】:

我正在使用下面的这个脚本来计算某些邮箱拥有的文件夹数量。我目前遇到问题。如果我想检查 10 个邮箱并假设 1 个邮箱根本没有文件夹,Powershell 在导出时会跳过它。所以我的 csv 文件中只有 9 行,而且我永远不知道跳过了哪个邮箱。如何确保在此脚本期间也导出电子邮件地址?

$users = gc "c:\temp\user-list.txt"

foreach ($user in $users) { (Get-mailboxfolderstatistics -identity $user).Count | fl | out-file -FilePath C:\emails.csv -append}

user-list.txt 文件包含:

  • mailbox1@mycomp.com
  • mailbox2@mycomp.com
  • mailbox3@mycomp.com
  • mailbox4@mycomp.com
  • mailbox5@mycomp.com
  • mailbox6@mycomp.com
  • mailbox7@mycomp.com
  • mailbox8@mycomp.com
  • mailbox9@mycomp.com
  • mailbox10@mycomp.com

导出文件 emails.csv 如下所示:

  • 50
  • 36
  • 35
  • 35
  • 36
  • 36
  • 36
  • 49
  • 36

【问题讨论】:

  • 好吧,你问它是为了.Count,除了数字之外你还期待什么? :)
  • 是的,我知道 :) 但我不知道 powershell 会跳过不包含任何内容的邮箱,所以我要做的就是将电子邮件粘贴到导出之前:p

标签: powershell exchange-server


【解决方案1】:

不要单独输出计数,而是创建一个包含邮箱名称和计数的对象,然后使用Export-Csv 创建 CSV 文件:

$users |Select @{Name='Username';Expression={$_}},@{Name='FolderCount';Expression={@(Get-mailboxfolderstatistics -identity $_).Count}} |Export-Csv C:\emails.csv -NoTypeInformation

【讨论】:

  • 嗨,马蒂亚斯。感谢您的评论,但这不起作用。每个邮箱的文件夹计数值与第一个邮箱相同吗?
  • @ThijsDriesen 我的错,忘记在示例中将$user 替换为$_。我现在已经更新了答案
猜你喜欢
  • 2014-04-17
  • 2016-10-26
  • 2014-02-19
  • 2021-03-08
  • 2020-05-02
  • 2019-02-10
  • 2015-10-29
  • 1970-01-01
  • 2016-10-19
相关资源
最近更新 更多