Update -
Here is my modified script below to include LastLogonTime and Office. The Office data is now visible but I receive an error on LastLogonTime.
$MB = Get-Mailbox -resultSize unlimited
$MB | foreach{
$AccountEnabled = "Enabled"
$user = Get-User $_ | select DisplayName, FirstName, LastName, company, department, title, samAccountName, UserAccountControl, City, StateOrProvince, CountryOrRegion, Office
$mbx = $_ | select ServerName, samAccountName, Name, Alias, PrimarySmtpAddress, DistinguishedName #, ProhibitSendQuota,ProhibitSendReceiveQuota,UseDatabaseQuotaDefaults,IssueWarningQuota
write-host "Processing: " $user.DisplayName "("$user.samAccountName")"
$ADSPath = "LDAP://" + $mbx.DistinguishedName
$ADUser = [ADSI]$ADSPath
$Description = [String]$ADUser.Description # Required to convert the returned value to a string
$mbx | add-member -type noteProperty -name DisplayName -value $User.DisplayName # Not part of the mailbox properties, so using Get-User property and adding it to $mbx variable
$mbx | add-member -type noteProperty -name FirstName -value $User.FirstName
$mbx | add-member -type noteProperty -name LastName -value $User.LastName
$mbx | add-member -type noteProperty -name Company -value $User.company
$mbx | add-member -type noteProperty -name Department -value $User.department
$mbx | add-member -type noteProperty -name Title -value $User.title
$mbx | add-member -type noteProperty -name City -value $User.City
$mbx | add-member -type noteProperty -name StateOrProvince -value $User.StateOrProvince
$mbx | add-member -type noteProperty -name CountryOrRegion -value $User.CountryOrRegion
$mbx | add-member -type noteProperty -name Office -value $User.Office
$mbx | add-member -type noteProperty -name Description -value $Description # Not avaliable from Exchange cmdlets, so using ADSI
If ($User.UserAccountControl -contains "AccountDisabled"){
$AccountEnabled = "Disabled"
}
$mbx | add-member -type noteProperty -name UserAccountControl -value $AccountEnabled
Get-MailboxStatistics $_ | ForEach{
$MBSize = $_.TotalItemSize.Value.ToKB()
$MBItemCount = $_.ItemCount
$MBDB = $_.DatabaseName
$MBLastLogonTime = $_.LastLogonTime
}
$mbx | add-member -type noteProperty -name TotalItemSizeinKB -value $MBSize # Get attributes from Get-MailboxStatistics and add them to $mbx variable
$mbx | add-member -type noteProperty -name ItemCount -value $MBItemCount
$mbx | add-member -type noteProperty -name DatabaseName -value $MBDB
$mbx | add-member -type noteProperty -name LastLogonTime -vaule $MBLastLogonTime
write-host "DisplayName: "$mbx.DisplayName "`tMailbox Size: "$mbx.TotalItemSizeinKB "`tMailbox Size: "$mbx.ItemCount "LastLogonTime: "$mbx.LastLogonTime
write-host
# Write-host $mbx.ServerName,"N/A", $mbx.DatabaseName, $mbx.Name, $mbx.FirstName, $mbx.LastName, $mbx.DisplayName, $mbx.Alias, $mbx.PrimarySmtpAddress, $mbx.samAccountName, $mbx.UserAccountControl, $mbx.TotalItemSizeinKB, $mbx.Description, $mbx.Department,
$mbx.Title, $mbx.City, $mbx.StateOrProvince, $mbx.CountryOrRegion, $mbx.DistinguishedName, $mbx.LastLogonTime, $mbx.Office
$mbx | Select ServerName,"N/A", DatabaseName, Name, FirstName, LastName, DisplayName, Alias, PrimarySmtpAddress, samAccountName, UserAccountControl, TotalItemSizeinKB, ItemCount, Company, Description, Department, Title, City, StateOrProvince, CountryOrRegion,
DistinguishedName, LastLogonTime, Office
} | export-csv -NoTypeInformation c:\MailboxData2.csv -Encoding unicode
$MB = $Null
$user = $Null
$ADUser = $Null
$MBX = $Null
Error Message:
Add-Member : A parameter cannot be found that matches parameter name 'vaule'.
At C:\Get-MailboxInfo.ps1:48 char:68
+ $mbx | add-member -type noteProperty -name LastLogonTime -vaule <<<< $MB
LastLogonTime
+ CategoryInfo : InvalidArgument: (:) [Add-Member], ParameterBind
ingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm
ands.AddMemberCommand
Jason
There is an amazing pack of free network admin tools.
click here to download it