I figured I would update a few of my scripts to work in both environments. The
Database script can be seen below and downloaded HERE. The DB script has been updated to show better information on DB size and Lun information. I have created a new Transaction log script to work with Exchange 2007 and can be seen below or downloaded from HERE. The Exchange 2010 Script is
the Same and can be Downloaded HERE.
DBSize.ps1 Script
$report = @()
foreach ($DB in
$MYDatabases)
{
[string]$DBPathString = $db.EDBFILEpath
# Build Database File Path
$MyDriveString =$DBPathString.substring(0,1);
$MySubString=$DBPathString.substring(0,2);
$UNCPath = “\\$($db.Server)\”+ $MyDriveString + “$ ;
$Shell = new-object -com Shell.Application;
$UNCDBPath = $DBPathString.Replace($MySubString,$UNCPath);
$drives = Get-WmiObject -ComputerName $DB.Server Win32_LogicalDisk |
Where-Object {$_.DeviceID -eq $MyDriveString +”:”}
foreach($drive in
$drives)
{
$size1 = $drive.size / 1GB
$size = “{0:N2}” -f $size1
$size = $size + ” GB”
$free1 = $drive.freespace / 1GB
$free = “{0:N2}” -f $free1
$free = $free + ” GB”
}
#Get File Info
$DBFiles = get-childitem -path $UNCDBPath;
[decimal]$GBSize = ($DBFiles | Measure-Object -Property Length -Sum).Sum;
[decimal]$GBSize = $GBSize/1073741824;
$DBFILESIZE = “{0:N2}” -f $GBSize;
$DBFILESIZe = $DBFILESIZE + “GB”;
# Output info
$MyData = New-Object Object;
$MyData | Add-Member NoteProperty Name $DB.Name;
$MyData | Add-Member NoteProperty Server $DB.Server;
$MyData | Add-Member NoteProperty Size $DBFILESIZE;
$MyData | Add-Member NoteProperty “Lun Size” $size;
$MyData | Add-Member NoteProperty “Free Space” $free;
$report += $MyData
}
$report |FT -autosize
$report = @()
foreach ($DB in
$MYDatabases)
{
[string]$logPathString = $db.LogFolderPath
$MyDriveString
=$logPathString.substring(0,1);
$MySubString=$logPathString.substring(0,2);
$UNCPath = “\\$($db.Server)\” + $MyDriveString + “$ ;
$Logfoldername = $logPathString.Replace($MySubString,$UNCPath);
$Shell = new-object -com
Shell.Application
$Logfolder = $shell.namespace($Logfoldername)
$logfolderitems = $logfolder.items()
$logcount = $logfolderitems.count
$drives = Get-WmiObject -ComputerName $DB.Server Win32_LogicalDisk |
Where-Object {$_.DeviceID -eq $MyDriveString +”:”}
foreach($drive in
$drives)
{
$size1 = $drive.size / 1GB
$size = “{0:N2}” -f $size1
$size = $size + ” GB”
$free1 = $drive.freespace / 1GB
$free = “{0:N2}” -f $free1
$NewLogs1 = $free / .001
$free = $free + ” GB”
}
$MyData = New-Object Object;
$MyData | Add-Member NoteProperty DB -value
$DB.Name;
$MyData | Add-Member NoteProperty Server $DB.Server;
$MyData | Add-Member NoteProperty Logs $logcount;
$MyData | Add-Member NoteProperty “Lun Size” $size;
$MyData | Add-Member NoteProperty “Free Space” $free;
$MyData | Add-Member NoteProperty “Available Logs” $NewLogs1;
$report += $MyData
}
$report |FT -autosize

