The Surly Admin

Father, husband, IT Pro, cancer survivor

Shrink SQL Log Files

If you’re a Windows Administrator and have Microsoft SQL Servers in your environment–and you’d be a rare bird if you didn’t–then you’ve encountered this problem.  Backups are missed for awhile, massive restore is done, something happens and your transaction log file grows way too big.  It’s not uncommon to find it being much larger then the actual database!  If you’re like me you would RDP to the server, check out the data drive and see that the log file itself was out of size.  You’d then hit Google to find out how to do a shrink file, then have open SQL Management Studio and try to figure out the logical name of the log file, then run the query.  Usually about 20 minutes of lookups, all so you can run a SQL query that typically takes a few seconds to complete.  Time to address this using PowerShell.

Continue reading

January 5, 2015 Posted by | PowerShell | , , | 3 Comments