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:by MasterOfTheHat at 2013-03-27 08:16:18
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.
Unfortunately, we don’t have an Exchange 2010 environment here to run it against, but I see a couple of things in the script.by penguinviw at 2013-03-27 09:33:56
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…
Thank you for your input on the code.by ArtB0514 at 2013-03-27 10:48:26
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!!
Read Get-Help About_CommonParameters
and 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:03Maybe I shuold start over with my question.by penguinviw at 2013-03-27 13:53:00
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.
Just figued it out.by DexterPOSH at 2013-03-27 16:21:53
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.
Hi penguinviw,by penguinviw at 2013-04-01 12:00:23
Thanks for circling back and letting us know how it worked for you.
Just a word of advice , wrap your code insidetags when you post for better formatting.
In my joy I did not realzie that the lineby penguinviw at 2013-04-01 13:27:00Write-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!!
Sorry, never mind. That line is working now. I was trying to run the wrong test script.