2015-07-22 2 views
0

J'essaie d'obtenir un rapport Exchange 2010 à partir d'une plate-forme mutualisée. La chose est que j'ai besoin d'informations obtenues à partir de différentes applets de commande. Notre client demande pour DisplayName, MailboxPlan, PrimarySMTPAddress(Get-Mailbox), TotalItemSize et lastlogontime (Get-MailboxStatistics)Besoin d'obtenir un rapport utilisateur Exchange 2010

Je suis en train de le faire en utilisant Powershell, mais Je reçois une erreur ... pouvez-vous m'aider à trouver ce qui ne va pas?

est ici le script:

$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" 

J'obtiens cette erreur:

  • 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

Toute pensée?

Mise à jour

Essayé une approche différente, mais avec le même résultat. Je pense que le problème est ici 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

** Mise à jour **: J'ai essayé d'utiliser '' select' et Select-Object -Property', et il échoue avec la même erreur message – EdoBarroso

Répondre

0

TRUC: Impossible de convertir ... ObjectId..to..one des types suivants ... System.String ...

ne pas utiliser Select-Object, juste Sélectionner, etc.

$TBMailbox = Get-Mailbox -Organization organization -ResultSize Unlimited | Select Identity,DisplayName,MailboxPlan,PrimarySMTPAddress Je vais devoir jouer avec votre « foreach » déclaration cependant, ce n'est pas comment je l'ai écrit, mais cela ne signifie pas qu'il ne fonctionnerait pas.

+0

Ou Select-Object -Property Identity, DisplayName, MailboxPlan, PrimarySMTPAddress – ALIENQuake

+0

Ne fonctionne pas, même erreur ... J'ai essayé avec 'Select' et' Select-Object -Property'. Peut-être une autre façon d'écrire la phrase? ... – EdoBarroso

0

Enfin, j'ai résolu cela en utilisant un script Powershell. Je vais partager ici, en cas où quelqu'un pourrait l'utiliser:

# 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>"