Link to home
Start Free TrialLog in
Avatar of Albert Widjaja
Albert WidjajaFlag for Australia

asked on

Modifying PowerShell script to show total transaction log size in Exchange Server 2013 ?

I had this question after viewing Powershell to show mailbox DB .EDB size ?.

Hi,

Can anyone here please assist me in modifying the below PowerShell script to calculate the Exchange Transaction log file size ?

Get-MailboxDatabase | 
    Select Server, 
           Name, 
           @{Name="DB Size (GB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $path = "`\`\" + $objitem.server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $size = ((Get-ChildItem $path).length)/1048576KB; [math]::round($size, 2)}}, 
           @{Name="Number of Mbx";expression={(Get-Mailbox -Database $_.Identity | Measure-Object).Count}},
           EdbFilePath,
           LogFolderPath,
           LogFileSize, 
           CircularLoggingEnabled, 
           IsPublicFolderDatabase | ft -AutoSize

Open in new window


So far it works great, but I cannot get the total Transaction Log size.

Any help would be greatly appreciated.

Thanks,
Avatar of Robin Dadswell
Robin Dadswell
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,

The problem you have is it is the folder size that you are really looking for not the file size (as Exchange builds lots of them at the maximum file size which is the Log File Size,

here is one that will show it to you in MB
Get-MailboxDatabase | 
    Select Server, 
           Name, 
           @{Name="DB Size (GB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $path = "`\`\" + $objitem.server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $size = ((Get-ChildItem $path).length)/1048576KB; [math]::round($size, 2)}}, 
           @{Name="Number of Mbx";expression={(Get-Mailbox -Database $_.Identity | Measure-Object).Count}},
           EdbFilePath,
           LogFolderPath,
           @{Name="Log Folder Size (MB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $path = "`\`\" + $objitem.server + "`\" + $objItem.LogFolderPath.DriveName.Remove(1).ToString() + "$"+ $objItem.LogFolderPath.PathName.Remove(0,2); $size = ((Get-ChildItem $path).length)/1024KB; [math]::round($size, 2)}}, 
           CircularLoggingEnabled, 
           IsPublicFolderDatabase | ft -AutoSize

Open in new window

and here it is modified to show you it in GB
Get-MailboxDatabase | 
    Select Server, 
           Name, 
           @{Name="DB Size (GB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $path = "`\`\" + $objitem.server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $size = ((Get-ChildItem $path).length)/1048576KB; [math]::round($size, 2)}}, 
           @{Name="Number of Mbx";expression={(Get-Mailbox -Database $_.Identity | Measure-Object).Count}},
           EdbFilePath,
           LogFolderPath,
           @{Name="Log Folder Size (GB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $path = "`\`\" + $objitem.server + "`\" + $objItem.LogFolderPath.DriveName.Remove(1).ToString() + "$"+ $objItem.LogFolderPath.PathName.Remove(0,2); $size = ((Get-ChildItem $path).length)/1048576KB; [math]::round($size, 2)}}, 
           CircularLoggingEnabled, 
           IsPublicFolderDatabase | ft -AutoSize

Open in new window



Thanks

Robin
Avatar of Albert Widjaja

ASKER

Hi Robin,

My Exchange mailbox DB and the Transaction logs are in the same folder due to DAG limitations.
No Problem,

I have amended the 2 sums for Database Size and Log Folder Size to exclude the logs and the database respectively,

Log Size GB:
Get-MailboxDatabase | 
    Select Server, 
           Name, 
           @{Name="DB Size (GB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $databasepath = "`\`\" + $objitem.server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $databasesize = ((Get-ChildItem $databasepath).length)/1048576KB; [math]::round($databasesize, 2)}}, 
           @{Name="Number of Mbx";expression={(Get-Mailbox -Database $_.Identity | Measure-Object).Count}},
           EdbFilePath,
           LogFolderPath,
           @{Name="Log Folder Size (GB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $logpath = "`\`\" + $objitem.server + "`\" + $objItem.LogFolderPath.DriveName.Remove(1).ToString() + "$"+ $objItem.LogFolderPath.PathName.Remove(0,2); $logsize = ((Get-ChildItem $logpath -exclude "*edb*,*CatalogData*").length)/1048576KB; [math]::round($logsize, 2)}}, 
           IsPublicFolderDatabase | ft -AutoSize

Open in new window

Log Size MB:
Get-MailboxDatabase | 
    Select Server, 
           Name, 
           @{Name="DB Size (GB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $databasepath = "`\`\" + $objitem.server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $databasesize = ((Get-ChildItem $databasepath).length)/1048576KB; [math]::round($databasesize, 2)}}, 
           @{Name="Number of Mbx";expression={(Get-Mailbox -Database $_.Identity | Measure-Object).Count}},
           EdbFilePath,
           LogFolderPath,
           @{Name="Log Folder Size (MB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $logpath = "`\`\" + $objitem.server + "`\" + $objItem.LogFolderPath.DriveName.Remove(1).ToString() + "$"+ $objItem.LogFolderPath.PathName.Remove(0,2); $logsize = ((Get-ChildItem $logpath -exclude "*edb*,*CatalogData*").length)/1024KB; [math]::round($logsize, 2)}}, 
           IsPublicFolderDatabase | ft -AutoSize

Open in new window


Log Size KB:
Get-MailboxDatabase | 
    Select Server, 
           Name, 
           @{Name="DB Size (GB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $databasepath = "`\`\" + $objitem.server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $databasesize = ((Get-ChildItem $databasepath).length)/1048576KB; [math]::round($databasesize, 2)}}, 
           @{Name="Number of Mbx";expression={(Get-Mailbox -Database $_.Identity | Measure-Object).Count}},
           EdbFilePath,
           LogFolderPath,
           @{Name="Log Folder Size (KB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $logpath = "`\`\" + $objitem.server + "`\" + $objItem.LogFolderPath.DriveName.Remove(1).ToString() + "$"+ $objItem.LogFolderPath.PathName.Remove(0,2); $logsize = ((Get-ChildItem $logpath -exclude "*edb*,*CatalogData*").length)/1KB; [math]::round($logsize, 2)}}, 
           IsPublicFolderDatabase | ft -AutoSize

Open in new window


Thanks

Robin
Hang on sorry, I noticed a slight mistake,

here it is resolved in MB:
Get-MailboxDatabase | 
    Select Server, 
           Name, 
           @{Name="DB Size (GB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $databasepath = "`\`\" + $objitem.server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $databasesize = ((Get-ChildItem $databasepath).length)/1048576KB; [math]::round($databasesize, 2)}}, 
           @{Name="Number of Mbx";expression={(Get-Mailbox -Database $_.Identity | Measure-Object).Count}},
           EdbFilePath,
           LogFolderPath,
           @{Name="Log Folder Size (MB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $logpath = "`\`\" + $objitem.server + "`\" + $objItem.LogFolderPath.DriveName.Remove(1).ToString() + "$"+ $objItem.LogFolderPath.PathName.Remove(0,2) + "\*"; $logsize = ((Get-ChildItem $logpath -include "*log").length)/1024KB; [math]::round($logsize, 2)}}, 
           IsPublicFolderDatabase | ft -AutoSize

Open in new window


Thanks

Robin
Hi Robin,

THanks for the script.

Get-MailboxDatabase | 
    Select Server, 
           Name, 
           @{Name="DB Size (GB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $databasepath = "`\`\" + $objitem.server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $databasesize = ((Get-ChildItem $databasepath).length)/1048576KB; [math]::round($databasesize, 2)}}, 
           @{Name="Number of Mbx";expression={(Get-Mailbox -Database $_.Identity | Measure-Object).Count}},
           EdbFilePath,
           LogFolderPath,
           @{Name="Log Folder Size (MB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $logpath = "`\`\" + $objitem.server + "`\" + $objItem.LogFolderPath.DriveName.Remove(1).ToString() + "$"+ $objItem.LogFolderPath.PathName.Remove(0,2) + "\*"; $logsize = ((Get-ChildItem $logpath -include "*log").length)/1024KB; [math]::round($logsize, 2)}}, 
           IsPublicFolderDatabase | ft -AutoSize

Open in new window


Somehow the return is still 0 KB ?

The Exchange log filter that you proposed: -exclude "*edb*,*CatalogData*" looks makes more sense, but why are you replacing it into -include "*log" ?
Exchange Server logs is a 1 MB text file starts with E0*.log extension.
I've changed it into: Get-ChildItem $logpath -include "*.log" and even Exclude "*edb*,*CatalogData*" -include "*.log" but still not working either ?

it shows 0 on the column
When you look at the log location do you see many logs in there? Is the database size working?
Yes, there are hundreds of E00*.log files and also the database size is working with no issue.
As soon as I'm in front of a pc, I will amended it slightly and send it back on a slight variation
Sure Robin,

Many thanks for the assistance !
ASKER CERTIFIED SOLUTION
Avatar of Robin Dadswell
Robin Dadswell
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Robin, it works great