Export Powershell results an Excel sheet.

The below code will export to information to an excel sheet in a proper column and table format.

cls
$ToDayDate=Get-Date
$After=[datetime]::Today.AddDays(-7)
$Servers=@("RAMESH","RAMESH\UAT")
$Servers|
ForEach-Object{
$InstanceName=$_
Get-DBAErrorLog -SQLInstance $InstanceName `
-Before $ToDayDate -After $After |
Where-Object {($_.Text -like "*register a Service Principal Name (SPN)*") -or ($_.Text -like "*taking longer than*") `
-or($_.Text -like "*login failed*")
}
}|Export-Csv "C:\Users\hi\Desktop\Test\Analysis.csv" -NoTypeInformation

Comments

Popular posts from this blog

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

Pre login Handshake or Connection Timeout Period

Transparent Data Encryption(TDE) with Master Key and Certificate in SQL Server