需要获取 Exchange 2010 用户报告
Need to get an Exchange 2010 user report
我正在尝试从多租户平台获取 Exchange 2010 报告。问题是我需要从不同的 cmdlet 获得的信息。
我们的客户要求 DisplayName、MailboxPlan、PrimarySMTPAddress (Get-Mailbox)、TotalItemSize 和 上次登录时间 (Get-MailboxStatistics)
我正在尝试使用 Powershell 执行此操作,但出现错误...你能帮我找出问题所在吗?
这是脚本:
$TBMailbox = Get-Mailbox -Organization organization -ResultSize Unlimited | Select-Object Identity,DisplayName,MailboxPlan,PrimarySMTPAddress
ForEach ($Mbx in $TBMailbox) {$temp += ,(Get-MailboxStatistics -Identity $Mbx.Identity | Select $Mbx.Identity,$Mbx.DisplayName,$Mbx.MailboxPlan,$Mbx.PrimarySMTPAddress,TotalItemSize,LastLogonTime)}
$temp | Export-Csv -Path "C:\Path"
我遇到了这个错误:
- ForEach ($Mbx in $TBMailbox) {$temp += ,(Get-MailboxStatistics -Identity $Mbx.Identity | Select <<<< $Mbx.Identity,$Mbx.MailboxPlan,$Mbx.PrimarySMTPAddress,TotalItemSize,LastLogonTime)}
- CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException
- FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand
Select-Object : Cannot convert Microsoft.Exchange.Data.Directory.ADObjectId to one of the following types {System.String, System. Management.Automation.ScriptBlock}. At line:1 char:96
有什么想法吗?
更新
尝试了不同的方法,但结果相同。我认为这里的问题是 Select-Object:
Get-Mailbox -Organization organization -ResultSize Unlimited | ForEach-Object -Process {Select-Object $_.DisplayName,$_.MailboxPlan,$_.PrimarySMTPAddress,@{n=”Size(MB)”;e = {$MBXstat = Get-MailboxStatistics -Identity $_.Identity; $MBXstat.totalItemsize.value.toMB()}},@{n="LastLogonTime";e = {$MBXstat = Get-MailboxStatistics -Identity $_.Identity; $MBXstat.lastlogontime}}} | Export-Csv "C:\report.csv"
提示:无法将...ObjectId..转换为..以下类型之一...System.String...
不要使用 Select-对象,只需 Select 名称等
$TBMailbox = Get-Mailbox -Organization organization -ResultSize Unlimited | Select Identity,DisplayName,MailboxPlan,PrimarySMTPAddress
不过,我将不得不尝试一下你的 "foreach" 声明,这不是我写的方式,但这并不意味着它行不通。
最后我使用 Powershell 脚本解决了这个问题。我会在这里分享它,以防有人可以使用它:
# Script will get organization users and print it's name, email address, account usage and last logon time
$ErrorActionPreference = "SilentlyContinue";
$scriptpath = $MyInvocation.MyCommand.Definition
$dir = Split-Path $scriptpath
#Variables to configure
$organization = "organization";
#No change needed from here!!!
$reportPath = "$dir\"
$reportName = "Report_$(get-date -format dd-MM-yyyy__HH-mm-ss).html";
$mbxReport = $reportPath + $reportName
$i = 0;
If (Test-Path $mbxReport)
{
Remove-Item $mbxReport
}
#Loading Exchange CMDlets
. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto
cls
Write-Host "Obteniendo informacion de las Casillas..."
$mbxArray = Get-Mailbox -organization $organization -ResultSize Unlimited
$Total = $mbxArray.count
Write-Host "Se procesaran $Total casillas"
$titleDate = get-date -uformat "%d-%m-%Y"
$header = "
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<title>Reporte de usuarios - $organization</title>
<STYLE TYPE='text/css'>
<!--
table {
border: thin solid #666666;
}
td {
font-family: Tahoma;
font-size: 11px;
border-top: 1px solid #999999;
border-right: 1px solid #999999;
border-bottom: 1px solid #999999;
border-left: 1px solid #999999;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
body {
margin-left: 5px;
margin-top: 5px;
margin-right: 0px;
margin-bottom: 10px;
table {
border: thin solid #000000;
}
-->
</style>
</head>
<body>
<table width='100%'>
<tr bgcolor='#CCCCCC'>
<td colspan='7' height='25' align='center'>
<font face='tahoma' color='#003399' size='4'><strong>Información de usuarios $Organization $titledate</strong></font>
</td>
</tr>
</table>
"
Add-Content $mbxReport $header
$tableHeader = "
<table width='100%'><tbody>
<tr bgcolor=#CCCCCC>
<td width='10%' align='center'>Usuario</td>
<td width='5%' align='center'>Mail</td>
<td width='15%' align='center'>Mailbox Plan</td>
<td width='10%' align='center'>Tamaño (MB)</td>
<td width='10%' align='center'>Ultimo Logon</td>
</tr>
"
Add-Content $mbxReport $tableHeader
foreach($mbx in $mbxArray)
{
$Name = $mbx.Name
$Plan = $mbx.MailboxPlan
$Address = $mbx.PrimarySMTPAddress
$Statistics = Get-MailboxStatistics -Identity $mbx.Identity
foreach($stats in $Statistics)
{
$Size = $stats.TotalItemSize.value.ToMB()
$Logon = $stats.LastLogonTime
$dataRow = "
<tr>
<td width='10%' align='center'>$Name</td>
<td width='5%'>$Address</td>
<td width='15%' align='center'>$Plan</td>
<td width='10%' align='center'>$Size</td>
<td width='10%' align='center'>$Logon</td>
</tr>
"
Add-Content $mbxReport $dataRow;
$i++
Write-Host "Procesando $Address ($i de $Total)";
}
}
Add-Content $mbxReport "</body></html>"
我正在尝试从多租户平台获取 Exchange 2010 报告。问题是我需要从不同的 cmdlet 获得的信息。 我们的客户要求 DisplayName、MailboxPlan、PrimarySMTPAddress (Get-Mailbox)、TotalItemSize 和 上次登录时间 (Get-MailboxStatistics)
我正在尝试使用 Powershell 执行此操作,但出现错误...你能帮我找出问题所在吗?
这是脚本:
$TBMailbox = Get-Mailbox -Organization organization -ResultSize Unlimited | Select-Object Identity,DisplayName,MailboxPlan,PrimarySMTPAddress
ForEach ($Mbx in $TBMailbox) {$temp += ,(Get-MailboxStatistics -Identity $Mbx.Identity | Select $Mbx.Identity,$Mbx.DisplayName,$Mbx.MailboxPlan,$Mbx.PrimarySMTPAddress,TotalItemSize,LastLogonTime)}
$temp | Export-Csv -Path "C:\Path"
我遇到了这个错误:
- ForEach ($Mbx in $TBMailbox) {$temp += ,(Get-MailboxStatistics -Identity $Mbx.Identity | Select <<<< $Mbx.Identity,$Mbx.MailboxPlan,$Mbx.PrimarySMTPAddress,TotalItemSize,LastLogonTime)}
- CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException
- FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand Select-Object : Cannot convert Microsoft.Exchange.Data.Directory.ADObjectId to one of the following types {System.String, System. Management.Automation.ScriptBlock}. At line:1 char:96
有什么想法吗?
更新
尝试了不同的方法,但结果相同。我认为这里的问题是 Select-Object:
Get-Mailbox -Organization organization -ResultSize Unlimited | ForEach-Object -Process {Select-Object $_.DisplayName,$_.MailboxPlan,$_.PrimarySMTPAddress,@{n=”Size(MB)”;e = {$MBXstat = Get-MailboxStatistics -Identity $_.Identity; $MBXstat.totalItemsize.value.toMB()}},@{n="LastLogonTime";e = {$MBXstat = Get-MailboxStatistics -Identity $_.Identity; $MBXstat.lastlogontime}}} | Export-Csv "C:\report.csv"
提示:无法将...ObjectId..转换为..以下类型之一...System.String...
不要使用 Select-对象,只需 Select 名称等
$TBMailbox = Get-Mailbox -Organization organization -ResultSize Unlimited | Select Identity,DisplayName,MailboxPlan,PrimarySMTPAddress
不过,我将不得不尝试一下你的 "foreach" 声明,这不是我写的方式,但这并不意味着它行不通。
最后我使用 Powershell 脚本解决了这个问题。我会在这里分享它,以防有人可以使用它:
# Script will get organization users and print it's name, email address, account usage and last logon time
$ErrorActionPreference = "SilentlyContinue";
$scriptpath = $MyInvocation.MyCommand.Definition
$dir = Split-Path $scriptpath
#Variables to configure
$organization = "organization";
#No change needed from here!!!
$reportPath = "$dir\"
$reportName = "Report_$(get-date -format dd-MM-yyyy__HH-mm-ss).html";
$mbxReport = $reportPath + $reportName
$i = 0;
If (Test-Path $mbxReport)
{
Remove-Item $mbxReport
}
#Loading Exchange CMDlets
. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto
cls
Write-Host "Obteniendo informacion de las Casillas..."
$mbxArray = Get-Mailbox -organization $organization -ResultSize Unlimited
$Total = $mbxArray.count
Write-Host "Se procesaran $Total casillas"
$titleDate = get-date -uformat "%d-%m-%Y"
$header = "
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<title>Reporte de usuarios - $organization</title>
<STYLE TYPE='text/css'>
<!--
table {
border: thin solid #666666;
}
td {
font-family: Tahoma;
font-size: 11px;
border-top: 1px solid #999999;
border-right: 1px solid #999999;
border-bottom: 1px solid #999999;
border-left: 1px solid #999999;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
body {
margin-left: 5px;
margin-top: 5px;
margin-right: 0px;
margin-bottom: 10px;
table {
border: thin solid #000000;
}
-->
</style>
</head>
<body>
<table width='100%'>
<tr bgcolor='#CCCCCC'>
<td colspan='7' height='25' align='center'>
<font face='tahoma' color='#003399' size='4'><strong>Información de usuarios $Organization $titledate</strong></font>
</td>
</tr>
</table>
"
Add-Content $mbxReport $header
$tableHeader = "
<table width='100%'><tbody>
<tr bgcolor=#CCCCCC>
<td width='10%' align='center'>Usuario</td>
<td width='5%' align='center'>Mail</td>
<td width='15%' align='center'>Mailbox Plan</td>
<td width='10%' align='center'>Tamaño (MB)</td>
<td width='10%' align='center'>Ultimo Logon</td>
</tr>
"
Add-Content $mbxReport $tableHeader
foreach($mbx in $mbxArray)
{
$Name = $mbx.Name
$Plan = $mbx.MailboxPlan
$Address = $mbx.PrimarySMTPAddress
$Statistics = Get-MailboxStatistics -Identity $mbx.Identity
foreach($stats in $Statistics)
{
$Size = $stats.TotalItemSize.value.ToMB()
$Logon = $stats.LastLogonTime
$dataRow = "
<tr>
<td width='10%' align='center'>$Name</td>
<td width='5%'>$Address</td>
<td width='15%' align='center'>$Plan</td>
<td width='10%' align='center'>$Size</td>
<td width='10%' align='center'>$Logon</td>
</tr>
"
Add-Content $mbxReport $dataRow;
$i++
Write-Host "Procesando $Address ($i de $Total)";
}
}
Add-Content $mbxReport "</body></html>"