Changing Log file retention using PowerShell

I love SQL Server. No matter how long you play with it, there is always a little setting here and there that I did not know about, or had forgotten over the years. This morning Mr Denny clued me into one of these on his blog (via Twitter). The setting was the number of SQL server error logs to retain. He showed us how to set this in SSMS and via a T-SQL change to the registry.

My first thought as I read this was “how can I do this in PowerShell?”.

Sometimes it is easy, sometimes it is harder than anticipated. In this case, it was way to easy, it took me all of 2 minutes looking at the SMO Server object to find a wonderful little property, NumberOfLogFiles. This led me to write this little script that I am going to add into my standard Post deployment configuration script:

$server = gss -computername SERVER1
$server.NumberOfLogFiles = 20

gss is an alias to my own profile loaded function that simply returns an SMO object referencing the server I am looking at. Of course, as Mr Denny states, the number you want to configure will vary from install to install, so make sure you use the appropriate value.

Thanks for reading.

This entry was posted in SQL Server. Bookmark the permalink.

2 Responses to Changing Log file retention using PowerShell

  1. With havin so much content and articles
    do you ever run into any problems of plagorism or copyright violation?
    My blog has a lot of exclusive content I’ve either written myself or outsourced but it appears a lot of it is popping it up all over the internet without my authorization. Do you know any methods to help reduce content from being ripped off? I’d genuinely appreciate

  2. I’m afraid I would have no clue. I only started this blogging malarky last year, and really it is a way for me to learn material, and hopefully share some pearls of wisdom. I don’t think anything I put out is world changing, most of it has been done before in similar ways, so I don’t really look out for that sort of thing.

    Good luck with your materials.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s