| Author |
Topic  |
|
|
JSCLMEDAVE
Administrator
    
USA
6113 Posts
Status: online |
Posted - 02/28/2012 : 1:08:04 PM
|
Just curious to know why the size of "Total Item Size" "Total Deleted Item Size" seems to be way off.
Example:
Get-MailBoxStatistics tbolton | Select @{name="Total Item Size (MB)"; Expression={$_.TotalItemSize.Value.ToMB()}},DeletedItemCount,@{name="TotalDeletedItemSize(MB)";Expression={$_.TotalDeletedItemSize.Value.ToMB()}}
Will result in something like -
- Total Item Size (MB)107
- DeletedItemCount 3159
- Total Deleted Item Size (MB)446
|
Tim-
“This too shall pass" |
|
|
JSCLMEDAVE
Administrator
    
USA
6113 Posts
Status: online |
Posted - 02/28/2012 : 2:42:43 PM
|
If you were pulling s Mailbox Size report would you skip
@{name="TotalDeletedItemSize(MB)";Expression={$_.TotalDeletedItemSize.Value.ToMB()}}
and go with instead
@{name="TotalDeletedItemSize(MB)";Expression=Get-MailboxFolderStatistics $_.identity.Value.ToMB() | Where {$_.FolderPath -eq "/Deleted Items"}
Still playing with this... |
Tim-
“This too shall pass" |
 |
|
|
JSCLMEDAVE
Administrator
    
USA
6113 Posts
Status: online |
Posted - 02/28/2012 : 5:05:04 PM
|
Ok this is what I am going with. This is still a work in progress...
# Creating $mbox as an object # Get-Mailbox -Filter Is pulling ALL of the MailBoxes that are NOT using the Default Database Quotas # -ResultSize Unlimited makes sure that I do not get the size limitation errror # select = Everything I want from Get-Mailbox $mbox = Get-Mailbox -Filter 'UseDatabaseQuotaDefaults -eq $False' -ResultSize Unlimited | select samAccountName,primarySmtpAddress,alias,database,UseDatabaseQuotaDefaults,LitigationHoldEnabled,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota
# Passing the $mbox object to a for-each " % " and adding items. $mbox | % { $obj = "" | select Name,SMTP,Alias,Database,QuotaDefault,"Litigation Hold",IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,ItemCount,TotalItemSize,StorageLimitStatus,DeletedItemSize,"Deleted Items" # The SamAccountName will also be used for -Identity for the following cmdlets $obj.Name = $_.samaccountname $obj.SMTP = $_.primarySmtpAddress $obj.alias = $_.alias $obj.database = $_.database $obj.quotadefault = $_.UseDatabaseQuotaDefaults $obj."Litigation Hold" = $_.LitigationHoldEnabled $obj.IssueWarningQuota = $_.IssueWarningQuota $obj.ProhibitSendQuota = $_.ProhibitSendQuota $obj.ProhibitSendReceiveQuota = $_.ProhibitSendReceiveQuota
# For every item in $mbox select these items to add from Get-MailboxStatistics for each item from above. Get-MailboxStatistics -Identity $_.SamAccountName | % { $obj.ItemCount = $_.itemcount $obj.totalitemsize = $_.totalitemsize $obj.StorageLimitStatus = $_.StorageLimitStatus
}
# For every item in $mbox select these items to add from Get-MailboxFolderStatistics for each item from above. Get-MailboxFolderStatistics -Identity $_.SamAccountName | Where {$_.FolderPath -eq "/Deleted Items"} | % { $obj.DeletedItemSize = $_.FolderAndSubfolderSize $obj."Deleted Items" = $_.ItemsInFolderAndSubfolders
}
$obj # Export to a CSV file } | Export-CSV C:\TimBolton.CSV
Edit - Added $obj."Litigation Hold" = $_.LitigationHoldEnabled
|
Tim-
“This too shall pass" |
 |
|
|
Jazzy
Administrator
    
Netherlands
1926 Posts
Status: offline |
|
|
JSCLMEDAVE
Administrator
    
USA
6113 Posts
Status: online |
Posted - 02/29/2012 : 09:49:48 AM
|
quote: Originally posted by Jazzy
The value TotalDeletedItemSize applies to the items in the dumpster, not the Deleted items folder.
Thanks for the confirmation Jetze.
There are a LOT of web sites that do not take that into account which brought about several questions about the results. |
Tim-
“This too shall pass" |
 |
