Reputation: 9
Thank you for your feedback, the script they gave me to improve opens an excel document on my desktop, since this will be ran across the network I do not want this to happen. However, I do want to keep the design of the sheet with the cell items. This is what I have.
$Date = [DateTime]::Now.AddDays(-1)
$Date.tostring("MM-dd-yyyy"), $env:Computername
$objExcel.visible = $True
$objSheet = $objWorkbook.Worksheets.Item(1)
$objSheet.Cells.Item(1,1) = "Server"
$objSheet.Cells.Item(1,2) = "LogName"
$objSheet.Cells.Item(1,3) = "Time"
$objSheet.Cells.Item(1,4) = "Source"
$objSheet.Cells.Item(1,5) = "Message"
$objSheetFormat = $objSheet.UsedRange
$objSheetFormat.Interior.ColorIndex = 19
$objSheetFormat.Font.ColorIndex = 11
$objSheetFormat.Font.Bold = $True
$row = 1
$servers = gc c:\Myscripts\servers.txt
foreach ($server in $servers)
{
$row = $row + 1
$AppLog = Get-EventLog -LogName Application -EntryType Error -computer $server -Newest 5
so how do I get this form in the excel but instead of opening a file just saving the file to my pointed location with something like below?
{ | Export-Csv -Path c:\ ('security-log-{0}.csv' -f ([DateTime]::Now).ToString("MM-dd-yyyy")
}
Upvotes: 0
Views: 140
Reputation: 174435
You can invoke the SaveAs()
method on the Workbook to save it:
$objWorkbook.SaveAs('C:\security-log-{0:MM-dd-yyyy}.csv' -f [datetime]::Now)
Upvotes: 1