Solved

Consolidating scripts

Posted on 2012-04-10
3
337 Views
Last Modified: 2012-04-11
I have this script here which works well. I also have a command that I runs afterwards directly below. I would like to consolidate this into one script. The problem is I do not know how to gracefully end the foreach loop and then enter a new one to place this command in. For example if I have 4 users I would like for the script to run 4 times and as a last option run this command directly below. Any help would be appreciated, thanks.

get-content c:\list.txt | foreach { get-mailboxfolderstatistics -id $_ | select name, foldersize, itemsinfolder

}

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




$mbc

}}

Open in new window

0
Comment
Question by:techdrive
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
slidingfox earned 500 total points
ID: 37830386
Try this. It'll write the output to C:\results.txt rather than to the screen. Because your outputting two different object types, the formatting of the output is a bit crazy when you write to the host. This is why I went for a txt file instead.

Hope it does what your after...
--------------------------------------------------------------------------
Get-Content C:\list.txt |
    Foreach {
       
        $mbx = Get-Mailbox -id $_
        $mbxstats = Get-Mailboxstatistics -id $_ | select DisplayName,@{l=’MailboxSize(MB)’;e={$_.TotalItemSize/1MB}},ItemCount
        $fldstats = Get-Mailboxfolderstatistics -id $_ | select name,foldersize,itemsinfolder
        $date = Get-Date
       
        $out = New-Object -Type PSObject
        $out | add-member -type noteProperty -name Alias -value $mbx.Alias
        $out | add-member -type noteProperty -name DisplayName -value $mbxstats.DisplayName
        $out | add-member -type noteProperty -name ServerName -value $mbx.ServerName
        $out | add-member -type noteProperty -name ProhibitSendReceiveQuota -value $mbx.ProhibitSendReceiveQuota
        $out | add-member -type noteProperty -name UseDatabaseQuotaDefaults -value $mbx.UseDatabaseQuotaDefaults
        $out | add-member -type noteProperty -name IssueWarningQuota -value $mbx.IssueWarningQuota      
        $out | add-member -type noteProperty -name ’MailboxSize(MB)’ -value $mbxstats.’MailboxSize(MB)
        $out | add-member -type noteProperty -name ItemCount -value $mbxstats.ItemCount
       
        Write-Output $out | Out-File C:\Results.txt -append
        Write-Output $fldstats | Out-File C:\Results.txt -append
}
0
 

Author Comment

by:techdrive
ID: 37830881
You Sir are awesome. This works grrreeeaaatttt.
0
 
LVL 6

Expert Comment

by:slidingfox
ID: 37832021
Glad it works for you. :)

If your happy with it, could you mark it as an accepted solution please.

Cheers.
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question