|
|
JSCLMEDAVE
Administrator
    
USA
6113 Posts
Status: online |
Posted - 09/13/2012 : 2:26:10 PM
|
Update - I set this to create an Excel Spreadsheet
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(1,1) = "Name "
$Sheet.Cells.Item(1,2) = "SMTP "
$Sheet.Cells.Item(1,3) = "Alias "
$Sheet.Cells.Item(1,4) = "DataBase "
$Sheet.Cells.Item(1,5) = "Quota Default "
$Sheet.Cells.Item(1,6) = "Litigation Hold "
$Sheet.Cells.Item(1,7) = "IssueWarningQuota "
$Sheet.Cells.Item(1,8) = "ProhibitSendQuota "
$Sheet.Cells.Item(1,9) = "ProhibitSendReceiveQuota "
$Sheet.Cells.Item(1,10) = "ItemCount "
$Sheet.Cells.Item(1,11) = "TotalItemSize "
$Sheet.Cells.Item(1,12) = "StorageLimitStatus "
$Sheet.Cells.Item(1,13) = "DeletedItemSize "
$Sheet.Cells.Item(1,14) = "DeletedItems "
$WorkBook = $Sheet.UsedRange
# http://dmcritchie.mvps.org/excel/colors.htm
$WorkBook.Interior.ColorIndex = 34
$WorkBook.Font.ColorIndex = 1
$WorkBook.Font.Bold = $True
$intRow = 2
# Creating $mbox as an object
# Get-Mailbox -Filter Is pulling ALL of the MailBoxes that are NOT using the Default Database Quotas
# -ResultSize Unlimited makes sure that I do not get the size limitation errror
# select = Everything I want from Get-Mailbox
$mbox = Get-Mailbox -Filter 'UseDatabaseQuotaDefaults -eq $False' -ResultSize Unlimited | select samAccountName,primarySmtpAddress,alias,database,UseDatabaseQuotaDefaults,LitigationHoldEnabled,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota
# Passing the $mbox object to a for-each " % " and adding items.
$mbox | % {
$obj = "" | select Name,SMTP,Alias,Database,QuotaDefault,"Litigation Hold",IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,ItemCount,TotalItemSize,StorageLimitStatus,DeletedItemSize,"Deleted Items"
# The SamAccountName will also be used for -Identity for the following cmdlets
$obj.Name = $_.samaccountname
$obj.SMTP = $_.primarySmtpAddress.tostring()
$obj.alias = $_.alias
$obj.database = $_.database.tostring()
$obj.quotadefault = $_.UseDatabaseQuotaDefaults.tostring()
$obj."Litigation Hold" = $_.LitigationHoldEnabled.tostring()
$obj.IssueWarningQuota = $_.IssueWarningQuota.tostring()
$obj.ProhibitSendQuota = $_.ProhibitSendQuota.tostring()
$obj.ProhibitSendReceiveQuota = $_.ProhibitSendReceiveQuota.tostring()
# For every item in $mbox select these items to add from Get-MailboxStatistics for each item from above.
Get-MailboxStatistics -Identity $_.SamAccountName | % {
$obj.ItemCount = $_.itemcount.tostring()
$obj.totalitemsize = $_.totalitemsize.tostring()
$obj.StorageLimitStatus = $_.StorageLimitStatus.tostring()
}
# For every item in $mbox select these items to add from Get-MailboxFolderStatistics for each item from above.
Get-MailboxFolderStatistics -Identity $_.SamAccountName | Where {$_.FolderPath -eq "/Deleted Items"} | % {
$obj.DeletedItemSize = $_.FolderAndSubfolderSize.tostring()
$obj."Deleted Items" = $_.ItemsInFolderAndSubfolders.tostring()
}
$obj
} | % {
$Sheet.Cells.Item($intRow, 1) = $_.Name
$Sheet.Cells.Item($intRow, 2) = $_.SMTP
$Sheet.Cells.Item($intRow, 3) = $_.alias
$Sheet.Cells.item($intRow, 4) = $_.database
$Sheet.Cells.Item($intRow, 5) = $_.quotadefault
$Sheet.Cells.Item($intRow, 6) = $_."Litigation Hold"
$Sheet.Cells.Item($intRow, 7) = $_.IssueWarningQuota
$Sheet.Cells.Item($intRow, 8) = $_.ProhibitSendQuota
$Sheet.Cells.Item($intRow, 9) = $_.ProhibitSendReceiveQuota
$Sheet.Cells.Item($intRow, 10) = $_.ItemCount
$Sheet.Cells.Item($intRow, 11) = $_.totalitemsize
$Sheet.Cells.Item($intRow, 12) = $_.StorageLimitStatus
$Sheet.Cells.Item($intRow, 13) = $_.DeletedItemSize
$Sheet.Cells.Item($intRow, 14) = $_."Deleted Items"
$intRow = $intRow + 1
}
$WorkBook.EntireColumn.AutoFit()
#Clear
|
Tim-
“This too shall pass" |
 |
