Solved

Powershell command to find Whitespace

Posted on 2014-04-03
4
584 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vmware PowerCLI script 4 64
Can't a Exchange 2010 snap-in in PowerShell script 25 10
Doubt. 2 55
How to Powershell Script 7 0
Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
how to add IIS SMTP to handle application/Scanner relays into office 365.

929 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

15 Experts available now in Live!

Get 1:1 Help Now