Decreasing performance for excel com object in powershell script -


I have a powerhall script which is read repeatedly to an Excel com object *. Csv generates a graph, generates a graph, and then the graph as shown in the * .pdf file is shown below the code section when the script starts, per file is between 2-4 seconds. Now the script runs, now it takes more time to process a personal CSV file. After about 1,000 files, it takes about 60 seconds per file. All the small columns in the CSV files are from 70 rows. When I have 215 graphs, it takes about 12 minutes to run. When I have 1,522 graphs, it takes about 20 hours. Is there something that I can do to speed it up?

Tia, Mark K.

  # # Create an Excel object and use it to generate the graph. # $ Ex = new-object -ComObject Excel.Application $ ChartType = "microsoft.office.interop.excel.xlChartType" -as [type] $ xlFixedFormat = "Microsoft.Office.Interop.Excel.xlFixedFormatType" -as [type] $ ex.DisplayAlerts = to $ wrong to $ ex.Visible = $ incorrect $ WB = $ ex.Workbooks.Add () $ ws = $ wb.worksheets $ WS1 = $ ws.Item (1), then { # Delete unnecessary worksheets currently $ ws.item (3) .delete () $ ws.item (2) .delete ()} catch [exception] {out-null} $ i = 0 foreach ($ p $ $ pdfs) { # $ p is + $: "// xxxxxxxxxxxxx / http text" a PDF to a csv file {$ ws1.Name = $ p.Substring ( '.' 0, $ p.IndexOf ()) $ connector = ( LPAR + "/" + $ P) to be source $ CellRef = $ ws 1.Range ("A1") $ Conn = $ ws1.QueryTables.Add ($ Connector, $ CellRef) $ ws1.QueryTables.item ($ Conn.name). TextFileCommaDelimiter = $ correct $ ws1.QueryTables.item ($ Conn.name). TextFileParseType = 1 $ ws1.QueryTables.item ($ Conn.name) .Refre sh () | Out null $ WS2 = $ ex.charts.add () $ ws2.chartType = $ ChartType :: xlLine $ ws2.Name = $ ws1.Name + "Graph" $ ws2.HasTitle = $ true $ ws2.ChartTitle.Text = $ Ws1 Range ("A1"). Text $ data = $ ws1.range ("b2: b71") $ ws2.setSourceData ($ data) | Out null $ ws2.SeriesCollection (1) .XValues ​​= $ ws1.Range ( "A2: A71") $ wb.ExportAsFixedFormat ($ xlFixedFormat :: xlTypePDF, "$ drive`: \ captrendGraphs \ $ LPAR \" + $ WS1 .name + ".pdf", 0, $ true, $ true, 1,1) $ ws2.Delete () | Out-null $ ws1.UsedRange.ClearContents () | Out-null} cache [exception] {list-host $ _ exception.tstrring () list-log $ ($ _. Exception.stosting ()) list-host $ _exception Write message-log $ ($ _exception message) - host $ _. Exception. Write Source- Log $ ($ _. Exceptionation.source) Write-Host $ _. exception. Write StackTrace - Write $ ($ _. Exception. StackTrace) - Write "Host" with write "$ 1 + + $ rptP = $ (" {0: D4} "-f $ i +" "+ $ p)" : "$ P write-log $ (" happened with error: "+ $ p)} -stost $ rptP -log $ rptP}  

You can probably open and close the time interval (15 minutes) or the new Excel session in the graph construction interval (each 1000) and see if anything helps.


Comments