PowerShell : Control Excel
Voici quelques bouts de code pour controler Microsoft Excel à partir de PowerShell
#Creation of the xls Sheet
$a = New-Object -comobject Excel.Application
$a.visible = $True
$MyWorkBook = $a.Workbooks.Add()
$MyWorksheets = $MyWorkBook.Worksheets.Item(1)
$i=1;
$MyWorksheets.Cells.Item(1,$i++) = "Server Name"
$MyWorksheets.Cells.Item(1,$i++) = "Host"
$MyWorksheets.Cells.Item(1,$i++) = "Cluster"
#Excel Sheet Format
$d = $MyWorksheets.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$MyWorksheets.Cells.Item($intRow,$i++) = "OK"
$MyWorksheets.Cells.Item($intRow,$i-1).Interior.ColorIndex = 4
#Save the XLS page in CSV
$FileFormat=[Microsoft.Office.Interop.Excel.xlFileFormat]::xlCsv
if(test-path "$FileLocation\BocadaExport.csv"){Remove-Item "$FileLocation\BocadaExport.csv"}
$MyWorksheets.SaveAs("$FileLocation\BocadaExport.csv",$FileFormat)
#Quit XLS
$excel.displayalerts = $False
$excel.quit()
