Book Image

PowerShell for SQL Server Essentials

By : Donabel Santos
Book Image

PowerShell for SQL Server Essentials

By: Donabel Santos

Overview of this book

Table of Contents (15 chapters)
PowerShell for SQL Server Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Implementing Reusability with Functions and Modules
Index

SQL Server error logs


You can view error logs in SQL Server Management Studio (SSMS). To view SQL Server-specific errors, you can open up SSMS and expand the SQL Server Agent node. Under the Error Logs folder, you can see the most recent error and the most recent archived error:

Alternatively, you can go to Management and expand SQL Server Logs. When you double-click on any one of the error logs, a log file viewer appears. You can select an option to view additional logs from the left-hand side pane. To view the most recent SQL Server-specific logs, check SQL Server on the left-hand side pane and then the Current checkbox:

Using SMO, you can also query this same information. This requires creating an SMO server object that references the instance you are working with. Once your server variable is instantiated, you can invoke the ReadErrorLog() method. The following snippet shows how you can display the five most recent entries in the SQL Server log:

#assuming you already created your SMO server...