Good day all,
I'm trying to come up with a function that I can run across all mailbox servers in my environment; gathering information such as drives presented to it, drive capacity, drive free space, database size, mbx count, avg mbx size, database whitespace, etc.. I start running into errors when I wanted to add the drive report to this. Can anyone take a look and see where im faulting? When I run this I get "you cannot call a method on a null-valued expression.'
Thank you for your help.
function DatabaseStatistics{
$ExchangeServers = get-exchangeserver
$Drivespace = Get-wmiobject win32_logicaldisk -computername $ExchangeServers
foreach($Drive in $drivespace) {
$DrFree = $drivespace.deviceid.freespace
$DrSize = $drivespace.deviceid.volumename.size
$Databases = Get-MailboxDatabase * -Status
foreach($Database in $Databases) {
$DBSize = $Database.DatabaseSize
$MBCount = @(Get-MailboxStatistics -Database $Database.Name).Count
$MBAvg = Get-MailboxStatistics -Database $Database.Name |
%{$_.TotalItemSize.value.ToMb()} |
Measure-Object -Average
New-Object PSObject -Property @{
Server = $Database.Server.Name
DatabaseName = $Database.Name
LastFullBackup = $Database.LastFullBackup
MailboxCount = $MBCount
"DatabaseSize (GB)" = $DBSize.ToGB()"AverageMailboxSize (MB)" = $MBAvg.Average"WhiteSpace (MB)" = $Database.AvailableNewMailboxSpace.ToMb()"Drive and Capacity" = $drsize.toGB()"Drive Freespace" = $drfree.toGB()
}
}
}
}