Solved

Consolidating scripts

Posted on 2012-04-10
3
334 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 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