Solved

Powershell command to find Whitespace

Posted on 2014-04-03
4
617 Views
Last Modified: 2014-04-21
I'm trying to determine the amount of white space in Exchange 2007 with this script. When I run it I receive the Warning:

: WARNING: By default only the first 1000 items are returned. To change the number of items returned, specify the parameter “-ResultSize”. To return all items
specify “-ResultSize Unlimited” (Note: Returning all items may take a very long time and consume a large amount of memory depending on the actual number of
items). It is not recommended to store the results in a variable; instead pipe the results to another task or script to perform batch changes.

For every Get- command I added the “-Resultsize Unlimited” but I still get the warning. EX:
Get-MailboxStatistics -ResultSize Unlimited
Get-MailboxDatabase -ResultSize Unlimited

Open in new window

Here is the script I'm trying to run:
function Get-ExchangeWhiteSpace { 

param( 
   $ComputerName = $(throw "ComputerName cannot be empty.") 
)

# Convert Dates to WMI CIM dates
$tc = [System.Management.ManagementDateTimeconverter] 
$Start =$tc::ToDmtfDateTime( (Get-Date).AddDays(-1).Date ) 
$End =$tc::ToDmtfDateTime( (Get-Date).Date) 

#Create a hash Table to hold the freespace information
$whiteSpace = @{}

# Create two claculated properties for InsertionStrings values
$DB = @{Name="DB";Expression={$_.InsertionStrings[1]}} 
$FreeMB = @{Name="FreeMB";Expression={[int]$_.InsertionStrings[0]}} 

$freespace = Get-WMIObject Win32_NTLogEvent -ComputerName $ComputerName -Filter "LogFile=’Application’ AND EventCode=1221 AND TimeWritten>=’$Start’ AND TimeWritten<=’$End’" | Select-Object $DB,$FreeMB | Sort-Object FreeMB –Unique –Descending
$freespace | ForEach-Object {$whiteSpace.Add($_.DB,$_.FreeMB)}
}

$date = ( get-date ).ToString(‘MM-dd-yyyy’)

$AllServers = @()
foreach ($server in Get-MailboxServer -ResultSize Unlimited)
{
. Get-ExchangeWhiteSpace $server
    foreach ($objItem in Get-MailboxDatabase -ResultSize Unlimited -server $server)
    {
    $edbfilepath = $objItem.edbfilepath
    $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)
    $dbsize = Get-ChildItem $path
$dbpath = $EdbFilePath.PathName.Remove(0,2).remove($EdbFilePath.PathName.length-6)
$mailboxpath = "$server$dbpath"
$size = get-wmiobject -ExchangeServer $server win32_logicaldisk |where-object {$_.deviceid -eq $objItem.EdbFilePath.DriveName} |select-object deviceID, Freespace, Size
$freespace = ($size.freespace / 1GB)
$total = ($size.size / 1GB)
$PercentFree = "{0:n2}" -f ($freespace / $total *100)
$mailboxcount = Get-MailboxStatistics -ResultSize Unlimited -database "$mailboxpath" |Where {$_.DisconnectDate -eq $null -and $_.ObjectClass -eq ‘Mailbox’} |measure-object
$disconnectedmailboxcount = Get-MailboxStatistics -ResultSize Unlimited -database "$mailboxpath" |Where {$_.DisconnectDate -ne $null} |measure-object
$ReturnedObj = New-Object PSObject
$ReturnedObj | Add-Member -MemberType NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity
$ReturnedObj | Add-Member -MemberType NoteProperty -Name "Total Size (GB)" -Value ("{0:n2}" -f ($total))
$ReturnedObj | Add-Member -MemberType NoteProperty -Name "Used Space (GB)" -Value ("{0:n2}" -f ($dbsize.Length/1024MB))
$ReturnedObj | Add-Member -MemberType NoteProperty -Name "Free Space (GB)" -Value ("{0:n2}" -f ($freespace))
$ReturnedObj | Add-Member -MemberType NoteProperty -Name "Percent Disk Free" -Value $percentfree
$ReturnedObj | Add-Member -MemberType NoteProperty -Name "User Mailbox Count" -Value $mailboxcount.count
$dbasename = $objitem.Identity.parent.name +"\" + $objitem.Identity.name
$ReturnedObj | Add-Member -MemberType NoteProperty -Name "White Space (GB)" -Value ("{0:n2}" -f ($whiteSpace[$dbasename]/1024))
$ReturnedObj | Add-Member -MemberType NoteProperty -Name "Total Free (GB)" -Value ("{0:n2}" -f ($freespace + $whiteSpace[$dbasename]/1024))
$TotalPercent = ($freespace + $whiteSpace[$dbasename]/1024) / $total *100
$ReturnedObj | Add-Member -MemberType NoteProperty -Name "Total Percent Free" -Value ("{0:n2}" -f ($TotalPercent))
    $AllServers += $ReturnedObj
}
}

$body = "<font color=blue>Mailbox database size report for $date<br /><br />"
$bodydetail = $allservers |sort-object "Server\StorageGroup\Database" |convertto-html
$body = $body + $bodydetail

Open in new window

0
Comment
Question by:tolinrome
[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
4 Comments
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39975648
Are you certain that we are talking about Exchange 2007? It does not have a -Resultsize parameter for the cmdlets you use, and there are several other (syntax) errors in the script.

To get mailbox stats, you usually write
get-mailbox -ResultSize Unlimited | Get-MailboxStatistics # and so on

Open in new window

0
 
LVL 7

Author Comment

by:tolinrome
ID: 39976091
I copied the script from a blog that was for Exchange 2007, guess not, thanks.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40006496
Did my comment make a change here, or are you waiting for something?
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

696 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