Solved

Consolidating scripts

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now