Export powershell result to excel XLS -not a csv....help-meee
I am trying to record given data get on powershell in excel, but I did not discover a way to record the data, somebody I can help me? #### $excel = new-object -comobject excel.application $excel.visible = $true $workbook = $excel.workbooks.add() $workbook.workSheets.item(3).delete() $workbook.WorkSheets.item(2).delete() $workbook.WorkSheets.item(1).Name = "DBUsers" $sheet = $workbook.WorkSheets.Item("DBUsers") $x = 2 $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] For($b = 1 ; $b -le 5 ; $b++) { $sheet.cells.item(1,$b).font.bold = $true $sheet.cells.item(1,$b).borders.LineStyle = $lineStyle::xlDashDot $sheet.cells.item(1,$b).borders.ColorIndex = $colorIndex::xlColorIndexAutomatic $sheet.cells.item(1,$b).borders.weight = $borderWeight::xlMedium } $sheet.cells.item(1,1) = "Database" $sheet.cells.item(1,2) = "DisplayName" $sheet.cells.item(1,3) = "StorageLimitStatus" $sheet.cells.item(1,4) = "ItemCount" $sheet.cells.item(1,5) = "TotalItemSize" ############excel write ?? $Database = @{n="Database";e={ $stats.database }} $DisplayName = @{n="DisplayName";e={ $stats.Displayname }} $StorageLimitStatus = @{n="StorageLimitStatus";e={ $stats.StorageLimitStatus }} $ItemCount = @{n="ItemCount";e={ $stats.ItemCount }} $TotalItemSize = @{n="TotalItemSize(MB)";e={ $stats.TotalItemSize.Value.ToMB() }} $Servers=get-content c:\servers.txt Foreach($server in $servers) { $stats = get-mailbox -server $server | foreach { $stats = get-mailboxstatistics $_ $_ | select alias, *SMTP*,$Database,$DisplayName,$StorageLimitStatus,$ItemCount,$TotalItemSize $sheet.cells.item($x,1) = $database $sheet.cells.item($x,2) = $Displayname $sheet.cells.item($x,3) = $StorageLimitStatus $sheet.cells.item($x,4) = $ItemCount $sheet.cells.item($x,5) = $TotalItemSize.Value.ToMB $x++ } } ###
June 24th, 2009 12:53am

I tried playing around with your example, but I'm still new to PoSh and using the comobjects. I would had just sent it out to a CSV file. If you figure it out, please post it up Id like to play around with this some more and learn how to make the spreadsheets formated already, seem pretty straight foward, the Exchange side of it is displaying to the screen properly. Try here might have better luck. http://powershellcommunity.org/Forums/tabid/54/afv/topicsview/aff/3/Default.aspx
Free Windows Admin Tool Kit Click here and download it now
June 24th, 2009 2:16pm

This is a sample Excel+PowerShell script which I found somewhere few days back. See it if it could help u. $strComputer = . $Excel = New-Object -Com Excel.Application $Excel.visible = $True $Excel = $Excel.Workbooks.Add() $Sheet = $Excel.WorkSheets.Item(1) $Sheet.Cells.Item(1,1) = Computer $Sheet.Cells.Item(1,2) = Drive Letter $Sheet.Cells.Item(1,3) = Description $Sheet.Cells.Item(1,4) = FileSystem $Sheet.Cells.Item(1,5) = Size in GB $Sheet.Cells.Item(1,6) = Free Space in GB $WorkBook = $Sheet.UsedRange $WorkBook.Interior.ColorIndex = 8 $WorkBook.Font.ColorIndex = 11 $WorkBook.Font.Bold = $True $intRow = 2 $colItems = Get-wmiObject -class Win32_LogicalDisk -namespace root\CIMV2 ` -computername $strComputer foreach ($objItem in $colItems) { $Sheet.Cells.Item($intRow,1) = $objItem.SystemName $Sheet.Cells.Item($intRow,2) = $objItem.DeviceID $Sheet.Cells.Item($intRow,3) = $objItem.Description $Sheet.Cells.Item($intRow,4) = $objItem.FileSystem $Sheet.Cells.Item($intRow,5) = $objItem.Size / 1GB $Sheet.Cells.Item($intRow,6) = $objItem.FreeSpace / 1GB $intRow = $intRow + 1 } $WorkBook.EntireColumn.AutoFit() Clear Copy the script code and save it as LogDiskRpt.ps1Run the script: LogDiskRpt.ps1 Regards,Laeeq Qazi: Snr Software Engineer(Exchange+Sharepoint+BES+DynamicsCRM) www.hostingcontroller.com
June 24th, 2009 3:32pm

I found some examples in the Internet working with " Get-wmiObject - class Win32_" but I do not obtain to way to select data data from get-mailbox and get-mailboxstatistics and after save them in excel. I download the PowerGUI to try to debug, but i still continue without a vision to record in excel.
Free Windows Admin Tool Kit Click here and download it now
June 24th, 2009 8:47pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics