Before jumping into more hardcore SQL Server PowerShell features, let’s briefly look at the SQL Server event log. Fortunately, the log simply contains text-based files, which PowerShell can read. You could use the
Get-Content cmdlet to view the entire log, but instead you can use the
Select-String cmdlet to look for a specific string or pattern in the error log file. First, you change the current location to the SQL Server log directory:
PS>Set-Location "C:\Program Files\Microsoft SQL Server"PS>Set-Location (join-path $pwd "MSSQL11.MSSQLSERVER\MSSQL\Log")PS>Select-String "error" ERRORLOG
The PowerShell prompt in the preceding example is simply a generic one because the preceding commands ...