|
|
Jazzy
Administrator
    
Netherlands
1926 Posts
Status: offline |
Posted - 09/13/2012 : 2:41:25 PM
|
Interesting Tim, thanks for sharing. As a fellow PowerShell enthousiastic, may I do you a suggestion? You could try to work with functions. Functions are small building blocks which you can use later as easy as if it was a cmdlet. This makes it more easy for you to reuse a part of a script or implement something you found on the web. Also it brings more structure and makes it easier to understand for other people.
Your script could then look something like this:
########################### # Functions # Function Create-MailboxList { $mbox = Get-Mailbox -Filter 'UseDatabaseQuotaDefaults -eq $False' -ResultSize Unlimited | select samAccountName,primarySmtpAddress,alias,database,UseDatabaseQuotaDefaults,LitigationHoldEnabled,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota }
Function Make-ExcelSheet { $Excel = New-Object -Com Excel.Application $Excel.visible = $True $Excel = $Excel.Workbooks.Add() $Sheet = $Excel.WorkSheets.Item(1) $Sheet.Cells.Item(1,1) = "Name " $Sheet.Cells.Item(1,2) = "SMTP " $Sheet.Cells.Item(1,3) = "Alias " $Sheet.Cells.Item(1,4) = "DataBase " $Sheet.Cells.Item(1,5) = "Quota Default " $Sheet.Cells.Item(1,6) = "Litigation Hold " $Sheet.Cells.Item(1,7) = "IssueWarningQuota " $Sheet.Cells.Item(1,8) = "ProhibitSendQuota " $Sheet.Cells.Item(1,9) = "ProhibitSendReceiveQuota " $Sheet.Cells.Item(1,10) = "ItemCount " $Sheet.Cells.Item(1,11) = "TotalItemSize " $Sheet.Cells.Item(1,12) = "StorageLimitStatus " $Sheet.Cells.Item(1,13) = "DeletedItemSize " $Sheet.Cells.Item(1,14) = "DeletedItems " $WorkBook = $Sheet.UsedRange # http://dmcritchie.mvps.org/excel/colors.htm $WorkBook.Interior.ColorIndex = 34 $WorkBook.Font.ColorIndex = 1 $WorkBook.Font.Bold = $True }
Function Count-Items { etcetera } ########################### # Main part # Make-ExcelSheet Create-MailboxList Count-Items
I started doing this in my scripts and think it was a great improvement. Disclaimer: I'm not a pro, just sharing my experiences. :)
Better explenation: http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/ |
Jetze Mellema
Exchange specialist Former MVP (2005-2012) My blog: http://jetzemellema.blogspot.com (Dutch) My company: http://www.imara-ict.nl/ |
Edited by - Jazzy on 09/13/2012 2:42:22 PM |
 |
|
|
JSCLMEDAVE
Administrator
    
USA
6113 Posts
Status: online |
Posted - 09/13/2012 : 2:53:41 PM
|
Awesome!
I am just now getting my feat wet with Functions.
Thank You!
|
Tim-
“This too shall pass" |
 |
|
|
JeffWouters
Here To Stay
 
Netherlands
147 Posts
Status: offline |
Posted - 09/14/2012 : 02:50:32 AM
|
Great work guys, very nice introduction of functions in the script :-) @Tim: Take a look at the function snippets in ISE v3 ;-) Also, chapter19 from Don's "PoSH in a month of lunches" (edition based on PSv2) covers the basics very well :-) Personally I found the Technet help about_functions_* very useful: http://technet.microsoft.com/en-us/library/hh847829 |
Greetsz, Jeff. |
 |
|
| |
Topic  |
|
|
|