Blog Archives

Backup all databases using Backup-SqlDatabase cmdlet


Launch SSMS Right click on databases node, Select Menu item “Start PowerShell” Type in following command to backup all databases to Default backup folder dir |  Backup-SqlDatabase     Databases are backed up to Default backup folder  

Posted in Backup, Scripting, SQL Power shell, SQL Server

Set autoclose property for all database


in SSMS , Right click on database node in Object Explorer, Select menu item “Start PowerShell” Type in following in power shell window to set Auto Close on all databases dir | foreach {$_.AutoClose = $true; $_.Alter()} If you would

Posted in DB Management, SQL Power shell, SQL Server, SSMS

Scripting database using Smo.Scripter


You can automate script generation using SMO and power shell using the following power shell script. Script generated would be similar to the script generated using “Generate Script Wizard” in ssms You can download script from here This posting is

Tagged with:
Posted in Scripting, SQL Power shell, SQL Server

Index rebuild on large database – SQL Agent Powershell job


Index rebuild on a large database could take longer time. One of our customer was looking for a solution to rebuild index one by one  when index  fragmentation is greater than 30%.  Related  newsgroup thread: http://social.msdn.microsoft.com/Forums/en-US/sqlkjmanageability/thread/4faae7c8-3e58-4117-8538-f397e342743f In this blog post, I have

Posted in DB Management, Powershell, SQL Agent, SQL Power shell, SQL Server

Powershell script to run query against many servers and send combined output as email


This powershell script is sample code to run query against multiple SQL Servers and export the combined output to Excel. This Excel file is later sent as email attachment using hotmail. Related email thread: http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/987d48c0-a82d-4424-8699-cdd0b2bc9c51 # This posting is provided

Posted in SQL Power shell

SQL 2008 Power Shell script – Databases that were not backed up in last 7 days


Here is a simple powershell command to list databases that were not backed up in last 7 days. http://blogs.msdn.com/b/sethus/archive/2008/06/10/sql-2008-power-shell-script-databases-that-were-not-backed-up-in-last-7-days.aspx

Posted in Backup, Powershell, SQL Power shell, SQL Server