1

Guys I have this unique problem and have been stomping my head for answers. I basically have two good running scripts but I need to combine them. For some reason this is not working and I am getting all types of syntax powershell errors.

1st script which works correctly. Please see below for the second script

Get-Content c:\list.txt | foreach {
    Get-Mailboxstatistics -id $_ | foreach{
        $mbx = $_ | select DisplayName, @{Label=’MailboxSize("MB")’;Expression={$_.TotalItemSize/1MB}}, ItemCount
        $date_captured=get-date | select datetime

        Get-Mailbox -id $_ | foreach{
            $mbx | add-member -type noteProperty -name Alias -value $_.Alias
            $mbx | add-member -type noteProperty -name ServerName -value $_.ServerName
            $mbx | add-member -type noteProperty -name ProhibitSendReceiveQuota -value $.ProhibitSendReceiveQuota 
            $mbx | add-member -type noteProperty -name UseDatabaseQuotaDefaults -value $.UseDatabaseQuotaDefaults 
            $mbx | add-member -type noteProperty -name IssueWarningQuota -value $_.IssueWarningQuota
        } $mbx, $date_captured

    }

}

Here is the second command that runs. This works great by itself and again trying to

combine this with the command above this fails.

get-mailboxfolderstatistics -id "alias" | select name, foldersize, itemsinfolder

Now what I am trying to accompish is to get my output to something like this below.

DisplayName MailboxSize("MB") ItemCount
Alias ServerName
ProhibitSendReceiveQuota UseDatabaseQuotaDefaults IssueWarningQuota

DateTime : Tuesday, April 10, 2012 4:04:28 PM

Name Foldersize Itemsinfolder topofinfromationstore 0 3 calendar
1234 54 inbox 1024785 241 sent items 14745 54 deleted items 5414745 875

2
  • Not clear on what you are asking. Also, your 1st "working" script has syntax errors. Commented Apr 10, 2012 at 22:21
  • I got a funny feeling that I am missing } . I was at work when I did this and unfortunately not at a machine to run this. I am almost sure it is missing a "}" bracket. Also I am just trying to combine the script at the top along with the following command. I would like the output to go to one file. Commented Apr 10, 2012 at 23:43

2 Answers 2

1

You can use Out-File to log the output of both commands e.g.:

<first-command> | Out-File c:\log.txt
<second-command> | Out-File c:\log.txt -Append

Or if you prefer redirection operators:

<first-command>   > c:\log.txt
<second-command> >> c:\log.txt
Sign up to request clarification or add additional context in comments.

2 Comments

this actually worked like a charm. I am trying to get this to go into excel now. I have been reading where I can make this tab deliminited.
@user1324990 You can use something like this to export as TSV: $output = @(<first-command>); $output += @(<second-command>); $output | Export-Csv C:\log.csv -delimiter "``t"
1

If I follow your question what I think you want to do is combine the results of two commands so that you end up with a new object. This code will write a custom object to the pipeline with the values you seem to be after. To save to a file run your script and pipe it to Out-File or anything else.

Get-Content c:\list.txt | foreach {
Get-Mailboxstatistics -id $_ | foreach-object {
    #define a hash table of properties
    $size=($_.TotalItemSize)/1MB
    $props=@{
    MailboxSizeMB=$size;
    Displayname=$_.DisplayName;
    ItemCount=$_.ItemCount;
    DateCaptured=Get-Date;
    } #close hash

    Get-Mailbox -id $_ | foreach-object {
        $props.Add("Alias",$_.Alias)
        $props.Add("ServerName",$_.ServerName)
        $props.Add("ProhibitSendReceiveQuota",$_.ProhibitSendReceiveQuota)
        $props.Add("UseDatabaseQuotaDefaults",$_.UseDatabaseQuotaDefaults)
        $props.Add("IssueWarningQuota",$_.IssueWarningQuota)
    } #foreach mailbox

    #write a custom object
    New-Object -TypeName PSObject -Property $props

} #foreach mailboxstatistic

} #foreach content

1 Comment

I am sorry about getting back so late. I like what you have done with the commands and making them a hash. This gives me a lot of thought about other things I can use this for. From your example though however, I still cannot get the command get-mailboxfolderstatistics entered into the commands above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.