?
Solved

Powershell command to find Whitespace

Posted on 2014-04-03
4
Medium Priority
?
645 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
3 Comments
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 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 71

Expert Comment

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

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

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

There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multiple…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
Suggested Courses

864 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