利用ems实现mailgroup member 导出到excel,并设置格式。
# This script should be run in Exchange powershell Environment.It will export # members of mailgroup that start with manu、 pc、 qa、and pe into the excel.
################################# open a excel file################################$exl = new-object -comobject excel.application
$exl.visible = $true
$wb = $exl.workbooks.add()
$ws = $wb.worksheets.Item(1)
#################################################################get distributionggroups that start with
$mailgp = get-distributiongroup |select-string "^manu|^pc|^qa|^pe"
################################################################get members of the distributiongroup###############################################################
$y=1foreach ($gp in $mailgp) { $title = get-distributiongroup -identity "$gp" |select name $ws.cells.item(1,$y)= $title.name $members = get-distributiongroupmember -identity "$gp" |select name $x=2 foreach ($member in $members) { $ws.cells.item($x,$y) = $member.name $x++ } $y++ } ##################################################################### #set the excel style ##################################################################### $lineStyle = "microsoft.office.interop.excel.xlLineStyle" -as [type]$colorIndex = "microsoft.office.interop.excel.xlColorIndex" -as [type]$borderWeight = "microsoft.office.interop.excel.xlBorderWeight" -as [type]$chartType = "microsoft.office.interop.excel.xlChartType" -as [type]
$colcon=$mailgp.count
for($b = 1 ; $b -le $colcon ; $b++){ $ws.cells.item(1,$b).columnWidth= 14# $ws.item(1,$b).font.bold = $true $ws.cells.item(1,$b).borders.LineStyle = $lineStyle::xlcontinuous $ws.cells.item(1,$b).borders.ColorIndex = $colorIndex::xlColorIndexAutomatic $ws.cells.item(1,$b).borders.weight = $borderWeight::xlMedium}