?
Solved

Consolidating scripts

Posted on 2012-04-10
3
Medium Priority
?
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
slidingfox earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

752 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