"xp_cmdshell" is an extended stored procedure provided by Microsoft and stored in the master database. This procedure allows you to issue operating system commands directly to the Windows command shell via T-SQL code.

— To allow advanced options to be changed.
EXEC sp_configure ‘show advanced options’, 1;
GO
— To update the currently configured value for advanced options.
RECONFIGURE;
GO
— To enable the feature.
EXEC sp_configure ‘xp_cmdshell’, 1;
GO
— To update the currently configured value for this feature.
RECONFIGURE;
GO

Let’s start out with a simple directory search example. Say you do not have access to the physical SQL Server machine, but you want to see all the files are accessible form the database service. To do that enter the below command with the original path of the share path

Exec xp_cmdshell ‘Dir \\MyServer\MyShare\’

Taken from: http://msdn.microsoft.com/en-us/library/ms190693.aspx

Advertisements