我试图从多租户平台获取Exchange 2010报告。问题是我需要从不同的cmdlet获得的信息。 我们的客户要求 DisplayName,MailboxPlan,PrimarySMTPAddress (Get-Mailbox ), TotalItemSize 和 LastLogonTime (获取-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($ TBMailbox中的$ Mbx){$ 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:无法将Microsoft.Exchange.Data.Directory.ADObjectId转换为以下类型之一{System.String,System。 Management.Automation.ScriptBlock}。在行: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"
答案 0 :(得分:0)
提示:无法转换... ObjectId..to ..以下类型之一... System.String ...
不要使用Select-Object,只需选择名称等
$TBMailbox = Get-Mailbox -Organization organization -ResultSize Unlimited | Select Identity,DisplayName,MailboxPlan,PrimarySMTPAddress
我不得不玩你的“foreach”声明,但这不是我写的方式,但这并不意味着它不起作用。
答案 1 :(得分:0)
最后,我使用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>"