Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell Exchange邮箱报告_Powershell_Exchange Server - Fatal编程技术网

Powershell Exchange邮箱报告

Powershell Exchange邮箱报告,powershell,exchange-server,Powershell,Exchange Server,我正在尝试为托管的Exchange平台生成一个邮箱报告,并稍微实现自动化。基本上每个租户都在一个OU中。因此,我试图首先提取一个OU的列表,然后计算每个OU中的邮箱数。以下是我目前掌握的情况: $ous = (Get-ADOrganizationalUnit -SearchBase "OU=Microsoft Exchange Hosted Organizations,DC=yomamma,DC=com" -Filter { (ObjectClass -eq 'organizationaluni

我正在尝试为托管的Exchange平台生成一个邮箱报告,并稍微实现自动化。基本上每个租户都在一个OU中。因此,我试图首先提取一个OU的列表,然后计算每个OU中的邮箱数。以下是我目前掌握的情况:

$ous = (Get-ADOrganizationalUnit -SearchBase "OU=Microsoft Exchange Hosted Organizations,DC=yomamma,DC=com" -Filter { (ObjectClass -eq 'organizationalunit') -and (Name -notlike 'Hosted Organization Security Groups') -and (Name -Notlike 'Microsoft Exchange Hosted Organizations') })

foreach ($ou in $ous) {
(Get-Mailbox -Organization $ou.Name -Filter {( Name -notlike 'Administrator' -and Name -notlike 'DiscoverySearch*' )} -ResultSize unlimited).count
}
它是有效的。。。某种程度上。结果将是每行上有大量的数字,每个OU的邮箱数。问题是,$ous变量中有OU,我将计数输出到屏幕。我需要的是输出两列,OU,以及另一列中的计数,这样我就可以将其导入Export-CSV cmdlet,这样我就可以将客户端名称(OU)和CSV文件中的计数通过电子邮件发送给他们


我只是不知道如何一次获得所有数据的组合。

组织信息的最简单方法是将信息放入一个对象中,如果以后需要更改数据,它已经存在于一个可以操作的对象中

$ous = (Get-ADOrganizationalUnit -SearchBase "OU=Microsoft Exchange Hosted Organizations,DC=yomamma,DC=com" -Filter { (ObjectClass -eq 'organizationalunit') -and (Name -notlike 'Hosted Organization Security Groups') -and (Name -Notlike 'Microsoft Exchange Hosted Organizations') })

foreach ($ou in $ous)
{
    # This is how many mailboxes this OU has
    $mailboxCount = (Get-Mailbox -Organization $ou.Name -Filter {( Name -notlike 'Administrator' -and Name -notlike 'DiscoverySearch*' )} -ResultSize unlimited).count

    # This is a fancy object to store our information
    $mailboxObject = New-Object psobject -Property ([Ordered]`
    @{
        "OU" = $ou
        "MailboxCount" = $mailboxCount
    })

    # You can export your CSV here or do other stuff
    # $mailboxObject | Export-CSV C:\MyPath -NoTypeInformation
}

小提示:如果您没有使用PowerShell v3,请去掉
[Ordered]
属性:)

如果我理解正确,答案非常简单。这将输出csv内容。如果愿意,您可以删除引号并将逗号替换为't',然后可以从PowerShell控制台复制/粘贴到Excel中

$ous = (Get-ADOrganizationalUnit -SearchBase "OU=Microsoft Exchange Hosted Organizations,DC=yomamma,DC=com" -Filter { (ObjectClass -eq 'organizationalunit') -and (Name -notlike 'Hosted Organization Security Groups') -and (Name -Notlike 'Microsoft Exchange Hosted Organizations') })

foreach ($ou in $ous) {
    '"' + $ou.Name + '",' + (Get-Mailbox -Organization $ou.Name -Filter {( Name -notlike 'Administrator' -and Name -notlike 'DiscoverySearch*' )} -ResultSize unlimited).count
}

这似乎是一个更好的方法。。。我不熟悉这个新东西。然而,我无法让它运行。我得到一个“Microsoft.Exchange.Diagnostics.ETraceConfiguration”的类型初始值设定项引发了一个异常。类别信息:OperationStaopped,PSRemotingTransportException,FullyQualifiedErrorId:JobFailure”我确实认为可能需要将带有“OU”=$OU”的行修改为“OU=$OU.Name”“也许,因为$ou变量将包含更多信息,我只需要Name值。仍然得到相同的结果。我正在运行powershell 3。好的,不知道为什么,但我的powershell窗口一直在使用powershell 3时崩溃。但是,我可以在另一台装有Powershell 2的服务器上运行脚本。一个问题是上面的foreach循环在每次运行时都会覆盖$mailboxObject,因此最终CSV中只有一行。所以我添加了一个“$mailboxList=@()”数组,然后在新对象运行“$mailboxList+=$mailboxCount”之后,在$mailboxList数组上导出CSV。这就得到了所需的输出。谢谢你的帮助!