Solved

Powershell command to find Whitespace

Posted on 2014-04-03
4
577 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
  • 2
4 Comments
 
LVL 68

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 68

Expert Comment

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

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

747 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

12 Experts available now in Live!

Get 1:1 Help Now