Answer the question
In order to leave comments, you need to log in
Why does PowerShell add extra information when exporting to Excel?
Good afternoon! there is a code
$Connection = "Server=localhost\SQLEXPRESS;Database=msdb;Trusted_Connection=True;"
$InputFile = "C:\Users\user\TestScripts\SQLQuery2.sql"
$ExportFile = "C:\Users\user\TestScripts\Report1.xls"
$Sheatnamber = 0
$result = Invoke-Sqlcmd -InputFile $InputFile -OutputAs Dataset -ConnectionString $Connection
$t = $result.Tables.Count
for ($i = 0; $i -lt $t; $i++)
{
$Sheatnamber = $Sheatnamber + 1
$sheatname = "Запрос " + $Sheatnamber
$result.Tables.Item($i) | Export-Excel -WorksheetName $sheatname -Path $ExportFile -AutoSize -Append
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question