Merging two Exchange 2010 Powershell export scripts into one

Miguel Abreu 21 Reputation points
2022-10-30T13:39:24.597+00:00

Hi all.

I've been trying to merge two scripts but I'm having problems and I need some help...

I need to export specific information of my tenants mailboxes into a single CSV file but some information comes up empty on the CSV file cells and I found out that I need to use a different script to get that information, I tried to merge the two scripts but with no success and I've tried to use the "- Append" parameter to add the second script results on to the same CSV file but also with no success.

This is the first script:

Get-Mailbox -ResultSize Unlimited | Select-Object AddressBookPolicy, ProhibitSendQuota, SamAccountName, UserPrincipalName, WhenMailboxCreated, Alias, OrganizationalUnit, CustomAttribute1, DisplayName, PrimarySmtpAddress, RecipientType, RecipientTypeDetails, WindowsEmailAddress, WhenChanged, WhenCreated | export-csv -NoTypeInformation .\Mailboxes_filtered.csv -Delimiter ";" -Encoding unicode

And this is the second:

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Select DisplayName, StorageLimitStatus, TotalItemSize |export-csv -NoTypeInformation .\Mailboxes_filtered.csv -Delimiter ";" -Encoding unicode

If I try to add the second script objects into the first script, the respective cells on the CSV come up empty (except "DisplayName") and if I try to use all objects in the second script, only those three above won't show up empty on the CSV file.

So what I really need is to merge or combine this two scripts into just one (or append the second script results into the same CSV file). I allready found out ways on this forum on how to resolve this issue but the solution is done with severall scripts and command lines using variables to store results but that won't work for me...what I really need is to get the information I need with just one script so it can be practical to use, after that I can organize the exported info on a Excel datasheet.

Thanks in advance!

Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,428 questions
0 comments No comments
{count} votes

Accepted answer
  1. KyleXu-MSFT 26,226 Reputation points
    2022-10-31T02:16:41.167+00:00

    @Miguel Abreu

    You could merge them into one as below:

    $Mailboxes = Get-Mailbox -RecipientTypeDetail UserMailbox -ResultSize Unlimited   
    $Data = @()  
    foreach($Mailbox in $Mailboxes){  
        $temp = Get-Mailbox $Mailbox.PrimarySmtpAddress.Address | Select-Object AddressBookPolicy, ProhibitSendQuota, SamAccountName, UserPrincipalName, WhenMailboxCreated, Alias, OrganizationalUnit, CustomAttribute1, DisplayName, PrimarySmtpAddress, RecipientType, RecipientTypeDetails, WindowsEmailAddress, WhenChanged, WhenCreated,StorageLimitStatus, TotalItemSize  
        $temp.StorageLimitStatus = (Get-MailboxStatistics $Mailbox.PrimarySmtpAddress.Address).StorageLimitStatus  
        $temp.TotalItemSize = (Get-MailboxStatistics $Mailbox.PrimarySmtpAddress.Address).TotalItemSize.Value  
        $data+=$temp  
    }$data | export-csv c:/temp/log.csv -NoTypeInformation  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



0 additional answers

Sort by: Most helpful