[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1216
  • Last Modified:

Powershell command for file size

Via powershell, how can I query the Exchange 2007 mailbox servers to get the file size of the edb files?  We have four exchange databases on one lun (volume) so we have four edb files on the G drive.  We have four folders and in each folder is where the edb files are contained.  I wouldnt mind getting the folder size and all sub folder sizes in the top level folder.....just need some powershell polishing.
0
tpaukovits
Asked:
tpaukovits
1 Solution
 
mspieglerCommented:
0
 
paarunCommented:
I may be wrong, but will putting a dir command in batch file not solve your problem?
0
 
martingagnonCommented:
I've tested one of the script from the link that mspiegler provided and it is working great :

$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
foreach ($server in $exchangeservers)
{
    $db = Get-MailboxDatabase -server $server
    foreach ($objItem in $db)
    {
    $edbfilepath = $objItem.edbfilepath
    $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)
    $dbsize = Get-ChildItem $path
    $ReturnedObj = New-Object PSObject
    $ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity
    $ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))
    Write-Output $ReturnedObj
    }
}

Thanks!
0
Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

 
tpaukovitsAuthor Commented:
yes, thank martingangnon this is exactly what I was looking for. how can I modifiy this so it's exported via csv file?
0
 
martingagnonCommented:
Use this script then.

$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
$AllServers = @()
foreach ($server in $exchangeservers)
{
    $db = Get-MailboxDatabase -server $server
    foreach ($objItem in $db)
    {
    $edbfilepath = $objItem.edbfilepath
    $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)
    $dbsize = Get-ChildItem $path
    $ReturnedObj = New-Object PSObject
    $ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity
    $ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))
    $AllServers += $ReturnedObj
    }
}

$AllServers |export-csv c:\test.csv -notype -force
0
 
tpaukovitsAuthor Commented:
perfect!!! couldn't be any better!!
0

Featured Post

Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now