search
Categories
Archive
Blogroll

Badges

Microsoft PowerShell MVP
MCSE
Sponsors

VirtualMetric
Cozumpark Bilisim Portali
Getting Exchange Server 2010 Database statistics with PowerShell
Posted in Exchange Server, Windows Powershell | No Comment | 1,165 views | 24/05/2013 14:02

You can get your db statistics like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# PoSHStats Pipeline
function PoSHStats-Pipeline 
{
	# Create Timer
	Begin { $i=0; $Timer = [Diagnostics.StopWatch]::StartNew() } 
 
	# Process Items
	Process { $i++; $_ }
 
	# Informational Output
	End { Write-Debug "Processed $i items in $($Timer.Elapsed.TotalSeconds) seconds." } 
}
 
$ExchangeServer = "EXMB04"
 
# Get MailboxDatabase
if ($ExchangeServer.IsMailboxServer -eq $True)
{
	Get-MailboxDatabase -Status | where {$_.Server -eq "$ExchangeHost"} | PoSHStats-Pipeline | %{
 
		# Database Statistics
		$DBName = $_.Name
		$DBSize = $_.DatabaseSize.ToGB()
		$DBLastFullBackup = $_.LastFullBackup.ToString()
		$DBWhiteSpace = $_.AvailableNewMailboxSpace.ToMB()
 
		# Mailbox Statistics
		$MBStats = Get-MailboxStatistics -Database $DBName | %{$_.TotalItemSize.value.ToMb()} | Measure-Object -Average
		$MBCount = $MBStats.Count
		$MBAvg = ([math]::round(($MBStats.Average), 0))
 
		# Mailbox Database Disk Usage
		$DBDrive = $_.EdbFilePath.DriveName
		$DBDiskInfo = Get-WmiObject -ComputerName $ExchangeHost -Class Win32_LogicalDisk | Where {$_.DeviceID -eq $DBDrive}
		$DBDiskSize = ([math]::round(($DBDiskInfo.Size / 1GB), 0))
		$DBDiskFreeSpace = ([math]::round(($DBDiskInfo.FreeSpace / 1GB), 0))
 
		# Exchange Database Disk Usage
		[int]$ExchangeDatabaseSize = [int]$ExchangeDatabaseSize + [int]$DBSize
		[int]$ExchangeDatabaseWhiteSpace = [int]$ExchangeDatabaseWhiteSpace + [int]$DBWhiteSpace
 
		# Database White Space
		[int]$DatabaseWhiteSpace = ([math]::round(($DBWhiteSpace / 1KB), 0))
 
		# Exchange Server Disk Usage
		$TestDrive = $DiskDrives.Contains("$DBDrive")
 
		if ($TestDrive -ne $True)
		{
			$DiskDrives.Add("$DBDrive") | Out-Null
			[int]$ExchangeDatabaseDiskSize = [int]$ExchangeDatabaseDiskSize + [int]$DBDiskSize
			[int]$ExchangeDatabaseDiskFreeSpace = [int]$ExchangeDatabaseDiskFreeSpace + [int]$DBDiskFreeSpace
		}
 
		# Host Total Database Size
		[int]$HostTotalDatabaseSize = [int]$HostTotalDatabaseSize + [int]$DBSize
 
		# Host Total Database Count
		[int]$HostTotalDatabaseCount++ | Out-Null
 
		# Host Total Mailbox Count
		[int]$HostTotalMailboxCount = [int]$HostTotalMailboxCount + [int]$MBCount
 
		# Host Total Mailbox Average
		[int]$HostTotalMailboxAverage = [int]$HostTotalMailboxAverage + [int]$MBAvg
	}
}

This is the preview code of PoSHStats Exchange Server module.



Leave a Reply