需要创建Powershell v2脚本以列出Exchange 2010服务器中的邮箱详细信息(邮箱名称,电子邮件地址,邮箱大小),并将其导入MySQL数据库表。
我可以将Exchange信息导入Powershell,但是如何将每条信息插入MySQL中的不同列?
例如:邮箱名称,电子邮件地址,邮箱大小等。
任何人都知道怎么做?
答案 0 :(得分:0)
这是一个可以编辑的脚本,用于将电子邮件地址和任何其他交换机导出的powershell内容添加到mysql
中[void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data")
$servers = Get-MailboxServer
foreach($server in $servers)
{ $mailboxes = Get-Mailbox -server $server -ResultSize unlimited
foreach ($m in $mailboxes)
{ $stats = Get-MailboxStatistics $m | Select ItemCount,DeletedItemCount,TotalItemSize,TotalDeletedItemSize
$date = Get-Date -Format "dd MMM yyyy h:mmtt"
$alias = $m.Alias
$items = $stats.ItemCount
$deletedItems = $stats.DeletedItemCount
$size = $stats.TotalItemSize.Value.ToMB()
$deletedSize = $stats.TotalDeletedItemSize.Value.ToMB()
$dbconnect = New-Object MySql.Data.MySqlClient.MySqlConnection
$dbconnect.ConnectionString = "server=<SERVER>;port=3306;uid=<USERNAME>;pwd=<PASSWORD>;database=<DATABASE>;"
$dbconnect.Open()
$sql = New-Object MySql.Data.MySqlClient.MySqlCommand
$sql.Connection = $dbconnect
$sql.CommandText = "INSERT INTO <TABLE> (Timestamp,Alias,ItemCount,TotalItemSize,DeletedItemCount,TotalDeletedItemSize) values ('" + $date + "','" + $alias + "','" + $items + "','" + $size + "','" + $deletedItems + "','" + $deletedSize + "')"
$sql.ExecuteNonQuery()
$dbconnect.Close()
}
}