part of output invisible

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 8 months ago.

  • Author
    Posts
  • #5725

    by penguinviw at 2013-03-27 06:29:31

    I am trying to scan a group of ou's, collect all the mailboxes within and give some stats from each. It seems to work except that some of the lines are invisible. Wierd. The lines saying the user has never logged into the mailbox are yellow, but all other lines are just not there. I say they are invisible because there are a random amount of blank lines in between the above mentioned lines. LIke there should be something there. Here is my code:
    Import-Module ActiveDirectory
    if(!(Get-PSSnapin |
    Where-Object {$_.name -eq "Microsoft.Exchange.Management.PowerShell.E2010"})) {
    ADD-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
    }
    $oulisting = Get-OrganizationalUnit "KT" -SingleNodeOnly | select name
    function Oustats(){
    Foreach ($ounames in $Oulisting){
    write "—–" $ounames "—–"
    Get-Mailbox | Get-MailboxStatistics | Select-Object DisplayName, TotalItemSize, ItemCount,storagelimitstatus
    write ""
    write ""
    }
    }
    Oustats

    Thanks so much.

    by MasterOfTheHat at 2013-03-27 08:16:18

    Unfortunately, we don't have an Exchange 2010 environment here to run it against, but I see a couple of things in the script.
    1. The way you have the script structured, there is no reason to put that foreach loop in a function. Since you create the $oulisting object before the loop and because the script is short and you only use the loop once, you could just leave it inline.
    2.Your loop is going through each of the $ounames in $oulisting, but it isn't actually doing the Get-Mailbox lookup on each of those $ounames. Since you have no parameters on the Get-Mailbox cmdlet, it is actually grabbing every mailbox in org each time the loop is executed. You would need to the tweak the line to use the -OrganizationUnit parameter to have the loop only grab the mailboxes in a given OU.

    Something like:
    Import-Module ActiveDirectory
    if(!(Get-PSSnapin | Where-Object {$_.name -eq "Microsoft.Exchange.Management.PowerShell.E2010"})) {
    ADD-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
    }

    $oulisting = Get-OrganizationalUnit "netsrv" -SingleNodeOnly | select name

    Foreach ($ounames in $Oulisting){
    write "-----" $ounames "-----"
    Get-Mailbox -OrganizationalUnit $ounames | Get-MailboxStatistics | Select-Object DisplayName, TotalItemSize, ItemCount,storagelimitstatus
    write ""
    write ""
    }

    Again, I haven't tested it, so it may not be completely correct. Still not sure where you are getting the yellow lines from...

    by penguinviw at 2013-03-27 09:33:56

    Thank you for your input on the code.
    The yeallow lines are a warning message. "WARNING: The user hasn't logged on to mailbox......." do you know how I can suppress these?

    Thanks!!

    by ArtB0514 at 2013-03-27 10:48:26

    Read Get-Help About_CommonParametersand look for -WarningAction. You might also double check the cmdlet you are using to verify that it is supported there.

    by penguinviw at 2013-03-27 13:30:03

    Maybe I shuold start over with my question.
    I am trying to construct a script but can not seem to put it together successfully. I can run "Get-OrganizationalUnit "KT" -SingleNodeOnly | select Name" and get the names of all the OU's under the KT OU. I can run "get-mailbox -organizationalunit gga2 | get-mailboxstatistics | Sort-Object TotalItemSize -Descending | ft @{label="User";expression={$_.DisplayName}},@{label="TotalSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},@{label="Items";expression={$_.ItemCount}},@{label="Storage Limit";expression={$_.StorageLimitStatus}},Database,ServerName -auto" to get all the info I want from the gga2 OU (one of the OU's under the KT OU). But I can not seem to put them together to make a script that will show the mailbox info above for each OU. I have spend many hours and much frustration trying all kinds of things.

    Please help. Thanks.

    by penguinviw at 2013-03-27 13:53:00

    Just figued it out.
    Import-Module ActiveDirectory
    if(!(Get-PSSnapin |
    Where-Object {$_.name -eq "Microsoft.Exchange.Management.PowerShell.E2010"})) {
    ADD-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
    }
    $ErrorActionPreference = "SilentlyContinue"
    $WarningPreference = "SilentlyContinue"
    $oulist = Get-OrganizationalUnit "KT" -SingleNodeOnly
    Function Oustats(){
    ForEach ($Ounames in $Oulist){
    Write-Host "——" "$Ounames" "——"
    Get-Mailbox -ResultSize Unlimited -OrganizationalUnit $Ounames.Name | get-mailboxstatistics | Sort-Object TotalItemSize-Descending | ft @{label="User";expression={$_.DisplayName}},@{label="TotalSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},@{label="Items";expression={$_.ItemCount}},@{label="Storage Limit";expression={$_.StorageLimitStatus}},Database,ServerName -auto
    }
    }
    Oustats

    Thanks.

    by DexterPOSH at 2013-03-27 16:21:53

    Hi penguinviw,

    Thanks for circling back and letting us know how it worked for you.
    Just a word of advice , wrap your code inside tags when you post for better formatting.

    by penguinviw at 2013-04-01 12:00:23

    In my joy I did not realzie that the line Write-Host "------" "$Ounames" "------" did not seem to be doing anything at all.
    I would like to see:
    ——
    OU Name
    ——
    between each set of OU results.
    Thanks again!!

    by penguinviw at 2013-04-01 13:27:00

    Sorry, never mind. That line is working now. I was trying to run the wrong test script.

You must be logged in to reply to this topic.