切换到宽版
  • 9881阅读
  • 2回复

[求助]使用脚本生成Exchange服务报告 [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-03-21
— 本帖被 YOYO 从 Exchange 脚本中心 移动到本区(2015-06-25) —
  • 脚本环境:PowerShell
  • 适合版本:Exchange 2007
  • 适用平台:
The collected information is:
  • Server name
  • Database path and filename
  • Database Size
  • Mailboxes by database
  • Disk Size
  • Free space on disk
  • Percentage of free space


#----------------------------------------------
#  Capacity Planning Report for Exchange v1.0
#  Author: Fernando Ezequiel Hazzan
#  Date: 3/2/2010
#----------------------------------------------
# Get Servers Information
$servers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
$serversreport = @()
# Look into each server for needed data
foreach ($server in $servers)
{
    # Get database list from current server
$db = Get-MailboxDatabase -server $server
    # Work on each database
foreach ($objitem in $db)
    {
        # Get storage information of current database
        $driveinfo = Get-WMIObject -class "Win32_LogicalDisk" -namespace "root\CIMV2" -computername $server -filter ("Caption = '" + $objitem.EdbFilePath.DriveName + "' ")
        $drivefreespace = ($driveinfo.FreeSpace/1MB).tostring("0.00")
        $drivecapacity = ($driveinfo.Size/1MB).tostring("0.00")
        $percent = ($driveInfo.FreeSpace * 100.0)/$driveinfo.Size
  $percent = ("{0:N0}" -f $percent) + "%"
  
  # Get size information of the current database
  $edbfilepath = $objitem.edbfilepath
        $path = "`\`\" + $server + "`\" + $objitem.EdbFilePath.DriveName.Remove(1).ToString() + "$" + $objitem.EdbFilePath.PathName.Remove(0,2)
        $dbsize = Get-ChildItem $path    
        $start = $path.LastIndexOf('\')
        $dbpath = $path.Substring($start +1).remove($path.Substring($start +1).length -4)
        $mailboxpath = "$server\$dbpath"
        $mailboxcount = Get-MailboxStatistics -database "$mailboxpath" |measure-object
    
     # Create a sheet and insert the information needed
  $sheet = New-Object PSObject
        $sheet | Add-Member NoteProperty -Name "Server" -Value $server
  $sheet | Add-Member NoteProperty -Name "Database" -Value $objItem.edbfilepath.pathname
        $sheet | Add-Member NoteProperty -Name "Size(MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))
        $sheet | Add-Member NoteProperty -Name "Mailboxes" -Value $mailboxcount.count
        $sheet | Add-Member NoteProperty -Name "Disk Size(MB)" -Value $drivecapacity
        $sheet | Add-Member NoteProperty -Name "Free Spice(MB)" -Value $drivefreespace
  $sheet | Add-Member NoteProperty -Name "% Free" -Value $percent
    
     # Add the sheet of this database to the report string
  $serversreport += $sheet
    }
}
# Export the report to a CSV file
$serversreport |Export-CSV ((Get-Date -uformat "%m-%d-%Y") +".csv") -notype -force

分享到
只看该作者 1楼  发表于: 2013-02-23
只看该作者 2楼  发表于: 2014-02-13
快速回复
限60 字节
 
上一个 下一个